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.