duilib duilib Concise Guide to Getting Started tutorial 5. draw from the title bar

If you have done since the painting's title bar, will certainly be feeling all kinds is not easy, and some of the existing information, while the perfect realization of the function, but the code was chaotic, need to organize their own. If duilib, it is a small case. duilib fact, did not distinguish between the title bar and the client area, its implementation is to shield the system comes with a title bar, client area to simulate with a title bar, so I want to how to paint how to paint, very convenient.
    1, we first look at the shield system comes with a title bar,
         shielding the following three messages in HandleMessage function where you can WM_NCACTIVATE, WM_NCCALCSIZE, WM_NCPAINT
code is as follows:    

  1. virtual LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
  2.     {
  3.         LRESULT lRes = 0;
  4.         if( uMsg == WM_CREATE ) 
  5.         {
  6.             CControlUI *pWnd = new CButtonUI;
  7.             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
  8.             pWnd-> SetText (_T ( "Hello World")); // set the text
  9.             pWnd-> SetBkColor (0xFF00FF00); // set the background color
  10.             m_PaintManager.Init(m_hWnd);
  11.             m_PaintManager.AttachDialog(pWnd);
  12.             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
  13.             return lRes;
  14.         }
  15.         // The following three messages WM_NCACTIVATE, WM_NCCALCSIZE, WM_NCPAINT for shielding system title bar
  16.         else if( uMsg == WM_NCACTIVATE ) 
  17.         {
  18.             if( !::IsIconic(m_hWnd) ) 
  19.             {
  20.                 return (wParam == 0) ? TRUE : FALSE;
  21.             }
  22.         }
  23.         else if( uMsg == WM_NCCALCSIZE ) 
  24.         {
  25.             return 0;
  26.         }
  27.         else if( uMsg == WM_NCPAINT ) 
  28.         {
  29.             return 0;
  30.         }
  31.         if( m_PaintManager.MessageHandler(uMsg, wParam, lParam, lRes) ) 
  32.         {
  33.             return lRes;
  34.         }
  35.         return __super::HandleMessage(uMsg, wParam, lParam);
  36.     }
Copy the code



You can see the following effect
 

    2, to join Minimize Maximize buttons will operate later in the tutorial mentioned, because duilib has provided a basis for classes that implement common functions, so here it is skipped.

Guess you like

Origin www.cnblogs.com/blogpro/p/11427044.html