Jump to content
Sign in to follow this  
墨香年少

7. use dll resource

Recommended Posts

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


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

Share this post


Link to post
Share on other sites

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

 


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

Share this post


Link to post
Share on other sites

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


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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

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