赞
踩
实现效果图:
创建一个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="8" showbutton1="false" showbutton2="false" thumbnormalimage="file='common/vscrollbar.png' source='0,60,8,100' corner='0,4,0,4'" thumbhotimage="file='common/vscrollbar.png' source='8,60,16,100' corner='0,4,0,4'" thumbpushedimage="file='common/vscrollbar.png' source='16,60,24,100' corner='0,4,0,4'" railnormalimage="" railhotimage="" railpushedimage="" raildisabledimage="" bknormalimage="file='common/vscrollbar.png' source='0,0,8,60' corner='0,4,0,4'" bkhotimage="" bkpushedimage="" bkdisabledimage="" "/>
<Default name="HScrollBar" shared="true" value="height="8" showbutton1="false" showbutton2="false" thumbnormalimage="file='common/hscrollbar.png' source='0,0,32,8' corner='4,0,4,0'" thumbhotimage="file='common/hscrollbar.png' source='0,8,32,16' corner='4,0,4,0'" thumbpushedimage="file='common/hscrollbar.png' source='0,16,32,24' corner='4,0,4,0'" railnormalimage="" railhotimage="" railpushedimage="" raildisabledimage="" bknormalimage="file='common/hscrollbar.png' source='0,0,32,8' corner='4,0,4,0'" bkhotimage="" bkpushedimage="" bkdisabledimage="" "/>
<Style name="btnstyle_queding" shared="true" value="stateimage="res='common/queding.png' corner='6,6,6,6'" statecount="3" width="59" height="23" tooltip="确定"" />
<Style name="btnstyle_quxiao" shared="true" value="stateimage="res='common/quxiao.png'" statecount="3" width="59" height="23" tooltip="取消"" />
<Style name="option_style" value="cursor="hand" align="left" valign="vcenter" textcolor="#FFAFADAD" hottextcolor="#FFFFFFFF" textpadding="20,0,6,0""/>
<Style name="main_tab" value="textcolor="#FF386382" font="2" normalimage="tabbar_normal.png" hotimage="tabbar_hover.png" pushedimage="tabbar_pushed.png" selectedimage="tabbar_pushed.png" group="tab_header" " />
<Style name="colortab_style" shared="true" value="textcolor="#FFAFADAD" hottextcolor="#FFFFFFFF" selectedtextcolor="#FFFFFFFF" textpadding="6,0,6,0" bkcolor="#FF2c2c2c" hotbkcolor="#FF4b4b4b" pushedbkcolor="#FF424242" selectedbkcolor="#FF424242" group="tab_header"" />
<Style name="combo_style" value="height="28" textcolor="#FFFFFFFF" itemvalign="vcenter" textpadding="4,1,28,1" normalimage="res='common/combo.png' source='0,0,161,28' corner='2,2,28,2'" hotimage="res='common/combo.png' source='0,28,161,56' corner='2,2,28,2'" pushedimage="res='common/combo.png' source='0,56,161,84' corner='2,2,28,2'"" />
<Style name="list_style" value="headerbkimage="res='common/list_header_bg.png'" itemalign="center" itemlinecolor="#FF888888" itemshowrowline="true" itemshowcolumnline="true"" />
<Style name="edit_style" value="width="200" height="26" textpadding="6,6,6,6" bkcolor="#FF666666" nativebkcolor="#FF666666" bkimage="res='common/edit_bk.png' corner='6,6,6,6'"" />
<Style name="btn_style" value="drag="false" height="30" textpadding="6,0,6,0" normalimage="res='common/button_normal.png' corner='4,4,4,4'" hotimage="res='common/button_hover.png' corner='4,4,4,4'" pushedimage="res='common/button_pushed.png' corner='4,4,4,4'" focusedimage1="res='common/button_pushed.png' corner='4,4,4,4'" selectedimage="res='common/button_pushed.png' corner='4,4,4,4'"" />
<Style name="treenode_folder_style" value="padding="16,1,0,0" width="16" height="16" normalimage="file='common/treeview_b.png' source='0,0,16,16' " hotimage="file='common/treeview_b.png' source='16,0,32,16' " selectedimage="file='common/treeview_a.png' source='0,0,16,16' " selectedhotimage="file='common/treeview_a.png' source='16,0,32,16' ""/>
<Style name="treenode_checkbox_style" value="width="16" height="16" normalimage="file='common/unchecked.png' " selectedimage="file='common/checked.png'"" />
<Style name="treeview_item_style" value="folderattr="treenode_folder_style" checkboxattr="treenode_checkbox_style""/>
<Style name="listex_item_style" value="checkboxwidth="16" checkboxheight="16" checkboxnormalimage="file='common/unchecked.png'" checkboxselectedimage="file='common/checked.png'""/>
<Style name="colorbtn_style" shared="true" value="textcolor="#FFAFADAD" hottextcolor="#FFFFFFFF" textpadding="6,0,6,0" bkcolor="#FF2c2c2c" hotbkcolor="#FF4b4b4b" pushedbkcolor="#FF424242"" />
<Style name="cb_style" shared="true" value="style="option_style" height="16" normalimage="res='common/cb_normal.png' dest='0,0,16.16'" hotimage="res='common/cb_hot.png' dest='0,0,16.16'" pushedimage="res='common/cb_pushed.png' dest='0,0,16.16'" selectedimage="res='common/cb_selected.png' dest='0,0,16,16'"" />
<Style name="radio_style" shared="true" value="style="option_style" height="17" stateimage="res='common/radio_normal.png' dest='0,0,17,17'" statecount="2" selectedstateimage="res='common/radio_selected.png' dest='0,0,17,17'" selectedstatecount="2"" />
<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>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。