DUILIB-编译ZIP皮肤到程序中

Bertha 。 2022-08-12 01:19 41阅读 0赞

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

下面是示例代码

  1. #include "resource.h"
  2. //导入的资源类型必须为ZIPRES,和WindowImplBase的定义一致。为所有资源打包,而不要直接打包资源的文件夹
  3. class CDYFrameWnd : public WindowImplBase
  4. {
  5. public:
  6. explicit CDYFrameWnd(LPCTSTR pszXMLPath) :strXMLPath_(pszXMLPath){};
  7. explicit CDYFrameWnd(){};
  8. virtual ~CDYFrameWnd();
  9. virtual LPCTSTR GetWindowClassName()const { return _T("Window"); }
  10. virtual CDuiString GetSkinFile() { return _T("Window.xml"); }
  11. virtual CDuiString GetSkinFolder() { return _T(""); } //为UILIB_ZIPRESOURCE时候用不到,随便实现
  12. virtual void InitWindow();
  13. virtual LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM /*lParam*/, bool& /*bHandled*/);
  14. virtual void Notify(TNotifyUI& msg);
  15. virtual CControlUI* CreateControl(LPCTSTR pstrClass);
  16. virtual LPCTSTR GetResourceID() const
  17. {
  18. return MAKEINTRESOURCE(IDR_ZIP_SKIN);
  19. };
  20. virtual UILIB_RESOURCETYPE GetResourceType() const
  21. {
  22. return UILIB_ZIPRESOURCE;
  23. };
  24. protected:
  25. CDuiString strXMLPath_;
  26. };

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

  1. case UILIB_ZIPRESOURCE:
  2. {
  3. HRSRC hResource = ::FindResource(m_PaintManager.GetResourceDll(), GetResourceID(), _T("ZIPRES"));
  4. if( hResource == NULL )
  5. return 0L;
  6. DWORD dwSize = 0;
  7. HGLOBAL hGlobal = ::LoadResource(m_PaintManager.GetResourceDll(), hResource);
  8. if( hGlobal == NULL )
  9. {

添加后如下

  1. /
  2. //
  3. // ZIPRES
  4. //
  5. IDR_ZIP_SKIN ZIPRES "res\\UIZIP.zip"

代码可以去github获取:

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

发表评论

表情:
评论列表 (有 0 条评论,41人围观)

还没有评论,来说两句吧...

相关阅读

    相关 duilib-Ex-Debug

    由于一些事件google无法访问,托管在其上的项目也无法检出也基本无人更新,因此维护了一个版本,用于排除已有的bug和扩展一些功能。这样可以避免重复造轮子和重复的修车子。欢迎大

    相关 duilib消息类型

    duilib作为一个轻量快速的开源界面库,有很多值得学习的地方,虽然也有不少人吐槽它的各种问题,但是它是一种技术,技术没有正确与错误,好与坏之分,可以取其精华,学为己用就足够了