墨香年少 32 发布于 2023年8月11日 when you add the xml file to exe, if you open the exe by winrar, you can see the xml file. a new way is add xml file to a dll OK, let see the xml file's content <?xml version="1.0" encoding="UTF-8"?> <Window size="340,280" caption="0,0,0,35"> <Font id="0" name="Courier New Bold" size="22" bold="false"/> <VerticalLayout> <HorizontalLayout bkcolor="#FFff1a1a"/> <HorizontalLayout> <Button name="btn_close" font="0" text="duilib use dll resource" bkcolor="#FF00b33c"/> </HorizontalLayout> <HorizontalLayout bkcolor="#FFffd633"/> </VerticalLayout> </Window> and rename xml file: main_wnd.xml make main_wnd.xml to theme.zip 1. create a new project ( dll project ) add theme.zip to the resource, type is ZIPRES note: please copy theme.zip to :D:\duilib\project\resdll build project. you will get dll: 1>Finished generating code 1>resdll.vcxproj -> D:\duilib\project\duilib_hello\Release\resdll.dll ========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ========== add code to app.cpp HINSTANCE hRCDll = ::LoadLibrary(_T("resdll.dll")); CPaintManagerUI::SetResourceDll(hRCDll); run exe you can download the dll project and duilib_hello project resdll.zip duilib_hello.zip 目之所及,皆是回忆,心之所想,皆是过往 分享这篇帖子 链接帖子 分享到其他站点
墨香年少 32 发布于 2023年8月11日 app.h #pragma once #include <windows.h> #include "UIlib.h" using namespace DuiLib; app.cpp #include "app.h" class MainWndFrame : public WindowImplBase { protected: virtual CDuiString GetSkinFolder() override; virtual CDuiString GetSkinFile() override; virtual LPCTSTR GetWindowClassName(void) const override; virtual DuiLib::UILIB_RESOURCETYPE GetResourceType() const override; virtual LPCTSTR GetResourceID() 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; } DuiLib::UILIB_RESOURCETYPE MainWndFrame::GetResourceType() const { return UILIB_ZIPRESOURCE; } LPCTSTR MainWndFrame::GetResourceID() const { return MAKEINTRESOURCE(101); } 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")); HINSTANCE hRCDll = ::LoadLibrary(_T("resdll.dll")); CPaintManagerUI::SetResourceDll(hRCDll); // 创建窗口 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; } 目之所及,皆是回忆,心之所想,皆是过往 分享这篇帖子 链接帖子 分享到其他站点
墨香年少 32 发布于 2023年8月11日 app.cpp MAKEINTRESOURCE(101); why is 101? where is this number? you can find the number in : D:\duilib\project\resdll\resource.h #define IDR_ZIPRES1 101 目之所及,皆是回忆,心之所想,皆是过往 分享这篇帖子 链接帖子 分享到其他站点
墨香年少 32 发布于 2023年8月11日 you can download this dll to test your application [Release][x86] resdll.dll 目之所及,皆是回忆,心之所想,皆是过往 分享这篇帖子 链接帖子 分享到其他站点