duilib duilib Concise Guide to Getting Started tutorial 16. The combination of win32 and MFC

Although duilib comes used in the MFC duilib Demo, but only duilib MFC window and windows do not overlap situation. If you want to embed duilib controls in MFC window or embedding MFC controls in duilib control, then there would be no Demo can be seen, in fact, do not know how to do Alberl start, looked under ActiveXUI controls, this is a combination HWND, but Since the contact duilib soon, so sometimes can not understand ActiveXUI in the end is how the win32's HWND painted, had asked the group where you, the great God to guide Troy Thank pencil groups:   
    the time after you resolve upload code, but still there are users see do not know, so last night Alberl required to write duilib with MFC and the tutorial , of course, this tutorial already in Alberl plans and the like, so we compromise and friends, on a tutorial written only half finished and so this go supplement course, if small partners have additional requirements, may also mention Oh, if within Alberl plan, Alberl will try to meet the requirements of small partners ~ O (∩_∩) O ~

    a, in MFC use duilib
    only need tutorial CDuiFrameWnd front window as the parent window MFC thousand million,
    will CDuiFrameWnd m_duiFrame; defined as the MFC member variables in MFC Creating duilib initialization function OnInitDialog inside the window, the code is as follows:

  1.     // TODO: add this extra initialization code
  2.     CPaintManagerUI :: SetInstance (AfxGetInstanceHandle ()); // the specified instance duilib
  3.     CPaintManagerUI :: SetResourcePath (CPaintManagerUI :: GetInstancePath ()); // duilib specified resource path is specified here and exe same directory
  4.     :: CoInitialize (NULL); // remember the release :: CoUninitialize ();
  5.     m_duiFrame.Create(*this, _T("DUIWnd"), UI_WNDSTYLE_CHILD, 0, 0, 0, 800, 600); 
  6.     m_duiFrame.ShowWindow(TRUE); 
  7.     return TRUE; // set the focus to the control unless otherwise returns TRUE
Copy the code





 



    Here are just embed duilib to the main window of the MFC, if you want to embed duilib to a control MFC, and it is very simple, because only a HWND handle on the line, not go into details -
    but you can find the following questions :
1, before ActiveXUI that bug no longer there.
2, all MFC controls are displayed in the window above duilib, here and ZORD order should have relations.
3, in duilib window above the OK button point did not respond, Cancel button is clicked not only duilib that part of the above will have a reaction.
    Since the study only temporarily Alberl interfaces, not to study aspects of incident response, so do not study the details. If you have small partners urgently, then, the MFC control can be embedded on duilib control, or the MFC control on non-duilib area, so that you can respond to the.

    Second, the use in the MFC control duilib
    herein MFC example buttons on the control position of the slider bar duilib:
    1, ready to receive a control duilib MFC control code is as follows:

  1. // HWND of the control will take the show to the top CControlUI
  2. class CWndUI: public CControlUI
  3. {
  4. public:
  5.     CWndUI(): m_hWnd(NULL){}
  6.     virtual void SetInternVisible(bool bVisible = true)
  7.     {
  8.         __super::SetInternVisible(bVisible);
  9.         ::ShowWindow(m_hWnd, bVisible);
  10.     }
  11.     virtual void SetPos(RECT rc)
  12.     {
  13.         __super :: SetPos (rc);
  14.         ::SetWindowPos(m_hWnd, NULL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER | SWP_NOACTIVATE);
  15.     }
  16.     BOOL Attach(HWND hWndNew)
  17.     {
  18.         if (! ::IsWindow(hWndNew))
  19.         {
  20.             return FALSE;
  21.         }
  22.         m_hWnd = hWndNew;
  23.         return TRUE;
  24.     }
  25.     HWND Detach()
  26.     {
  27.         HWND hWnd = m_hWnd;
  28.         m_hWnd = NULL;
  29.         return hWnd;
  30.     }
  31. protected:
  32.     HWND m_hWnd;
  33. };
Copy the code




    2, the node into the XML Slider Wnd, and leaving only the location information, XML is as follows:


           

  1.             
Copy the code




    3. Create Wnd control: Because Slider is duilib built-in controls, so duilib automatically creates a Slider control based on XML messages, and CWndUI is our custom controls, so you need to create your own, just need to respond to CreateControl function (if duilib find custom controls, will automatically call this function to obtain control), in CDuiFrameWnd add the following functions:


  1. virtual CControlUI* CreateControl(LPCTSTR pstrClassName)
  2.     {
  3.         if (_tcsicmp(pstrClassName, _T("Wnd")) == 0)
  4.         {
  5.             CWndUI * chicken = new CWndUI;            
  6.             HWND    hWnd  = CreateWindow(_T("BUTTON"), _T("win32"), WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, 0, 0, 0, 0, m_PaintManager.GetPaintWindow(), NULL, NULL, NULL);
  7.             pUI->Attach(hWnd);  
  8.             //// above is used win32 button below this button with MFC
  9.             // CButton * pBtn = new CButton; // release the memory recall
  10.             //pBtn->Create(_T("MFC"), WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON, CRect(0, 0, 0, 0), CWnd::FromHandle(m_PaintManager.GetPaintWindow()), 0);
  11.             //pUI->Attach(*pBtn);            
  12.             Return chicken;
  13.         }
  14.         return NULL;
  15.     }
Copy the code





    The above code with the win32 button, which comment section is MFC button, parents can try both down effect:


     
    Until now, we can either add the MFC control in duilib, you can also add duilib controls in the original MFC project, will not have to worry about the controls can not be used before it ~ O (∩_∩) O ~

Guess you like

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