DUILIB-编译ZIP皮肤到程序中

为了防止客户随意的修改皮肤文件,可以把皮肤文件打包为ZIP编译到程序中。虽说不能阻止牛掰软件的资源提取,但是防一般的菜鸟客户足矣。


下面是示例代码

#include "resource.h"
//导入的资源类型必须为ZIPRES,和WindowImplBase的定义一致。为所有资源打包,而不要直接打包资源的文件夹

class CDYFrameWnd : public WindowImplBase
{
public:
	explicit CDYFrameWnd(LPCTSTR pszXMLPath) :strXMLPath_(pszXMLPath){};
	explicit CDYFrameWnd(){};

	virtual ~CDYFrameWnd();


	virtual LPCTSTR GetWindowClassName()const       { return _T("Window"); }
	virtual CDuiString GetSkinFile()                { return _T("Window.xml"); }
	virtual CDuiString GetSkinFolder()              { return _T(""); }  //为UILIB_ZIPRESOURCE时候用不到,随便实现
	virtual void  InitWindow();
	virtual LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM /*lParam*/, bool& /*bHandled*/);
	virtual void Notify(TNotifyUI& msg);
	virtual CControlUI* CreateControl(LPCTSTR pstrClass);
	virtual LPCTSTR GetResourceID() const
	{
		return MAKEINTRESOURCE(IDR_ZIP_SKIN);
	};
	virtual UILIB_RESOURCETYPE GetResourceType() const
	{
		return UILIB_ZIPRESOURCE; 
	};

protected:
	CDuiString strXMLPath_;

};


需要注意的是WindowImplBase中是这样载入ZIP资源的,因此资源类型必须为ZIPRES


case UILIB_ZIPRESOURCE:
			{
				HRSRC hResource = ::FindResource(m_PaintManager.GetResourceDll(), GetResourceID(), _T("ZIPRES"));
				if( hResource == NULL )
					return 0L;
				DWORD dwSize = 0;
				HGLOBAL hGlobal = ::LoadResource(m_PaintManager.GetResourceDll(), hResource);
				if( hGlobal == NULL ) 
				{

添加后如下

/
//
// ZIPRES
//

IDR_ZIP_SKIN            ZIPRES                  "res\\UIZIP.zip"


代码可以去github获取:

https://github.com/CodeBees/duilib-Ex-Debug/tree/master/Demo/UIZIPExample



  • 5
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值