Duilib的一些资料

 http://blog.csdn.net/tszhao/article/category/904045?viewmode=list

 

如何在WTL和MFC中使用duilib及如何静态使用duilib库!(初级讲解 附带一个Demo)

现在把我在实现过程中遇到的问题及解决方法列举一下 以便大家以后遇到问题的时候做一个参考。



1.我喜欢用静态库,不喜欢用动态库,用动态库就好像穿衣服还要随身携带衣架一样,多余还麻烦。

所以在用这个库的时候 第一件事就是把动态库变成静态库。还有改用成 unicode字符集

(1).找到uilib.h头文件 注释掉原有的定义:添加新的宏 #define UILIB_API

//#ifdef UILIB_EXPORTS
//#define UILIB_API __declspec(dllexport)
//#else
//#define UILIB_API __declspec(dllimport)
//#endif

(2)编译后不会报错,然后 在使用时就可以直接包含这个静态库了 同时要注意一点 还需要包含 几个静态库oledlg.lib dui.lib winmm.lib comctl32.lib

虽然也不简单,但是却可以让程序生成后 只有一个exe 也没有其他累赘。

2. 包含之后 编译工程 会报错createtextserver没有定义什么的。这个是因为新版本中加入了richedit支持,这个directui的 需要用到 texthost和textserver 这时候 需要引用richedit.dll和richedit.lib 为了方便,我把这部分的导入 放到了duilib库里面了。 至于是什么代码我就不贴了 导入库的代码 是个程序员就会了。



3.如果你的wtl ATL MFC文件已经包含了 atltypes之类的头文件,那你会发现会出N多的 crect cpoint csize等 说不知道用哪个。因为duilib自己实现了这三个函数 和ATL MFC WL里面的冲突了。那么这时候怎么办呢?.. 当然是用宏了,我们在duilib的 uibase.h下面可以找到他们定义 在定义前加#ifndef DUI_NOTYPES 定义后追加 #endif 这样我们在WTL中引入duilib库的时候 引用前加入 #define DUI_NOTYPES 就可以屏蔽掉那些错误了。



4. 接下来的问题 都快让我崩溃了,不过最后还是解决了。

在前面问题逐一解决之后 你会发现 项目里的很多地方都莫名其妙的报错了,甚至连最基本的 CDC CmemeryDC Cpen什么的都不认了 报一堆错误。

错误原因在于duilib里面的 windowsx.h头文件,这个是sdk编程人员不可能不知道的头文件了,里面是一些宏的定义,大大的方便了sdk编程。

而在这里却成了阻碍,那么怎么办呢? 我看了下报错的地方 又看了下windowsx里面宏,发现其实原因很简单,里面的一些宏定义和WTL的函数定义冲突了。那么这个时候 我们需要使用微软的 函数保护机制了。在我的项目中有冲突的是下面几个函数 SelectFont SelectPen 其实还有很多 selectbrush等。报什么错就加什么 没有必要一次加齐。

#ifdef _INC_WINDOWSX
#undef SelectFont
#undef SelectPen
#endif // _INC_WINDOWSX



5.那么到这个时候就可以正常的在WTL中使用duilib库了。



6.那么我们来说说 那棵树的实现。

树无疑 就是里面的list靠缩进实现了。节点我选择用以下模式做的。这样后面排序的时候 我只需要交换CHorizontalLayoutUI就可以了 而无须改变

CListContainerElementUI 索引号了。

CListContainerElementUI

CHorizontalLayoutUI

控件

控件

CHorizontalLayoutUI

CListContainerElementUI

7.自动计算下滚动条!

CListContainerElementUI 没有自动计算下滚动条的功能,可能是因为是容器 里面的东西多少位置之类的都无法确定吧。

我的项目为了针对我这个项目 我在CHorizontalLayoutUI 插入了Ctextui 在底层库里面加入自动计算Ctextui 的宽度并设置CListContainerElementUI 宽度的逻辑就可以了

在这个过程总需要注意CListContainerElementUI 的setfixwight 有刷新的 会导致死循环 所以要加一个默认参数。



8.排序 排序就不多说的 原理比较简单 一个快速排序,然后 颠倒CHorizontalLayoutUI和 tag就可以了、我的快排写的 比较麻烦好像 因为当时比较着急 写的时候比较乱 不过还可以 至少实现功能了,但是目前只是叶子节点排序,如果想实现非叶子节点排序也不是不可以,但是会比较麻烦 因为我也不用 就没写,有兴趣的自己写下吧。



9.最后 因为群里面有人希望出一个demo 我就简单写一个demo 但是没再WTL用 因为怕麻烦。

demo真是非常之简单,只有一个treeviwe 其他的什么都没有.连标题栏什么都没写 那些我相信大家很简单的就能写出来。我把demo放到csdn上 想看的下载吧 。

先贴图:treeviewdemo 点击这里下载源码

哦 对了 忘了 QQ:672496008 如果有编译不了 或者什么地方不明白的可以问我... 就这个demo而言我还是会的。

超出这个demo范围我可能就帮不上忙了 我也才接触1个星期而已!


原文:http://blog.csdn.net/lin98666lin/article/details/6580461

DuiLib——xml配置项

DUILibxml配置项
根节点 子类 属性 类型
Window
|--------Image 图片信息
| o------name string
| o------restype string
| o------mask unsigned long#
|
|--------Font 字体信息
| o------name string
| o------size long
| o------bold bool
| o------underline bool
| o------default bool
|
|--------Default 默认Attribute属性
o------name string
o------value string

root(Window属性)
o--size 窗体初始化大小 SIZE(int cx, int cy)
o--sizebox 窗体区域 RECT(long left, long top, long right,long bottom)
o--caption 窗体标题栏区域 RECT(long left, long top, long right,long bottom)
o--roundcorner 圆角大小 SIZE(int cx, int cy)
o--mininfo 窗体最小大小 SIZE(int cx, int cy)
o--maxinfo 窗体最大大小 SIZE(int cx, int cy)
o--showdirty 窗体显示 bool [true|false]
o--alpha 窗体透明度 int
o--bktrans 背景是否支持透明 bool [true|false]
o--disabledfontcolor 无效字体颜色 string #RRGGBBAA
o--defaultfontcolor 默认字体颜色 string #RRGGBBAA
o--linkfontcolor 链接正常字体色 string #RRGGBBAA
o--linkhoverfontcolor链接悬停字体色 string #RRGGBBAA
o--selectedcolor 字体被选后颜色 string #RRGGBBAA

公共资源
Image
|------o file/res string
|------o restype string
|------o dest RECT(long left, long top, long right,long bottom)
|------o source RECT(long left, long top, long right,long bottom)
|------o corner RECT(long left, long top, long right,long bottom)
|------o mask string #FFFFFFFF
|------o fade byte
|------o hole bool [true|false]
|------o xtiled bool [true|false]
|------o ytiled bool [true|false]
使用说明:
// 1、aaa.jpg
// 2、file='aaa.jpg' res='' restype='0' dest='0,0,0,0' source='0,0,0,0' corner='0,0,0,0'
// mask='#FF0000' fade='255' hole='false' xtiled='false' ytiled='false'


