当前位置:   article > 正文

duilib(Troy)------简单的项目实例_duilib troy

duilib troy

实现效果图:

创建一个win32项目

(1)stdafx.h

#pragma once

//
TODO:  在此处引用程序需要的其他头文件
//
#if !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_)
#define AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_
//#define WIN32_LEAN_AND_MEAN    
#define _CRT_SECURE_NO_DEPRECATE

#include <windows.h>
#include <objbase.h>
#include <zmouse.h>

#include "..\..\..\DuiLib\UIlib.h"

using namespace DuiLib;

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

#endif 
(2)Win32Project1.cpp

#include "StdAfx.h"
#include <exdisp.h>
#include <comdef.h>
#include "resource.h"
#include <ShellAPI.h>
#include "MainWnd.h"

#define _CRTDBG_MAP_ALLOC
#include<stdlib.h>
#include<crtdbg.h>


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\\Monster\\");
                       CPaintManagerUI::SetResourcePath(strResourcePath.GetData());
                       // 加载资源管理器
                       CResourceManager::GetInstance()->LoadResource(_T("res.xml"), NULL);
                       break;
    }
    case UILIB_RESOURCE:
    {
                           strResourcePath += _T("skin\\Monster\\");
                           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\\duidemo\\");
                              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;
    }
}

int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPSTR /*lpCmdLine*/, int nCmdShow)
{
    //_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
    //_CrtDumpMemoryLeaks();
    // COM
    HRESULT Hr = ::CoInitialize(NULL);
    if (FAILED(Hr)) return 0;
    // OLE
    HRESULT hRes = ::OleInitialize(NULL);
    // 初始化UI管理器
    CPaintManagerUI::SetInstance(hInstance);
    // 初始化资源
    InitResource();


    // 创建主窗口
    CMainWnd* pMainWnd = new CMainWnd();
    if (pMainWnd == NULL) return 0;
    pMainWnd->Create(NULL, _T("duilib使用例子集锦(By Troy)"), UI_WNDSTYLE_FRAME, 0L, 0, 0, 800, 572);
    pMainWnd->CenterWindow();
    // 消息循环
    CPaintManagerUI::MessageLoop();
    // 销毁窗口
    delete pMainWnd;
    pMainWnd = NULL;

    // 清理资源
    CPaintManagerUI::Term();
    // OLE
    OleUninitialize();
    // COM
    ::CoUninitialize();

    return 0;
}
(3)MainWnd.h

#pragma once

class CMainWnd : public WindowImplBase
{
public:
    CMainWnd();
    ~CMainWnd();

public:// UI初始化
    void Notify(TNotifyUI& msg);
    DuiLib::CDuiString GetSkinFile();
    LPCTSTR GetWindowClassName() const;
    void InitWindow();

    DUI_DECLARE_MESSAGE_MAP()
};
(4)MainWnd.cpp

#include "stdafx.h"
#include "MainWnd.h"

DUI_BEGIN_MESSAGE_MAP(CMainWnd, WindowImplBase)
DUI_END_MESSAGE_MAP()

CMainWnd::CMainWnd()
{

}

CMainWnd::~CMainWnd()
{

}


void CMainWnd::InitWindow()
{
}


DuiLib::CDuiString CMainWnd::GetSkinFile()
{
    return _T("XML_MAIN");
}

LPCTSTR CMainWnd::GetWindowClassName() const
{
    return _T("MainWnd");
}

void CMainWnd::Notify(TNotifyUI& msg)
{
    CDuiString name = msg.pSender->GetName();
    if (msg.sType == _T("click"))
    {
        if (name.CompareNoCase(_T("btn_activate")) == 0)
        {
            CEditUI* pEdit = static_cast<CEditUI*>(m_pm.FindControl(_T("edt_pass")));
            if (pEdit != nullptr)
            {
                CDuiString strText = pEdit->GetText();
            }
        }
    }
    return WindowImplBase::Notify(msg);
}
 

布局文件main.xml:

