標籤:style blog http ar color sp on div 2014
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 # endif11 #else12 # ifdef _UNICODE13 # pragma comment(lib, "DuiLib_u.lib")14 # else15 # pragma comment(lib, "DuiLib.lib")16 # endif17 #endif18 19 class CDuiFrameWnd : public CWindowWnd, public INotifyUI20 {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裡面的控制項ID42 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 }
Duilib學習三 響應按鈕