Font
Default

控件Control

控件名称 类

控件基类
Control CControlUI
|------o pos RECT(long left, long top, long right,long bottom)
|------o relativepos (int nMoveXPercent, int nMoveYPercent,int nZoomXPercent,int nZoomYPercent)
|------o padding RECT(long left, long top, long right,long bottom)
|------o bkcolor/bkcolor1 string #RRGGBBAA
|------o bkcolor2 string #RRGGBBAA
|------o bkcolor3 string #RRGGBBAA
|------o bordercolor string #RRGGBBAA
|------o focusbordercolor string #RRGGBBAA
|------o bordersize int
|------o borderround SIZE(int x, int y)
|------o bkimage Image 属性
|------o width int
|------o height int
|------o minwidth int
|------o minheight int
|------o maxwidth int
|------o maxheight int
|------o name string
|------o text string
|------o tooltip string
|------o userdata string
|------o enabled bool [true|false]
|------o mouse bool [true|false]
|------o visible bool [true|false]
|------o float bool [true|false]
|------o shortcut TCHAR
|------o menu bool [true|false]



容器
Container CContainerUI
|------o inset RECT(long left, long top, long right,long bottom)
|------o mousechild bool [true|false]
|------o vscrollbar bool [true|false]
|------o hscrollbar bool [true|false]
|------o childpadding int

布局管理器
VerticalLayout CVerticalLayoutUI : public CContainerUI
|------o sepheight int
|------o sepimm bool [true|false]
|------o CContainerUI::SetAttribute(pstrName, pstrValue)

HorizontalLayout CHorizontalLayoutUI : public CContainerUI
|------o sepwidth int
|------o sepimm bool [true|false]
|------o CContainerUI::SetAttribute(pstrName, pstrValue)

DialogLayout CDialogLayoutUI : public CContainerUI
|------o CContainerUI::SetAttribute(pstrName, pstrValue)

TileLayout CTitleLayoutUI : public CContainerUI
|------o columns int
|------o CContainerUI::SetAttribute(pstrName, pstrValue)

TabLayout CTabLayoutUI : public CContainerUI
|------o selectedid int
|------o CContainerUI::SetAttribute(pstrName, pstrValue)





Edit CEditUI : public CLabelUI
|------o readonly bool [true|false]
|------o password bool [true|false]
|------o maxchar int
|------o normalimage Image 属性
|------o hotimage Image 属性
|------o focusedimage Image 属性
|------o disabledimage Image 属性
|------o nativebkcolor string #RRGGBBAA
|------o CLabelUI::SetAttribute(pstrName, pstrValue)

List CListUI : public CVerticalLayoutUI, public IListUI
|------o header string bool [hidden|Show]
|------o headerbkimage string path
|------o scrollselect bool [true|false]
|------o multiexpanding bool [true|false]
|------o itemfont int Font列表的索引号
|------o itemalign string enum [left|center|right]
|------o itemendellipsis bool [true|false]
|------o itemtextpadding RECT(long left, long top, long right,long bottom)
|------o itemtextcolor string #RRGGBBAA
|------o itembkcolor string #RRGGBBAA
|------o itemimage string path
|------o itemselectedtextcolor string #RRGGBBAA
|------o itemselectedbkcolor string #RRGGBBAA
|------o itemselectedimage string path
|------o itemhottextcolor string #RRGGBBAA
|------o itemhotbkcolor string #RRGGBBAA
|------o itemhotimage Image 属性
| |------o file string path
| |------o corner RECT(long left, long top, long right,long bottom)
|------o itemdisabledtextcolor string #RRGGBBAA
|------o itemdisabledbkcolor string #RRGGBBAA
|------o itemdisabledimage Image 属性
|------o itemlinecolor string #RRGGBBAA
|------o itemshowhtml bool [true|false]
|------o CVerticalLayoutUI::SetAttribute(pstrName, pstrValue)

ListHeaderItem CListHeaderItemUI : public CControlUI
|------o dragable bool [true|false]
|------o sepwidth int
|------o align string enum [left|center|right]
|------o itemshowhtml bool [true|false]
|------o endellipsis bool [true|false]
|------o font int Font列表的索引号
|------o textcolor string #RRGGBBAA
|------o textpadding RECT(long left, long top, long right,long bottom)
|------o showhtml bool [true|false]
|------o normalimage Image 属性
|------o hotimage Image 属性
|------o pushedimage Image 属性
|------o focusedimage Image 属性
|------o sepimage Image 属性

CListElementUI : public CControlUI, public IListItemUI
|------o selected value 有此属性就选中
|------o CControlUI::SetAttribute(pstrName, pstrValue)

ListExpandElement CListExpandElementUI : public CListTextElementUI
|------o expander RECT(long left, long top, long right,long bottom)
|------o hideself bool [true|false]
|------o selected bool
|------o CListTextElementUI::SetAttribute(pstrName, pstrValue)

ListContainerElement CListContainerElementUI List容器
|------o selected value 有此属性就选中

ListHeader CListHeaderUI

CListLabelElementUI : public CListElementUI


ListTextElement CListTextElementUI : public CListLabelElementUI


Label CLabelUI : public CControlUI
|------o align string enum [left|center|right]
|------o endellipsis bool [true|false]
|------o font int Font列表的索引号
|------o textcolor string #RRGGBBAA
|------o disabledtextcolor string #RRGGBBAA
|------o textpadding RECT(long left, long top, long right,long bottom)
|------o showhtml bool [true|false]
|------o CControlUI::SetAttribute( pstrName, pstrValue )


Text CTextUI : public CLabelUI

Combo CComboUI : public CContainerUI, public IListOwnerUI
|------o textpadding RECT(long left, long top, long right,long bottom)
|------o normalimage Image 属性
|------o hotimage Image 属性
|------o pushedimage Image 属性
|------o focusedimage Image 属性
|------o disabledimage Image 属性
|------o dropbox string
|------o itemfont int Font列表的索引号
|------o itemalign string enum [left|center|right]
|------o itemtextpadding RECT(long left, long top, long right,long bottom)
|------o itemtextcolor string #RRGGBBAA
|------o itembkcolor string #RRGGBBAA
|------o itemimage Image 属性
|------o itemselectedtextcolor string #RRGGBBAA
|------o itemselectedimage Image 属性
|------o itemhottextcolor string #RRGGBBAA
|------o itemhotbkcolor string #RRGGBBAA
|------o itemhotimage Image 属性
|------o itemdisabledtextcolor string #RRGGBBAA
|------o itemdisabledbkcolor string #RRGGBBAA
|------o itemdisabledimage Image 属性
|------o itemlinecolor string #RRGGBBAA
|------o itemshowhtml bool [true|false]
|------o CContainerUI::SetAttribute(pstrName, pstrValue)