<?xml version="1.0" encoding="utf-8"?>
<Window size="550,350" sizebox="4,4,6,6" roundcorner="0,0" caption="0,0,0,64" bktrans="false" mininfo="550,350" showshadow="true" shadowimage="main/shadow.png" shadowsize="6" shadowcorner="8,8,8,8">
  <Font shared="true" id="0" name="宋体" size="13" default="true"/>
  <Font shared="true" id="1" name="宋体" size="12" bold="false" underline="true"/>
  <Font shared="true" id="2" name="宋体" size="16" bold="false"/>
  <Font shared="true" id="3" name="宋体" size="18" bold="false"/>
  <Default name="VScrollBar" shared="true" value="width=&quot;8&quot; showbutton1=&quot;false&quot; showbutton2=&quot;false&quot; thumbnormalimage=&quot;file='common/vscrollbar.png' source='0,60,8,100' corner='0,4,0,4'&quot; thumbhotimage=&quot;file='common/vscrollbar.png' source='8,60,16,100' corner='0,4,0,4'&quot; thumbpushedimage=&quot;file='common/vscrollbar.png' source='16,60,24,100' corner='0,4,0,4'&quot; railnormalimage=&quot;&quot; railhotimage=&quot;&quot; railpushedimage=&quot;&quot; raildisabledimage=&quot;&quot; bknormalimage=&quot;file='common/vscrollbar.png' source='0,0,8,60' corner='0,4,0,4'&quot; bkhotimage=&quot;&quot; bkpushedimage=&quot;&quot; bkdisabledimage=&quot;&quot; "/>
  <Default name="HScrollBar" shared="true" value="height=&quot;8&quot; showbutton1=&quot;false&quot; showbutton2=&quot;false&quot; thumbnormalimage=&quot;file='common/hscrollbar.png' source='0,0,32,8' corner='4,0,4,0'&quot; thumbhotimage=&quot;file='common/hscrollbar.png' source='0,8,32,16' corner='4,0,4,0'&quot; thumbpushedimage=&quot;file='common/hscrollbar.png' source='0,16,32,24' corner='4,0,4,0'&quot; railnormalimage=&quot;&quot; railhotimage=&quot;&quot; railpushedimage=&quot;&quot; raildisabledimage=&quot;&quot; bknormalimage=&quot;file='common/hscrollbar.png' source='0,0,32,8' corner='4,0,4,0'&quot; bkhotimage=&quot;&quot; bkpushedimage=&quot;&quot; bkdisabledimage=&quot;&quot; "/>
  <Style name="btnstyle_queding" shared="true" value="stateimage=&quot;res='common/queding.png' corner='6,6,6,6'&quot; statecount=&quot;3&quot; width=&quot;59&quot; height=&quot;23&quot; tooltip=&quot;确定&quot;"  />
  <Style name="btnstyle_quxiao" shared="true" value="stateimage=&quot;res='common/quxiao.png'&quot; statecount=&quot;3&quot; width=&quot;59&quot; height=&quot;23&quot; tooltip=&quot;取消&quot;"  />

  <Style name="option_style" value="cursor=&quot;hand&quot; align=&quot;left&quot; valign=&quot;vcenter&quot;  textcolor=&quot;#FFAFADAD&quot; hottextcolor=&quot;#FFFFFFFF&quot; textpadding=&quot;20,0,6,0&quot;"/>
  <Style name="main_tab" value="textcolor=&quot;#FF386382&quot; font=&quot;2&quot; normalimage=&quot;tabbar_normal.png&quot; hotimage=&quot;tabbar_hover.png&quot; pushedimage=&quot;tabbar_pushed.png&quot; selectedimage=&quot;tabbar_pushed.png&quot; group=&quot;tab_header&quot; " />
  <Style name="colortab_style" shared="true" value="textcolor=&quot;#FFAFADAD&quot; hottextcolor=&quot;#FFFFFFFF&quot; selectedtextcolor=&quot;#FFFFFFFF&quot; textpadding=&quot;6,0,6,0&quot; bkcolor=&quot;#FF2c2c2c&quot; hotbkcolor=&quot;#FF4b4b4b&quot; pushedbkcolor=&quot;#FF424242&quot; selectedbkcolor=&quot;#FF424242&quot; group=&quot;tab_header&quot;"  />
  <Style name="combo_style" value="height=&quot;28&quot; textcolor=&quot;#FFFFFFFF&quot; itemvalign=&quot;vcenter&quot; textpadding=&quot;4,1,28,1&quot; normalimage=&quot;res='common/combo.png' source='0,0,161,28' corner='2,2,28,2'&quot; hotimage=&quot;res='common/combo.png' source='0,28,161,56' corner='2,2,28,2'&quot; pushedimage=&quot;res='common/combo.png' source='0,56,161,84' corner='2,2,28,2'&quot;" />
  <Style name="list_style" value="headerbkimage=&quot;res='common/list_header_bg.png'&quot; itemalign=&quot;center&quot; itemlinecolor=&quot;#FF888888&quot; itemshowrowline=&quot;true&quot; itemshowcolumnline=&quot;true&quot;" />
  <Style name="edit_style" value="width=&quot;200&quot; height=&quot;26&quot; textpadding=&quot;6,6,6,6&quot; bkcolor=&quot;#FF666666&quot; nativebkcolor=&quot;#FF666666&quot; bkimage=&quot;res='common/edit_bk.png' corner='6,6,6,6'&quot;" />
  <Style name="btn_style" value="drag=&quot;false&quot; height=&quot;30&quot; textpadding=&quot;6,0,6,0&quot; normalimage=&quot;res='common/button_normal.png' corner='4,4,4,4'&quot; hotimage=&quot;res='common/button_hover.png' corner='4,4,4,4'&quot; pushedimage=&quot;res='common/button_pushed.png' corner='4,4,4,4'&quot; focusedimage1=&quot;res='common/button_pushed.png' corner='4,4,4,4'&quot; selectedimage=&quot;res='common/button_pushed.png' corner='4,4,4,4'&quot;"  />
  <Style name="treenode_folder_style" value="padding=&quot;16,1,0,0&quot; width=&quot;16&quot; height=&quot;16&quot; normalimage=&quot;file='common/treeview_b.png' source='0,0,16,16' &quot; hotimage=&quot;file='common/treeview_b.png' source='16,0,32,16' &quot; selectedimage=&quot;file='common/treeview_a.png' source='0,0,16,16' &quot; selectedhotimage=&quot;file='common/treeview_a.png' source='16,0,32,16' &quot;"/>
  <Style name="treenode_checkbox_style" value="width=&quot;16&quot; height=&quot;16&quot; normalimage=&quot;file='common/unchecked.png' &quot; selectedimage=&quot;file='common/checked.png'&quot;" />
  <Style name="treeview_item_style" value="folderattr=&quot;treenode_folder_style&quot; checkboxattr=&quot;treenode_checkbox_style&quot;"/>
  <Style name="listex_item_style" value="checkboxwidth=&quot;16&quot; checkboxheight=&quot;16&quot; checkboxnormalimage=&quot;file='common/unchecked.png'&quot; checkboxselectedimage=&quot;file='common/checked.png'&quot;"/>
  <Style name="colorbtn_style" shared="true" value="textcolor=&quot;#FFAFADAD&quot; hottextcolor=&quot;#FFFFFFFF&quot; textpadding=&quot;6,0,6,0&quot; bkcolor=&quot;#FF2c2c2c&quot; hotbkcolor=&quot;#FF4b4b4b&quot; pushedbkcolor=&quot;#FF424242&quot;"  />
  <Style name="cb_style" shared="true" value="style=&quot;option_style&quot; height=&quot;16&quot; normalimage=&quot;res='common/cb_normal.png' dest='0,0,16.16'&quot; hotimage=&quot;res='common/cb_hot.png' dest='0,0,16.16'&quot; pushedimage=&quot;res='common/cb_pushed.png' dest='0,0,16.16'&quot; selectedimage=&quot;res='common/cb_selected.png' dest='0,0,16,16'&quot;" />
  <Style name="radio_style" shared="true" value="style=&quot;option_style&quot; height=&quot;17&quot; stateimage=&quot;res='common/radio_normal.png' dest='0,0,17,17'&quot; statecount=&quot;2&quot; selectedstateimage=&quot;res='common/radio_selected.png' dest='0,0,17,17'&quot; selectedstatecount=&quot;2&quot;" />

  <VerticalLayout name="root" bkcolor="#FF202223" bkimage="file='png/bkimage.jpg'">
    <HorizontalLayout name="appbar" height="64" >
      <HorizontalLayout name="apptitle" childpadding="6">
        <Container width="64" height="64" bkimage="logo.jpg" />
        <VerticalLayout inset="0,10,0,0" childpadding="5">
          <Label name="title_lb" height="20" autocalcwidth="true" text="MONSTER" valign="vcenter" align="left" wordbreak="false" textcolor="#00000000" font="2" tooltip="duilib开源项目圈"/>
        </VerticalLayout>
      </HorizontalLayout>

      <HorizontalLayout inset="0,-1,0,0" float="true" height="30" width="100" floatalign="right,top" bordercolor="#FFFF0000" bordersize="0">
        <FadeButton name="minbtn" virtualwnd="mainpage" width="28" height="20" tooltip="最小化" normalimage="file='sysbtn/btn_mini_normal.png'" hotimage="file='sysbtn/btn_mini_highlight.png'" pushedimage="file='sysbtn/btn_mini_down.png' "/>
        <FadeButton name="maxbtn" virtualwnd="mainpage" width="28" height="20" tooltip="最大化" normalimage="file='sysbtn/btn_max_normal.png'" hotimage="file='sysbtn/btn_max_highlight.png'" pushedimage="file='sysbtn/btn_max_down.png' "/>
        <FadeButton name="restorebtn" virtualwnd="mainpage" width="28" height="20" tooltip="还原" visible="false" normalimage="file='sysbtn/btn_restore_normal.png'" hotimage="file='sysbtn/btn_restore_highlight.png'" pushedimage="file='sysbtn/btn_restore_down.png' "/>
        <FadeButton name="closebtn" virtualwnd="mainpage" width="39" height="20" tooltip="关闭" normalimage="file='sysbtn/btn_close_normal.png'" hotimage="file='sysbtn/btn_close_highlight.png'" pushedimage="file='sysbtn/btn_close_down.png' "/>
      </HorizontalLayout>

    </HorizontalLayout>

    <VerticalLayout name="body">
        <VerticalLayout height="130" padding="225,0,0,0">
            <Label width="100" height="100" bkimage="file='png/circle.png'" borderround="100,100" />
            <Label height="20" autocalcwidth="true" text="MONSTER" wordbreak="false" textcolor="#00000000" font="2" padding="20,0,0,0"/>
        </VerticalLayout>
        <VerticalLayout height="30" padding="165,30,0,0">
            <HorizontalLayout>
                <Control width="16" height="16" valign="center" bkimage="file='png/password_1.png'"/>
                <Control width="5"/>
                <Edit name="edt_pass" tipvalue="密码" style="edit_style" password="true" passwordchar="*"/>
            </HorizontalLayout>
        </VerticalLayout>
        <VerticalLayout height="180" padding="180,15,0,0">
            <Button name="btn_activate" width="210" height="40" normalimage="file='png/btn_active_n.png'" hotimage="file='png/btn_active_h.png'" pushedimage="file='png/btn_active_p.png'" text="注 册" />
        </VerticalLayout>
    </VerticalLayout>
  </VerticalLayout>
</Window>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Guff_9hys/article/detail/942889
推荐阅读
  

闽ICP备14008679号