我用的DuiLib Ultimate版本,开发工具VS2019

github:https://github.com/qdtroy/DuiLib_Ultimate
gitee(码云):https://gitee.com/qdtroy/DuiLib_Ultimate

下载编译

 

新建项目

 

代码:

CMainWnd.h

#pragma once

class CMainWnd : public WindowImplBase
{
public://UI初始化
    CMainWnd(void);
    virtual ~CMainWnd(void);

public:
    virtual CDuiString GetSkinFile();
    virtual LPCTSTR GetWindowClassName(void) const;
    void Notify(TNotifyUI& msg);

public://系统消息
    LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled);
};

 

CMainWnd.cpp

#include "pch.h"
#include "CMainWnd.h"

CMainWnd::CMainWnd(void)
{

}

CMainWnd::~CMainWnd(void)
{

}

CDuiString CMainWnd::GetSkinFile()
{
    return _T("res.xml");//名字可以按窗口类名取
}

LPCTSTR CMainWnd::GetWindowClassName(void) const
{
    return _T("CMainWnd");//名字可以按窗口类名取
}

LRESULT CMainWnd::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
//    m_trayIcon.DeleteTrayIcon();
    bHandled = FALSE;//消息不再循环下去
    PostQuitMessage(0);// 退出程序
    return 0;
}

void CMainWnd::Notify(TNotifyUI& msg)
{
    CDuiString name = msg.pSender->GetName();
    if (msg.sType == _T("windowinit"))
    {
    }
    else if (msg.sType == _T("click"))
    {
        if (name.CompareNoCase(_T("closebtn")) == 0)
        {
            //if (MSGID_OK == CMsgWnd::MessageBox(m_hWnd, _T("Duilib旗舰版"), _T("确定退出duidemo演示程序?")))
            //{
                //::DestroyWindow(m_hWnd);
//            }
            Close(IDOK);
            PostQuitMessage(0);
            return;
        }
    }
}

framework.h

#pragma once

#include "targetver.h"
#define WIN32_LEAN_AND_MEAN             // 从 Windows 头文件中排除极少使用的内容
// Windows 头文件
#include <windows.h>
// C 运行时头文件
#include <stdlib.h>
#include <malloc.h>
#include <memory.h>
#include <tchar.h>

#include "e:\VCLib\DuiLib_Ultimate\DuiLib\UIlib.h"

using namespace DuiLib;

#ifdef _DEBUG
#   ifdef _UNICODE
#       pragma comment(lib, "e:\\VCLib\\DuiLib_Ultimate\\lib\\DuiLib_d.lib")
#   else
#       pragma comment(lib, "e:\\VCLib\\DuiLib_Ultimate\\lib\\DuiLibA_d.lib")
#   endif
#else
#   ifdef _UNICODE
#       pragma comment(lib, "e:\\VCLib\\DuiLib_Ultimate\\lib\\DuiLib.lib")
#   else
#       pragma comment(lib, "e:\\VCLib\\DuiLib_Ultimate\\lib\\DuiLibA.lib")
#   endif
#endif

DuiProject1.cpp

// DuiProject1.cpp : 定义应用程序的入口点。
//

#include "pch.h"
#include "framework.h"
#include "DuiProject1.h"
#include "CMainWnd.h"

#define MAX_LOADSTRING 100