Button CButtonUI : public CLabelUI
|------o normalimage Image 属性
|------o hotimage Image 属性
|------o pushedimage Image 属性
|------o focusedimage Image 属性
|------o disabledimage Image 属性
|------o hottextcolor string #RRGGBBAA
|------o pushedtextcolor string #RRGGBBAA
|------o focusedtextcolor string #RRGGBBAA
|------o CLabelUI::SetAttribute(pstrName, pstrValue)

Option COptionUI : public CButtonUI
|------o group string
|------o selected bool [true|false]
|------o selectedimage Image 属性
|------o foreimage Image 属性
|------o selectedtextcolor string #RRGGBBAA
|------o CButtonUI::SetAttribute(pstrName, pstrValue)

Progress CProgressUI : public CLabelUI
|------o fgimage Image 属性
|------o hor bool
|------o min int
|------o max int
|------o value int
|------o CLabelUI::SetAttribute(pstrName, pstrValue)

Slider CSliderUI : public CProgressUI
|------o thumbimage Image 属性
|------o thumbhotimage Image 属性
|------o thumbpushedimage Image 属性
|------o thumbsize SIZE(int x, int y)
|------o step int
|------o CProgressUI::SetAttribute(pstrName, pstrValue)

RichEdit CRichEditUI : public CContainerUI, public IMessageFilterUI
|------o vscrollbar bool [true|false]
|------o autovscroll bool [true|false]
|------o hscrollbar bool [true|false]
|------o autohscroll bool [true|false]
|------o wanttab bool [true|false]
|------o wantreturn bool [true|false]
|------o wantctrlreturn bool [true|false]
|------o rich bool [true|false]
|------o multiline bool [false|true]
|------o readonly bool [true|false]
|------o numberonly bool [true|false]
|------o password bool [true|false]
|------o align string enum [left|center|right]
|------o font int Font列表的索引号
|------o textcolor string #RRGGBBAA
|------o CContainerUI::SetAttribute(pstrName, pstrValue)


ActiveX CActiveXUI : public CControlUI
|------o clsid string
|------o modulename string
|------o delaycreate bool [true|false]
|------o CControlUI::SetAttribute(pstrName, pstrValue)

ScrollBar CScrollBarUI : public CControlUI
|------o button1normalimage Image 属性
|------o button1hotimage Image 属性
|------o button1pushedimage Image 属性
|------o button1disabledimage Image 属性
|------o button2normalimage Image 属性
|------o button2hotimage Image 属性
|------o button2pushedimage Image 属性
|------o button2disabledimage Image 属性
|------o thumbnormalimage Image 属性
|------o thumbhotimage Image 属性
|------o thumbpushedimage Image 属性
|------o thumbdisabledimage Image 属性
|------o railnormalimage Image 属性
|------o railhotimage Image 属性
|------o railpushedimage Image 属性
|------o raildisabledimage Image 属性
|------o bknormalimage Image 属性
|------o bkhotimage Image 属性
|------o bkpushedimage Image 属性
|------o bkdisabledimage Image 属性
|------o hor bool [true|false]
|------o linesize int
|------o range int
|------o value int
|------o showbutton1 bool [true|false]
|------o showbutton2 bool [true|false]
|------o CControlUI::SetAttribute(pstrName, pstrValue)


控件的通用属性
stretch STRETCHMODE
o--------move_x
o--------move_y
o--------move_xy
o--------size_x
o--------size_y
o--------size_xy
o--------group
o--------line


考虑到在xml编辑器中使用<>符号不方便,可以使用{}符号代替
支持标签嵌套(如<l><b>text</b></l>),但是交叉嵌套是应该避免的(如<l><b>text</l></b>)
The string formatter supports a kind of "mini-html" that consists of various short tags:

Bold: <b>text</b>
Color: <c #xxxxxx>text</c> where x = RGB in hex
Font: <f x>text</f> where x = font id
Italic: <i>text</i>
Image: <i x y z> where x = image name and y = imagelist num and z(optional) = imagelist id
Link: <a x>text</a> where x(optional) = link content, normal like app:notepad or http:www.xxx.com
NewLine <n>
Paragraph: <p x>text</p> where x = extra pixels indent in p
Raw Text: <r>text</r>
Selected: <s>text</s>
Underline: <u>text</u>
X Indent: <x i> where i = hor indent in pixels

Y Indent: <y i> where i = ver indent in pixels


转自:http://www.cnblogs.com/wuqi924/articles/2127061.html

DuiLib——第一篇UIManager

DUiLib 源码分析 ——以UiLib 1.01版为分析目标
----------------------------------------------------------------------------------
分析约定:
private o------- 私有的成员变量或方法
protect x------- 受保护的成员变量或方法
public +------- 公开的成员变量或方法
----------------------------------------------------------------------------------

本篇分析一下源文件
UIManager.h/UIManager.cpp

CPaintManagerUI
成员变量

窗体句柄
o---m_hWndPaint 要CPaintManagerUI进行Direct绘图操作的窗体句柄
o---m_hwndTooltip 提示窗口句柄
o---m_hInstance 当前管理的Instance实例
o---m_hResourceInstance 当前管理的资源DLL Instance实例
o---m_pStrResourcePath 当前使用的资源路径
o---m_pStrResourceZip 当前使用的资源压缩包文件全称




------------------------------------------------------CPaintManagerUI使用的资源
绘图设备
o---m_hDcPaint 直接绘制到窗体的DC(为窗体的整个区域包括费客户区)
o---m_hDcOffscreen 内存缓冲区绘图DC
o---m_hDcBackground 背景绘制(支持AlphaBackground时使用)
位图
o---m_hbmpOffscreen m_hDcPaint的后台作图画布
o---m_hbmpBackground 背景图片bmp

------------------------------------------------------CPaintManagerUI用到的信息
o---m_ToolTip 提示消息
typedef struct tagTOOLINFOA {
UINT cbSize; //该结构体的大小 sizeof(TOOLINFO)
UINT uFlags; //附加标识类信息
HWND hwnd; //消息接受的窗体
UINT_PTR uId; //控件ID
RECT rect; //消息产生的区域位置
HINSTANCE hinst; //消息接收的实例
LPSTR lpszText; //提示消息
LPARAM lParam; //IE3.0以上的版本有该属性
void *lpReserved; //NT5.0以上的版本有该属性 附加信息
} TOOLINFO
标识类信息
o---m_bShowUpdateRect 是否显示更新区域
o---m_bFirstLayout 是否是首个布局
o---m_bUpdateNeeded 是否需要更新界面
o---m_bFocusNeeded 是否需要焦点
o---m_bOffscreenPaint 是否需要开双缓存绘图
o---m_bAlphaBackground 窗体背景是否需要支持Alpha通道(如png图片的半透明效果)
o---m_bMouseTracking 是否需要支持鼠标追踪
o---m_bMouseCapture 是否需要支持鼠标捕获

