跳转到帖子
登录关注  
墨香年少

7. use dll resource

已推荐帖子

when you add the xml file to exe, if you open the exe by winrar, you can see the xml file.

exe_file.png

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 )

create_dll_project.png

 

add theme.zip to the resource, type is ZIPRES

note: please copy theme.zip to :D:\duilib\project\resdll

res_preview.png

 

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

run_exe.png

 

you can download the dll project and duilib_hello project

resdll.zip

duilib_hello.zip


目之所及,皆是回忆,心之所想,皆是过往

分享这篇帖子


链接帖子
分享到其他站点

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;
}

 


目之所及,皆是回忆,心之所想,皆是过往

分享这篇帖子


链接帖子
分享到其他站点

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

number.png


目之所及,皆是回忆,心之所想,皆是过往

分享这篇帖子


链接帖子
分享到其他站点

创建帐户或登录来提出意见

你需要成为会员才能提出意见

创建帐户

注册成为会员。只要几个简单步骤!

注册帐户

登录

已有帐户? 请登录。

现在登录
登录关注  

×
×
  • 创建新的...

重要信息

注册必须使用2-8个中文汉字作为账号