墨香年少 32 发布于 2023年8月6日 Make sure you have already build duilib's dll or static lib You can use dll or static lib to build your exe application, in this tutorial, I will use static lib 1. create a new project. notice: application type is window not console! so let's create a empty new project. 2. Right click project. open setting dialog. - [Configuration Properties -> C/C++ -> General] set Additional include Directories: D:\duilib\include\DuiLib - [Configuration Properties -> C/C++ -> Preprocessor] set Preprocessor Definitions: UILIB_STATIC - [Configuration Properties -> C/C++ -> Code Generation] set Runtime Libray: Multi-threaded(/MT) - [Configuration Properties -> Linker -> General] set Additional Library Directories: D:\duilib\lib\static - [Configuration Properties -> Linker -> Input] set Additional Dependencies: duilib.lib 3.make sure Configuration Properties -> Linker -> System : SubSystem's value is : Windows (/SUBSYSTEM:WINDOWS) 4. Click Apply, click Ok close dialog. 5.make sure you have duilib.lib in D:\duilib\lib\static (you can from http://thinkh5.com/topic/123-3-编译-duilib-静态库/ to learn how to build duilib's static lib (duilib.lib) ) OK, let's write some code. 6. add a new file named: app.h , copy blow code and past to your vs editor: #pragma once #include "UIlib.h" using namespace DuiLib; 7. add a new file named app.cpp, code: #include "app.h" class MainWndFrame : public WindowImplBase { protected: virtual CDuiString GetSkinFolder() override; virtual CDuiString GetSkinFile() override; virtual LPCTSTR GetWindowClassName(void) const override; public: static const LPCTSTR kClassName; static const LPCTSTR kMainWndFrame; }; DuiLib::CDuiString MainWndFrame::GetSkinFolder() { return m_PaintManager.GetInstancePath(); } DuiLib::CDuiString MainWndFrame::GetSkinFile() { return kMainWndFrame; } LPCTSTR MainWndFrame::GetWindowClassName(void) const { return kClassName; } const LPCTSTR MainWndFrame::kClassName = _T("main_wnd"); const LPCTSTR MainWndFrame::kMainWndFrame = _T("main_wnd.xml"); int APIENTRY wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPWSTR lpCmdLine, _In_ int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(lpCmdLine); // 设置窗口关联的实例 CPaintManagerUI::SetInstance(hInstance); // 设置皮肤的默认路径 CPaintManagerUI::SetCurrentPath(CPaintManagerUI::GetInstancePath()); CPaintManagerUI::SetResourcePath(_T("theme")); // 创建窗口 MainWndFrame* pMainWndFrame = new MainWndFrame; pMainWndFrame->Create(nullptr, MainWndFrame::kClassName, UI_WNDSTYLE_DIALOG, 0); pMainWndFrame->CenterWindow(); pMainWndFrame->ShowWindow(); CPaintManagerUI::MessageLoop(); if (nullptr != pMainWndFrame) { delete pMainWndFrame; } return 0; } 8. not harry to build or run the project, you may notice the string "main_wnd.xml" , whereis this xml file? it's in : D:\duilib\project\duilib_hello\Release\theme\main_wnd.xml and it's code is: <?xml version="1.0" encoding="UTF-8"?> <Window size="640,480" caption="0,0,0,35"> <Font id="0" name="Courier New Bold" size="22" bold="false"/> <VerticalLayout> <HorizontalLayout bkcolor="#FFff1a1a"/> <HorizontalLayout> <Button font="0" text="Hello DuQingnian!" bkcolor="#FF00b33c"/> </HorizontalLayout> <HorizontalLayout bkcolor="#FFffd633"/> </VerticalLayout> </Window> OK, now we can click build and run you will get this: A small question, how to close this application? you may notice there's no close ico or close button. So, how to close this application? You can click the red square in vs editor to close it OK , this hello world tutorial is complete! try it yourself! 目之所及,皆是回忆,心之所想,皆是过往 分享这篇帖子 链接帖子 分享到其他站点