控件信息
o---m_pRoot xml根节点解析成的对象,通常为各种Window
o---m_pFocus 处于获得焦点状态的控件
o---m_pEventHover 处于鼠标悬停状态的控件
o---m_pEventClick 被鼠标点击的控件
o---m_pEventKey 接收键盘输入的控件

位置记录信息
o---m_pLastMousePos 鼠标最新的位置
o---m_szMinWindow 设置窗体可以调整到的最小大小
o---m_szMaxWindow 窗体可以调整到的最大大小
o---m_szInitWindowSize 窗体初始化是的大小
o---m_rcSizeBox 窗体外边框区域的大小
o---m_szRoundCorner 窗体四角的圆角弧度
o---m_rcCaption 窗体标题栏区域大小
o---m_uTimerID 当前定时器ID

集合类信息
o---m_aNotifiers 能够接收通知的对象集合
o---m_aTimers 定时器集合
o---m_aPreMessage 预处理消息集合
o---m_aPreMessageFilters 预处理消息过滤器集合
o---m_aMessageFilters 消息过滤器集合
o---m_aPostPaintControls 发送绘制请求的控件集合
o---m_aDelayedCleanup 延迟清理的对象集合
o---m_aAsyncNotify 异步通知消息集合
o---m_mNameHash 名称HashMap
o---m_mOptionGroup 选项组Map

xml对应资源
o---m_pParentResourcePM 上级(父类)资源的PaintManagerUI绘图管理器
o---m_dwDefaultDisabledColor 默认失效状态颜色
o---m_dwDefaultFontColor 默认字体颜色
o---m_dwDefaultLinkFontColor 默认超链接字体颜色
o---m_dwDefaultLinkHoverFontColor默认超链接鼠标悬停状态的字体颜色
o---m_dwDefaultSelectedBkColor 默认选中状态背景色
o---m_DefaultFontInfo 默认字体信息
TFontInfo{
hFont 该字体的句柄
sFontName 字体名称
iSize 字号
bBold 是否粗体
bUnderline 是否有下划线
bItalic 是否为斜体
TEXTMETRIC tm 该字体的TEXTMETRIC信息
}
o---m_aCustonFonts 自定义字体资源集合
o---m_mImageHash 图片资源HashMap
o---m_DefaultAttrHash DefaultAttr资源HashMap

私有方法
将所有的控件添加到m_mNameHash哈希表中
o---static CControlUI* CALLBACK __FindControlFromNameHash(CControlUI* pThis, LPVOID pData);
计算控件数量
o---static CControlUI* CALLBACK __FindControlFromCount(CControlUI* pThis, LPVOID pData);
根据点是否在区域中,查询控件
o---static CControlUI* CALLBACK __FindControlFromPoint(CControlUI* pThis, LPVOID pData);
通过Tab信息查询控件
o---static CControlUI* CALLBACK __FindControlFromTab(CControlUI* pThis, LPVOID pData);
从快照中查询控件
o---static CControlUI* CALLBACK __FindControlFromShortcut(CControlUI* pThis, LPVOID pData);
查找需要更新的控件
o---static CControlUI* CALLBACK __FindControlFromUpdate(CControlUI* pThis, LPVOID pData);
通过名称比较查询控件
o---static CControlUI* CALLBACK __FindControlFromName(CControlUI* pThis, LPVOID pData);

