Hello World is a tutorial , there are a code like this: CControlUI * pWnd = new CButtonUI; that is, in fact, that entire area green background area are buttons. (Down briefly here, CControlUI is duilib the base class for all controls, buttons and CButtonUI is a class, more controls will be introduced one by one in a later tutorial.)
So how do you respond to click on the message button do?
We need some step:
1, the function call message AddNotifier added duilib message loop
2, to a unique set of control buttons ID (SetName function)
3, in the Notify message processing function button clicks inside.
code show as below:
- class CDuiFrameWnd : public CWindowWnd, public INotifyUI
- {
- public:
- virtual LPCTSTR GetWindowClassName() const { return _T("DUIMainFrame"); }
- virtual void Notify(TNotifyUI& msg)
- {
- if(msg.sType == _T("click"))
- {
- if(msg.pSender->GetName() == _T("btnHello"))
- {
- :: MessageBox (NULL, _T ( "I'm Button"), _T ( "click on the button"), NULL);
- }
- }
- }
- virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- LRESULT lRes = 0;
- if( uMsg == WM_CREATE )
- {
- CControlUI *pWnd = new CButtonUI;
- pWnd-> SetName (_T ( "btnHello")); // Set the name of the control, the name used to identify each control, must be unique, which corresponds to the MFC control ID
- pWnd-> SetText (_T ( "Hello World")); // set the text
- pWnd-> SetBkColor (0xFF00FF00); // set the background color
- m_PaintManager.Init(m_hWnd);
- m_PaintManager.AttachDialog(pWnd);
- m_PaintManager.AddNotifier (this); // add message response controls, etc., which will convey the message to the message loop duilib we can do in the Notify message processing function in
- return lRes;
- }
- if( m_PaintManager.MessageHandler(uMsg, wParam, lParam, lRes) )
- {
- return lRes;
- }
- return __super::HandleMessage(uMsg, wParam, lParam);
- }
- protected:
- CPaintManagerUI m_PaintManager;
- };
Run results shown in Figure: