配置duilib库
一个简单的使用Duilib程序一般要在stdafx.h中进行配置(链接duilib的文件,包括头文件)。通常的配置代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#pragma once #define WIN32_LEAN_AND_MEAN #define _CRT_SECURE_NO_DEPRECATE #include <windows.h> #include <objbase.h> #include "..\DuiLib\UIlib.h" using namespace DuiLib;
#ifdef _DEBUG #ifdef _UNICODE #pragma comment(lib, "..\\bin\\DuiLib_ud.lib") #else #pragma comment(lib, "..\\bin\\DuiLib_d.lib") #endif #else #ifdef _UNICODE #pragma comment(lib, "..\\bin\\DuiLib_u.lib") #else #pragma comment(lib, "..\\bin\\DuiLib.lib") #endif #endif |
工程之间不同的相对目录,代码中的lib,头文件的目录一样。根据实际情况需要做相应变化。
编写工程的主窗口
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
// 窗口实例及消息响应部分 class CFrameWindowWnd : public CWindowWnd, public INotifyUI
{ public :
CFrameWindowWnd() { };
LPCTSTR GetWindowClassName() const { return _T( "UIMainFrame" );};
UINT GetClassStyle() const { return UI_CLASSSTYLE_FRAME | CS_DBLCLKS; };
void OnFinalMessage( HWND /*hWnd*/ ) { delete this ; };
void Notify(TNotifyUI& msg)
{
if ( msg.sType == _T( "click" ) ) {
if ( msg.pSender->GetName() == _T( "closebtn" ) ) {
Close();
}
}
}
LRESULT HandleMessage( UINT uMsg, WPARAMwParam, LPARAM lParam)
{
if ( uMsg == WM_CREATE )
{
m_pm.Init(m_hWnd);
CControlUI *pButton = new CButtonUI;
pButton->SetName(_T( "closebtn" ));
pButton->SetBkColor(0xFFFF0000);
m_pm.AttachDialog(pButton);
m_pm.AddNotifier( this );
return 0;
}
else if ( uMsg == WM_DESTROY )
{
::PostQuitMessage(0);
}
LRESULT lRes = 0;
if ( m_pm.MessageHandler(uMsg, wParam, lParam, lRes) ) return lRes;
return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
}
public :
CPaintManagerUI m_pm;
}; |
在winmain处加入消息循环及Duilib初始化部分,窗口创建
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
// 程序入口及Duilib初始化部分 int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/ , LPSTR /*lpCmdLine*/ , int nCmdShow)
{ CPaintManagerUI::SetInstance(hInstance);
CPaintManagerUI::SetResourcePath(CPaintManagerUI::GetInstancePath());
CFrameWindowWnd* pFrame = new CFrameWindowWnd();
if ( pFrame == NULL ) return 0;
pFrame->Create(NULL, _T( "测试" ), UI_WNDSTYLE_FRAME, WS_EX_WINDOWEDGE);
pFrame->ShowWindow( true );
CPaintManagerUI::MessageLoop();
return 0;
}
|