duiLib的Github链接:https://github.com/duilib/duilib
使用vcpkg快速安装duilib以及配置。步骤如下:
1、用git下载vcpkg,下载报错,这个错误通常表明在Git克隆过程中,与GitHub服务器的SSL连接被意外重置。改用http下载成功。
2、执行bootstrap-vcpkg.sh
3、执行vcpkg integrate install
4、执行vcpkg install duilib
查看已安装的包列表,检查duiLib在其中:
5、包含头文件路径
项目属性,c/c++ , 附加包含目录中添加vcpkg的DuiLib头文件路径。
添加的就是上图该路径。
6、配置库文件。这里是动态链接示例(如果是静态链接,附加依赖项添加duilib_static.lib,并在预处理器定义中添加UILIB_STATIC)
1)项目配置选所有配置,平台选win32或X64
2)配置属性 → VC++ 目录 → 库目录 编辑
3)粘贴库文件路径。
我的是这个路径:
4)附加依赖项(添加.lib文件名)
动态链接,输入duilib.lib ,如下:
5)动态链接需复制DLL文件
将 duilib.dll(位于 vcpkg_root\packages\duilib_x86-windows\bin)复制到项目的输出目录(如 Debug\ 或 Release\)
即将上面这个DLL文件复制到下面:
7、测试环境是否配置好。代码如下:
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <thread>
#include <atomic>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <queue>
#include <sstream>
#include <exception>
#include <format>
#include <stack>#include <duilib/UIlib.h>using namespace DuiLib;class TestWindow : public CWindowWnd, public INotifyUI {
public:LPCTSTR GetWindowClassName() const override {return _T("TestWindowClass");}UINT GetClassStyle() const override {return CS_DBLCLKS;}void OnFinalMessage(HWND hWnd) override {delete this;}void Notify(TNotifyUI& msg) override {}LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) override {if (uMsg == WM_CLOSE) {PostQuitMessage(0);return 0;}return __super::HandleMessage(uMsg, wParam, lParam);}
};int main() {// 创建窗口TestWindow wnd;wnd.Create(nullptr, _T("Test"), UI_WNDSTYLE_FRAME, 0, 0, 500, 400);wnd.ShowModal();
}
运行结果:
可以看到一个标题为Test的窗口。ok.