公开方法
绘图管理器的初始化(m_hWndPaint,m_hDcPaint赋值,在预处理消息中加入管理器)
+---void Init(HWND hWnd);
当前需要更新界面
+---void NeedUpdate();
指定区域失效
+---void Invalidate(RECT& rcItem);
获取绘图设备DC
+---HDC GetPaintDC() const;
获取绘图的窗口句柄
+---HWND GetPaintWindow() const;
获取提示窗体句柄
+---HWND GetTooltipWindow() const;
获取当前鼠标的位置
+---POINT GetMousePos() const;
获取客户区大小
+---SIZE GetClientSize() const;
获取窗体初始化时的大小
+---SIZE GetInitSize();
设置窗体初始化大小
+---void SetInitSize(int cx, int cy);
获取窗体的边框区域大小
+---RECT& GetSizeBox();
设置窗体的边框区域大小
+---void SetSizeBox(RECT& rcSizeBox);
获取标题区域位置
+---RECT& GetCaptionRect();
设置标题区域位置
+---void SetCaptionRect(RECT& rcCaption);
获取窗体四角的圆角弧度
+---SIZE GetRoundCorner() const;
设置窗体四角的圆角弧度
+---void SetRoundCorner(int cx, int cy);
获取窗体可以调整到的最小大小
+---SIZE GetMinInfo() const;
设置窗体可以调整到的最小大小
+---void SetMinInfo(int cx, int cy);
获取窗体可以调整到的最大大小
+---SIZE GetMaxInfo() const;
设置窗体可以调整到的最大大小
+---void SetMaxInfo(int cx, int cy);
窗体的不透明度(0完全透明-255完全不透明)
+---void SetTransparent(int nOpacity);
设置绘图是否支持透明处理
+---void SetBackgroundTransparent(bool bTrans);
是否显示更新区域
+---bool IsShowUpdateRect() const;
设置是否显示更新
+---void SetShowUpdateRect(bool show);
获取当前管理的实例句柄
+---static HINSTANCE GetInstance();
获得当前运行的实例的路径
+---static CStdString GetInstancePath();
获得当前的工作路径
+---static CStdString GetCurrentPath();
获取资源DLL的实例句柄
+---static HINSTANCE GetResourceDll();
获取资源的路径(以"\"结尾)
+---static const CStdString& GetResourcePath();
获得Zip资源的路径
+---static const CStdString& GetResourceZip();
设置实例句柄
+---static void SetInstance(HINSTANCE hInst);
设置当前的工作路径
+---static void SetCurrentPath(LPCTSTR pStrPath);
设置当前的DLL资源的实例句柄
+---static void SetResourceDll(HINSTANCE hInst);
设置资源所在文件夹路径
+---static void SetResourcePath(LPCTSTR pStrPath);
设置Zip资源的路径(包括Zip文件名)
+---static void SetResourceZip(LPCTSTR pStrZip);
设置使用上级资源的绘图管理器
+---bool UseParentResource(CPaintManagerUI* pm);
获得上级资源绘图管理器
+---CPaintManagerUI* GetParentResource() const;
获取禁用状态的默认颜色
+---DWORD GetDefaultDisabledColor() const;
设置禁用状态的默认颜色
+---void SetDefaultDisabledColor(DWORD dwColor);
获取字体默认颜色
+---DWORD GetDefaultFontColor() const;
设置字体默认颜色
+---void SetDefaultFontColor(DWORD dwColor);
设置链接文字的默认字体颜色
+---DWORD GetDefaultLinkFontColor() const;
获取链接文字的默认颜色
+---void SetDefaultLinkFontColor(DWORD dwColor);
获取鼠标悬停与超链上的默认字体颜色
+---DWORD GetDefaultLinkHoverFontColor() const;
获取鼠标悬停与超链上的默认字体颜色
+---void SetDefaultLinkHoverFontColor(DWORD dwColor);
获取选中状体的默认背景颜色
+---DWORD GetDefaultSelectedBkColor() const;
设置选中状态的默认背景颜色
+---void SetDefaultSelectedBkColor(DWORD dwColor);
获取默认使用的字体信息
+---TFontInfo* GetDefaultFontInfo();
设置默认使用的字体信息
+---void SetDefaultFont(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic);
获取用户自定义字体的数量(一般对应xml中Font的数量)
+---DWORD GetCustomFontCount() const;
向字体数组列表追加字体资源
+---HFONT AddFont(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic);
向字体数组列表中插入字体资源
+---HFONT AddFontAt(int index, LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic);
获取数组中指定下标的字体对象句柄
+---HFONT GetFont(int index);
从字体数组中获取指定配置的字体对象句柄
+---HFONT GetFont(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic);
字体数组集合中是否存在字体对象
+---bool FindFont(HFONT hFont);
字体数组集合中是否存在指定配置的字体对象
+---bool FindFont(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic);
获得字体对象的
+---int GetFontIndex(HFONT hFont);
根据指定的配置信息查询字体索引
+---int GetFontIndex(LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic);
从字体数组列表中移除字体对象
+---bool RemoveFont(HFONT hFont);
从字体数组列表中移除指定位置的字体信息
+---bool RemoveFontAt(int index);
清空字体数组列表
+---void RemoveAllFonts();
通过字体数组索引查找字体信息
+---TFontInfo* GetFontInfo(int index);
通过字体对象句柄获取字体信息
+---TFontInfo* GetFontInfo(HFONT hFont);
根据图像路径查找图像信息
+---const TImageInfo* GetImage(LPCTSTR bitmap);
根据名称,类型,遮罩色 查询 图像信息
+---const TImageInfo* GetImageEx(LPCTSTR bitmap, LPCTSTR type = NULL, DWORD mask = 0);
添加图像
+---const TImageInfo* AddImage(LPCTSTR bitmap, LPCTSTR type = NULL, DWORD mask = 0);
添加图像
+---const TImageInfo* AddImage(LPCTSTR bitmap, HBITMAP hBitmap, int iWidth, int iHeight, bool bAlpha);
根据图像名称移除图像
+---bool RemoveImage(LPCTSTR bitmap);
移除全部图像
+---void RemoveAllImages();
添加控件的默认配置信息(如button)
+---void AddDefaultAttributeList(LPCTSTR pStrControlName, LPCTSTR pStrControlAttrList);
根据控件名称查询该类控件的默认配置
+---LPCTSTR GetDefaultAttributeList(LPCTSTR pStrControlName) const;
移除指定控件类型名称的默认配置
+---bool RemoveDefaultAttributeList(LPCTSTR pStrControlName);
获取默认配置信息列表
+---const CStdStringPtrMap& GetDefaultAttribultes() const;
清空默认配置信息列表
+---void RemoveAllDefaultAttributeList();
将对话框控件附加到当前的管理器中
+---bool AttachDialog(CControlUI* pControl);
控件初始化
+---bool InitControls(CControlUI* pControl, CControlUI* pParent = NULL);
控件回收
+---void ReapObjects(CControlUI* pControl);

添加控件到指定的选项组
+---bool AddOptionGroup(LPCTSTR pStrGroupName, CControlUI* pControl);
查询指定选项组名称中的全部选项
+---CStdPtrArray* GetOptionGroup(LPCTSTR pStrGroupName);
从指定控件中移除指定选项组名称的选项组
+---void RemoveOptionGroup(LPCTSTR pStrGroupName, CControlUI* pControl);
清空全部选项组列表
+---void RemoveAllOptionGroups();

获取焦点状态的控件
+---CControlUI* GetFocus() const;
设置控件为获得焦点状态
+---void SetFocus(CControlUI* pControl);
设置控件为需要绘制焦点
+---void SetFocusNeeded(CControlUI* pControl);

设置下一个获得Tab键会获得焦点的控件,Tab是否继续往下走
+---bool SetNextTabControl(bool bForward = true);

为指定控件以及其子控件设置定时器
+---bool SetTimer(CControlUI* pControl, UINT nTimerID, UINT uElapse);
移除指定控件上的指定编号的定时器
+---bool KillTimer(CControlUI* pControl, UINT nTimerID);
清空所有的定时器
+---void RemoveAllTimers();

设置窗体接受鼠标事件
+---void SetCapture();
释放窗体捕获鼠标事件
+---void ReleaseCapture();
判断窗体是否接受鼠标事件
+---bool IsCaptured();

添加控件到通知集合中
+---bool AddNotifier(INotifyUI* pControl);
将控件从通知集合中移除
+---bool RemoveNotifier(INotifyUI* pControl);
发送同步/异步通知
+---void SendNotify(TNotifyUI& Msg, bool bAsync = false);
构建同步或异步通知并发送
+---void SendNotify(CControlUI* pControl, LPCTSTR pstrMessage, WPARAM wParam = 0, LPARAM lParam = 0, bool bAsync = false);


向预处理消息过滤器链中添加消息过滤器
+---bool AddPreMessageFilter(IMessageFilterUI* pFilter);
从预处理消息过滤器链合中移除指定的消息过滤器
+---bool RemovePreMessageFilter(IMessageFilterUI* pFilter);

向消息过滤器链中添加消息过滤器
+---bool AddMessageFilter(IMessageFilterUI* pFilter);
从消息过滤器链中移除消息过滤器
+---bool RemoveMessageFilter(IMessageFilterUI* pFilter);
获取发送需要绘制的控件的数量
+---int GetPostPaintCount() const;
向绘制请求集合中添加要绘制的控件
+---bool AddPostPaint(CControlUI* pControl);
从绘制请求集合中移除指定的控件
+---bool RemovePostPaint(CControlUI* pControl);
将绘制请求控件插入到绘制请求集合的指定位置
+---bool SetPostPaintIndex(CControlUI* pControl, int iIndex);
向延迟清理集合中添加需要延迟清理的对象
+---void AddDelayedCleanup(CControlUI* pControl);
获取根节点控件
+---CControlUI* GetRoot() const;
从根节点开始查找指定点所在的控件
+---CControlUI* FindControl(POINT pt) const;
从指定节点开始查找指定点所在的控件
+---CControlUI* FindControl(CControlUI* pParent, POINT pt) const;
从根节点开始,查找指定名称的控件
+---CControlUI* FindControl(LPCTSTR pstrName);
从指定节点开始查找指定名称的控件
+---CControlUI* FindControl(CControlUI* pParent, LPCTSTR pstrName);

消息循环,非游戏框架消息泵,无法利用无消息的空闲时间
+---static void MessageLoop();
消息翻译,在Win32原有的消息转换基础上,将需要自己处理的消息转发给消息预处理器
+---static bool TranslateMessage(const LPMSG pMsg);
消息预处理器
1.消息预处理过滤(消息预处理过滤器集合对消息进行过滤处理)
2.检查是否按下Tab键,设置下一个获得焦点的控件
3.处理Alt+Shortcut Key按下后的控件获得焦点和激活的设置
4.检查是否有系统键消息,有则发送获得焦点的控件的事件
+---bool PreMessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lRes);