void InitResource()
{
    // 资源类型
#ifdef _DEBUG
    CPaintManagerUI::SetResourceType(UILIB_FILE);
#else
    CPaintManagerUI::SetResourceType(UILIB_ZIPRESOURCE);
#endif
    // 资源路径
    CDuiString strResourcePath = CPaintManagerUI::GetInstancePath();
    // 加载资源
    switch (CPaintManagerUI::GetResourceType())
    {
    case UILIB_FILE:
    {
        strResourcePath += _T("skin\\");
        CPaintManagerUI::SetResourcePath(strResourcePath.GetData());
        // 加载资源管理器
        CResourceManager::GetInstance()->LoadResource(_T("res.xml"), NULL);
        break;
    }
    case UILIB_RESOURCE:
    {
        strResourcePath += _T("skin\\");
        CPaintManagerUI::SetResourcePath(strResourcePath.GetData());
        // 加载资源管理器
        CResourceManager::GetInstance()->LoadResource(_T("IDR_RES"), _T("xml"));
        break;
    }
    case UILIB_ZIP:
    {
        strResourcePath += _T("skin\\");
        CPaintManagerUI::SetResourcePath(strResourcePath.GetData());
        // 加密
        CPaintManagerUI::SetResourceZip(_T("duidemo_pwd.zip"), true, _T("duilib_ultimate"));
        //CPaintManagerUI::SetResourceZip(_T("duidemo.zip"), true);
        // 加载资源管理器
        CResourceManager::GetInstance()->LoadResource(_T("res.xml"), NULL);
        break;
    }
    case UILIB_ZIPRESOURCE:
    {
        strResourcePath += _T("skin\\");
        CPaintManagerUI::SetResourcePath(strResourcePath.GetData());
        HRSRC hResource = ::FindResource(CPaintManagerUI::GetResourceDll(), _T("IDR_ZIPRES"), _T("ZIPRES"));
        if (hResource != NULL) {
            DWORD dwSize = 0;
            HGLOBAL hGlobal = ::LoadResource(CPaintManagerUI::GetResourceDll(), hResource);
            if (hGlobal != NULL) {
                dwSize = ::SizeofResource(CPaintManagerUI::GetResourceDll(), hResource);
                if (dwSize > 0) {
                    CPaintManagerUI::SetResourceZip((LPBYTE)::LockResource(hGlobal), dwSize);
                    // 加载资源管理器
                    CResourceManager::GetInstance()->LoadResource(_T("res.xml"), NULL);
                }
            }
            ::FreeResource(hGlobal);
        }
    }
    break;
    }

    //// 注册控件
    //REGIST_DUICONTROL(CCircleProgressUI);
    //REGIST_DUICONTROL(CMyComboUI);
    //REGIST_DUICONTROL(CChartViewUI);
    //REGIST_DUICONTROL(CWndUI);
}

int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
    _In_opt_ HINSTANCE hPrevInstance,
    _In_ LPWSTR    lpCmdLine,
    _In_ int       nCmdShow)
{
    UNREFERENCED_PARAMETER(hPrevInstance);
    UNREFERENCED_PARAMETER(lpCmdLine);

        //HRESULT Hr = ::CoInitialize(NULL);
        //if (FAILED(Hr)) return 0;
        //// OLE
        //HRESULT hRes = ::OleInitialize(NULL);
        // 初始化UI管理器
    CPaintManagerUI::SetInstance(hInstance);
    // 初始化资源
    InitResource();

    //CDuiString strResourcePath = CPaintManagerUI::GetInstancePath();
    //// 加载资源
    //strResourcePath += _T("skin\\");
    //CPaintManagerUI::SetResourcePath(strResourcePath.GetData());

    // 创建主窗口
    CMainWnd* pMainWnd = new CMainWnd();
    if (pMainWnd == NULL) return 0;
    pMainWnd->Create(NULL, _T("MyDui"), UI_WNDSTYLE_FRAME, 0L, 0, 0, 800, 572);
    pMainWnd->CenterWindow();//窗口居中显示
    // 消息循环
    CPaintManagerUI::MessageLoop();
    // 销毁窗口
    delete pMainWnd;
    pMainWnd = NULL;
    // 清理资源
    CPaintManagerUI::Term();
    //// OLE
    //OleUninitialize();
    //// COM
    //::CoUninitialize();

    return 0;
}

配置项目

 

在bin目录中新建skin子目录,放入文件res.xml,内容如下:

<?xml version="1.0" encoding="utf-8"?>
<Window size="800,572" sizebox="4,4,6,6" caption="0,0,0,64" >
  <VerticalLayout name="root" bkcolor="#ffff0000">
      <HorizontalLayout inset="0,-1,0,0"  childalign="right" float="true" height="30" width="151" floatalign="right,top" bordercolor="#FFFF0000" bordersize="0" showshadow="true" shadowsize="5">
          <FadeButton name="minbtn" bkcolor="#ff00ff00" width="39" height="20" tooltip="最小化"/>
          <FadeButton name="closebtn" bkcolor="#ff00ff00" width="39" height="20" tooltip="关闭"/>
      </HorizontalLayout>
  </VerticalLayout>
</Window>

 

删除掉资源文件中自动生成的多余东西,这个不做也行,只是生成的exe稍大一点点 

 

编译运行,程序界面如下: