1 #pragma once 2 #include <UIlib.h> 3 using namespace DuiLib; 4 5 #ifdef _DEBUG 6 # ifdef _UNICODE 7 # pragma comment(lib, "DuiLib_ud.lib") 8 # else 9 # pragma comment(lib, "DuiLib_d.lib") 10 # endif 11 #else 12 # ifdef _UNICODE 13 # pragma comment(lib, "DuiLib_u.lib") 14 # else 15 # pragma comment(lib, "DuiLib.lib") 16 # endif 17 #endif 18 19 class CDuiFrameWnd : public CWindowWnd, public INotifyUI 20 { 21 public: 22 virtual LPCTSTR GetWindowClassName() const { return _T("DUIMainFrame"); } 23 virtual void Notify(TNotifyUI& msg) 24 { 25 if(msg.sType == _T("click")) 26 { 27 if(msg.pSender->GetName() == _T("btnHello")) 28 { 29 ::MessageBox(NULL, _T("我是按钮"), _T("点击了按钮"), NULL); 30 } 31 } 32 } 33 34 virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam) 35 { 36 LRESULT lRes = 0; 37 38 if( uMsg == WM_CREATE ) 39 { 40 CControlUI *pWnd = new CButtonUI; 41 pWnd->SetName(_T("btnHello")); // 设置控件的名称,这个名称用于标识每一个控件,必须唯一,相当于MFC里面的控件ID 42 pWnd->SetText(_T("Hello World")); // 设置文字 43 pWnd->SetBkColor(0xFF00FF00); // 设置背景色 44 45 m_PaintManager.Init(m_hWnd); 46 m_PaintManager.AttachDialog(pWnd); 47 m_PaintManager.AddNotifier(this); // 添加控件等消息响应,这样消息就会传达到duilib的消息循环,我们可以在Notify函数里做消息处理 48 return lRes; 49 } 50 51 if( m_PaintManager.MessageHandler(uMsg, wParam, lParam, lRes) ) 52 { 53 return lRes; 54 } 55 56 return __super::HandleMessage(uMsg, wParam, lParam); 57 } 58 59 protected: 60 CPaintManagerUI m_PaintManager; 61 }; 62 63 int APIENTRY _tWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) 64 { 65 CPaintManagerUI::SetInstance(hInstance); 66 67 CDuiFrameWnd duiFrame; 68 duiFrame.Create(NULL, _T("DUIWnd"), UI_WNDSTYLE_FRAME, WS_EX_WINDOWEDGE); 69 duiFrame.ShowModal(); 70 return 0; 71 }
原文:http://www.cnblogs.com/xiaoxiong0222/p/4158675.html