----------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------
消息处理器(核心处理器)
1.消息过滤
2.检查Custom消息并处理
3.检查是否有WM_CLOSE消息并处理
4.处理WM_ERASEBKGND(不允许进行背景擦除,防止闪烁)
5.绘制处理(核心)
5.1做延迟绘图判断,当前是否有 窗体大小调整的操作,或者是否需要初始化窗体
5.2设置焦点控件
5.3如果开启双缓存绘图,采用双缓存方式绘图,否则采用标准绘图方式绘图
5.4
6.处理客户区的绘制WM_PRINTCLIENT
7.接到WM_GETMINMAXINFO消息后向系统提交该窗体可调整大小的最小和最大限制
8.窗体大小改变时,向焦点控件发送改变大小消息并设置窗体需要更新
9.处理定时器消息,向定时器集合中广播定时消息
10.处理鼠标悬停
10.1向鼠标悬停的控件发送鼠标悬停消息
10.2如果当前控件有提示消息,创建消息提示窗体
11.处理鼠标离开事件,关闭消息提示框,发送鼠标离开消息,取消鼠标的追踪
12.鼠标移动时,开始追踪鼠标
12.1处理鼠标移动时,鼠标在控件上进入,移动,悬停和离开的消息
13.处理鼠标左键按下的消息设定活动的焦点的控件
14.鼠标双击事件处理,向需要接收鼠标双击事件的控件发送双击事件
15.鼠标左键抬起时,向上次接收到点击消息的控件发送鼠标左键抬起的消息
16.鼠标右键按下时,向需要接收鼠标右键按下的控件发送右键按下消息
17.鼠标右键快捷菜单消息,将该消息通知给上次点击过的按钮
18.滚轮消息时,象鼠标所在的控件发送滚轮消息
19.WM_CHAR 消息时,向获得焦点的控件发送该消息
20.键盘按下时,向焦点控件发送该键盘消息,并设定焦点控件为键盘消息控件
21.键盘按键抬起时,向事键盘消息控件发送该事件
22.设定鼠标光标消息时,获得光标所在控件接收该消息
23.通知消息到来时,加OCM_BASE后发送通知消息
24.命令消息到来,加OCM_BASE后发送消息
25.WM_CTLCOLOREDIT,STATIC消息到来后,加OCM_BASE后发送消息

+---bool MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& lRes);


转自:http://www.cnblogs.com/wuqi924/articles/2127062.html

----------------------------------------------------------------------------------
分析约定:
private o------- 私有的成员变量或方法
protect x------- 受保护的成员变量或方法
public +------- 公开的成员变量或方法
----------------------------------------------------------------------------------

本篇分析一下源文件
UIBase.h/UIBase.cpp
UILib的基础类的定义源文件
包括UI中常用宏的封装、代码调试宏、
绘图常用的各种数据结构,以及UILib中的窗体类等

UI里的宏
窗体样式宏
+---UI_WNDSTYLE_CONTAINER 容器样式,无任何样式
+---UI_WNDSTYLE_FRAME UI标准框架窗体样式(标题栏、边框、图标、标题、最大、最小按钮、关闭按钮)
+---UI_WNDSTYLE_CHILD UI窗体子控件样式
+---UI_WNDSTYLE_DIALOG UI对话框窗体样式
扩展窗体样式宏
+---UI_WNDSTYLE_EX_FRAME 窗体客户区凹陷样式
+---UI_WNDSTYLE_EX_DIALOG 工具栏窗口样式+模式对话框样式
类样式宏
+---UI_CLASSSTYLE_CONTAINER 类容器样式
+---UI_CLASSSTYLE_FRAME 水平、垂直大小改变时绘制
+---UI_CLASSSTYLE_CHILD 水平、垂直大小改变时绘制、支持双击事件、保存窗体位图
+---UI_CLASSSTYLE_DIALOG 水平、垂直大小改变时绘制、支持双击事件、保存窗体位图

ASSERT(expr) 判断表达式是否为NULL或FALSE
TRACE(LPSTSTR pstrFormat,...)
在Debug输出窗口打印格式化字符串
TRACEMSG(UINT uMsg) 返回指定消息的16进制表示

基础类
STRINGorID 用于构建资源名称或资源ID号
x---LPCTSTR m_lpstr;
+---STRINGorID(LPCTSTR lpString)
+---STRINGorID(UINT nID)

CPoint 点的封装类,支持LPARAM构建点
+---CPoint();
+---CPoint(const POINT& src);
+---CPoint(int x, int y);
+---CPoint(LPARAM lParam);

CSize 大小封装
+---CSize();
+---CSize(const SIZE& src);
+---CSize(const RECT rc);
+---CSize(int cx, int cy);

CRect 区域封装
+---CRect();
+---CRect(const RECT& src);
+---CRect(int iLeft, int iTop, int iRight, int iBottom);
+---int GetWidth() const 获取宽度
+---int GetHeight() const 获取高度
+---void Empty() 清空
+---bool IsNull() const 是否为Empty,IsEmpty
+---Join(const RECT& rc) 支持区域合并
+---Normalize() 正规化(使得left<right,top<bottom)
+---Offset(int cx, int cy) 区域偏移(移动)操作
+---Inflate(int cx, int cy) 区域膨胀
+---Deflate(int cx, int cy) 区域收缩
+---Union(CRect& rc) 区域并操作

CStdPtrArray 指针数组类
x---LPVOID* m_ppVoid 数据指针
x---int m_nCount 指针数量
x---int m_nAllocated 内存已分配大小
-----------------------------------------------------------------------
+---void Empty() 清空记录
+---void Resize(int iSize) 重新分配内存大小(注意:之前的记录丢失)
+---bool IsEmpty() const 是否为空数组
+---int Find(LPVOID iIndex) const 查询指定元素的索引号
+---bool Add(LPVOID pData) 在指针集合中添加新数据
+---bool SetAt(int iIndex, LPVOID pData)设置指定索引号处的新数据
+---bool InsertAt(int iIndex, LPVOID pData)在指定的索引号处插入数据
+---bool Remove(int iIndex) 移除指定索引号得数据
+---int GetSize() const 获取指针数量
+---LPVOID* GetData() 获取全部的数据
+---LPVOID GetAt(int iIndex) const 查询索引号所对应的元素
+---LPVOID operator[] (int nIndex) const支持[]查找元素

CStdValArray 自定义数据长度数组类
x---LPBYTE m_pVoid 指针数据
x---int m_iElementSize 元素大小
x---int m_nCount 元素数量
x---int m_nAllocated 当前分配的可用容量
-----------------------------------------------------------------------
+---CStdValArray(int iElementSize, int iPreallocSize = 0)
指定元素大小,预分配数量
+---void Empty() 清空数据
+---bool IsEmpty() const 是否为空数组
+---bool Add(LPCVOID pData) 追加数据
+---bool Remove(int iIndex) 移除指定索引号得数据
+---int GetSize() const 获取当前保存元素的个数
+---LPVOID GetData() 获取数据
+---LPVOID GetAt(int iIndex) const 获取指定索引号处的数据
+---LPVOID operator[] (int nIndex) const支持[]查找元素

CStdString 字符串类
x---LPTSTR m_pstr; 字符指针
x---TCHAR m_szBuffer[MAX_LOCAL_STRING_LEN + 1];字符缓冲区
-----------------------------------------------------------------------
+---CStdString(); 初始化字符串类
+---CStdString(const TCHAR ch);
+---CStdString(const CStdString& src);
+---CStdString(LPCTSTR lpsz, int nLen = -1);长度为-1由程序自己判断长度
+---void Empty(); 清空字符串
+---int GetLength() const; 获取字符串长度
+---bool IsEmpty() const; 字符串是否为空串
+---TCHAR GetAt(int nIndex) const; 获取指定位置处的字符
+---void Append(LPCTSTR pstr); 字符串追加操作
+---void Assign(LPCTSTR pstr, int nLength = -1);分配内存赋值
+---LPCTSTR GetData(); 获取字符串指针
+---void SetAt(int nIndex, TCHAR ch); 在指定索引处设置字符
+---int Compare(LPCTSTR pstr) const; 字符串比较
+---int CompareNoCase(LPCTSTR pstr) const;字符串忽略大小写比较
+---void MakeUpper(); 字符串转换为大小
+---void MakeLower(); 字符串转换为小写
+---CStdString Left(int nLength) const; 从左边截取指定长度的子串
+---CStdString Mid(int iPos, int nLength = -1) const;
截取中间字符串
+---CStdString Right(int nLength) const;从右开始截取指定长度的字符串

+---int Find(TCHAR ch, int iPos = 0) const;
从指定位置开始寻找匹配字符的位置
+---int Find(LPCTSTR pstr, int iPos = 0) const;
重指定位置开始寻找匹配字符串的位置
+---int ReverseFind(TCHAR ch) const; 反向查询字符位置
+---int Replace(LPCTSTR pstrFrom, LPCTSTR pstrTo);
将匹配的字符子串用指定字符串替换

+---int __cdecl Format(LPCTSTR pstrFormat, ...);
最长63位的字符串格式化
+---int __cdecl SmallFormat(LPCTSTR pstrFormat, ...);
一次格式化1024长度的字符串格式化


TITEM结构
o---CStdString Key 键
o---LPVOID Data 值
o---struct TITEM* pNext 下一个TITEM结构体指针

CStdStringPtrMap
x---TITEM** m_aT; TITEM双指针
x---int m_nBuckets; 容器容量
+---CStdStringPtrMap(int nSize = 83); 构建字符串Map集合
+---void Resize(int nSize = 83); 重新分配集合大小
+---LPVOID Find(LPCTSTR key) const; 更具键查询字符串指针
+---bool Insert(LPCTSTR key, LPVOID pData);插入数据
+---LPVOID Set(LPCTSTR key, LPVOID pData);设置指定键的数据
+---bool Remove(LPCTSTR key); 通过键移除数据
+---int GetSize() const; 获取大小
+---LPCTSTR GetAt(int iIndex) const; 获取指定索引处得字符串
+---LPCTSTR operator[] (int nIndex) const;通过下标获取字符串


CWindowWnd
x---HWND m_hWnd 窗体句柄,初始化为NULL
x---WNDPROC m_OldWndProc Win32窗口过程,默认为DefWindowProc
x---bool m_bSubclassed 是否子类化,默认为false
--------------------------------------------------------------------
获取窗口类名称,子类必须实现该纯虚函数
o---virtual LPCTSTR GetWindowClassName() const = 0;
获取父类名称,用以子类化
o---virtual LPCTSTR GetSuperClassName() const;
获得类样式
o---virtual UINT GetClassStyle() const;
消息处理函数
o---virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
窗体销毁前最后的处理工作
o---virtual void OnFinalMessage(HWND hWnd);
窗口过程回调函数
o---static LRESULT CALLBACK __WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
控件过程回调函数
o---static LRESULT CALLBACK __ControlProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
---------------------------------------------------------------------

+---CWindowWnd();
获取窗口句柄
+---HWND GetHWND() const;
获取窗口句柄
+---operator HWND() const;
注册窗口过程
1.调用GetClassStyle获取样式信息
2.调用绘图管理器的静态函数获取实例CPaintManagerUI::GetInstance()
3.调用GetWindowClassName()获取要注册的类名称
+---bool RegisterWindowClass();
通过已存在的窗体作为父类注册窗口类
+---bool RegisterSuperclass();
窗口创建
+---HWND Create(HWND hwndParent, LPCTSTR pstrName, DWORD dwStyle, DWORD dwExStyle, const RECT rc, HMENU hMenu = NULL);
创建窗口
1.如果存在父类名,就用注册父类来创建
2.不存在父类名,进行正常的窗口注册
3.以上注册成功后,创建窗口
+---HWND Create(HWND hwndParent, LPCTSTR pstrName, DWORD dwStyle, DWORD dwExStyle, int x = CW_USEDEFAULT, int y = CW_USEDEFAULT, int cx = CW_USEDEFAULT, int cy = CW_USEDEFAULT, HMENU hMenu = NULL);
窗口子类化
+---HWND Subclass(HWND hWnd);
卸载窗口子类化
+---void Unsubclass();
显示窗口
+---void ShowWindow(bool bShow = true, bool bTakeFocus = true);
显示模式窗口
+---bool ShowModal();
关闭窗口
+---void Close();
窗口居中,如果为子窗口,则居于父窗口的中央
+---void CenterWindow();
通过资源ID号设置图标
+---void SetIcon(UINT nRes);
发送UI同步消息
+---LRESULT SendMessage(UINT uMsg, WPARAM wParam = 0, LPARAM lParam = 0L);
投递UI异步消息
+---LRESULT PostMessage(UINT uMsg, WPARAM wParam = 0, LPARAM lParam = 0L);
调整客户区大小
+---void ResizeClient(int cx = -1, int cy = -1);

CWaitCursor 等待光标
x---HCURSOR m_hOrigCursor 替换前光标
+---CWaitCursor() 设置成等待光标

+---~CWaitCursor() 还原为之前的光标


转自:http://www.cnblogs.com/wuqi924/articles/2127064.html

 

网上找到Duilib入门教程中,第一个给的时基于SDK的例子,在这里,自己写了个MFC的,与入门教程中的例子一样。

新建一个窗口类(CTestDlg)

TestDlg.h内容如下:

  1. #pragma once   
  2. class CTestDlg:public CWindowWnd, INotifyUI  
  3. {  
  4. public:  
  5.     CTestDlg(void);  
  6.     ~CTestDlg(void);  
  7.       
  8. public:  
  9.     LPCTSTR GetWindowClassName() const;  
  10.     UINT GetClassStyle() const;  
  11.     void OnFinalMessage(HWND hWnd);  
  12.     void Notify(TNotifyUI& msg);  
  13.     LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);  
  14. private:  
  15.     CPaintManagerUI m_pm;  
  16. };  


TestDlg.cpp内容如下:

  1. #include "StdAfx.h"   
  2. #include "TestDlg.h"   
  3.   
  4.   
  5. CTestDlg::CTestDlg(void)  
  6. {  
  7. }  
  8.   
  9. CTestDlg::~CTestDlg(void)  
  10. {  
  11. }  
  12.   
  13. LPCTSTR CTestDlg::GetWindowClassName() const  
  14. {  
  15.     return L"CTestDlg";  
  16. }  
  17.   
  18. UINT CTestDlg::GetClassStyle() const  
  19. {  
  20.     return UI_CLASSSTYLE_FRAME | CS_DBLCLKS;  
  21. }  
  22.   
  23. void CTestDlg::OnFinalMessage(HWND hWnd)  
  24. {  
  25. }  
  26.   
  27. void CTestDlg::Notify(TNotifyUI& msg)  
  28. {  
  29.     if( msg.sType == _T("click") ) {  
  30.         if( msg.pSender->GetName() == _T("closebtn") ) {  
  31.             Close();  
  32.         }  
  33.     }  
  34. }  
  35.   
  36. LRESULT CTestDlg::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)  
  37. {  
  38.     if( uMsg == WM_CREATE ) {  
  39.         m_pm.Init(m_hWnd);  
  40.         CControlUI *pButton = new CButtonUI;  
  41.         pButton->SetName(_T("closebtn"));  
  42.         pButton->SetBkColor(0xFFFF0000);  
  43.         m_pm.AttachDialog(pButton);  
  44.         m_pm.AddNotifier(this);  
  45.         return 0;  
  46.     }  
  47.     else if( uMsg == WM_DESTROY ) {  
  48.         ::PostQuitMessage(0);  
  49.     }  
  50.     LRESULT lRes = 0;  
  51.     if( m_pm.MessageHandler(uMsg, wParam, lParam, lRes) ) return lRes;  
  52.     return CWindowWnd::HandleMessage(uMsg, wParam, lParam);  
  53.   
  54. }  


然后,在主对话框的类中,增加一个成员变量

  1. CTestDlg m_testDlg;  


在OnInitDialog函数中,增加如下两行代码:

  1. m_testDlg.Create(*this, NULL, UI_WNDSTYLE_CHILD, 0, 0, 0, 642, 520);  
  2. m_testDlg.ShowWindow(TRUE);  


编译运行,即可。

在上一篇文章"MFC中使用Duilib--1"中, 没有用到资源文件,即xml,本篇讲怎样加载文件。

1.  在exe输出目录下,创建一个skin目录,里面放入需要用到的图片文件,以及创建一个或几个xml文件,在这里,我创建一个skin.xml文件。内容如下:

  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <Window mininfo="200,360" size=" 480,320 ">  
  3.     <Default name="Button" value="normalimage="file='skin\button_nor.bmp' corner='4,2,4,2' fade='200' hsl='true'" hotimage="file='skin\button_over.bmp' corner='4,2,4,2' fade='200' hsl='true'" pushedimage="file='skin\button_down.bmp' corner='4,2,4,2' fade='200' hsl='true' " " />  
  4.         <Font name="幼圆" size="16" default="true" />  
  5.         <VerticalLayout bkcolor="#FFFF00FF">  
  6.             <Button name="changeskinbtn" height="20" text="测试按钮" maxwidth="120"/>  
  7.             <RichEdit name="testrichedit" bordercolor="#FF0000" bordersize="0" borderround="18,18" inset="4,2,4,2" bkcolor="#FFF2F5FA" bkcolor2="#FFA0A000" bkcolor3="#FFF2F5FA" font="1" multiline="true" vscrollbar="true" autovscroll="true" enabled="true" rich="true" readonly="false" text="测试richedit">  
  8.             </RichEdit>  
  9.             <Edit name="testedit" text="测试编辑框" />  
  10.         </VerticalLayout>  
  11. </Window>  


需要用到的资源图片有button_nor.bmp、button_over.bmp、button_down.bmp。

 

再将上节内容中的CTestDlg的HandleMessage函数中的WM_CREATE消息改成如下内容:

  1. LRESULT CTestDlg::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)  
  2. {  
  3.     if( uMsg == WM_CREATE ) {  
  4.         //m_pm.Init(m_hWnd);   
  5.         //CControlUI *pButton = new CButtonUI;  
  6.         //pButton->SetName(_T("closebtn"));  
  7.         //pButton->SetBkColor(0xFFFF0000);  
  8.         //m_pm.AttachDialog(pButton);   
  9.         //m_pm.AddNotifier(this);  
  10.         m_pm.Init(m_hWnd);  
  11.         CDialogBuilder builder;  
  12.         CControlUI *pRoot = builder.Create(L"skin\\skin.xml", (UINT)0, NULL, &m_pm);  
  13.         ASSERT(pRoot && "Failed to parse XML");  
  14.         m_pm.AttachDialog(pRoot);  
  15.         m_pm.AddNotifier(this);  
  16.         return 0;  
  17.     }  
  18.     else if( uMsg == WM_DESTROY ) {  
  19.         ::PostQuitMessage(0);  
  20.     }  
  21.     LRESULT lRes = 0;  
  22.     if( m_pm.MessageHandler(uMsg, wParam, lParam, lRes) ) return lRes;  
  23.     return CWindowWnd::HandleMessage(uMsg, wParam, lParam);  
  24.   
  25. }  

编译运行即可。

 

 

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值