Use DUILIB establish project

Use DUILIB load the XML interface

The main purpose of this is to teach you how to load XML interface in their own projects, which is the most basic application, the interface control responds to what, I do not talk about, you know, after this, I will give you a other people write blog, look at his article, we should understand more clearly

First, the establishment project

Establish win32 applications, and named blog_try

Here are some points to note:

1. Select the .net framework 2.0 If you do not select this when developing, and you use the default 3.5, then when you publish APP, you will only cry, because, more than 3.5 only in the WIN 7 the operating system is running, it must pay attention. I have the blood of the lesson! ! !

2, the other fact, nothing of note, and select items under win32 win32

 

Here selection: windows application

Second, take the environment

1, part of the generated code to delete

To blog_try, the automatically generated code to puncturing in this way, i.e., in addition to comprising functions other than the header files and winmain, the other not

2, copy the relevant files to the project directory duilib

2.1, the header file duilib source project copied to our project directory of blog_try:


2.2, the lib file in the same directory project blog_try

2.3, the dll file in debug directory

Third, the function overrides file loading interface

1, adding the following code in stdafx.h to add header files and libraries containing the duilib

[cpp]  view plain copy
  1. // TODO: here refer to other procedures required header files  
  2. #include "UIlib.h"  
  3. using namespace DuiLib;  
  4. #ifdef _DEBUG  
  5. #   ifdef _UNICODE  
  6. #       pragma comment(lib, "DuiLib_ud.lib")  
  7. #   else  
  8. #       pragma comment(lib, "DuiLib_d.lib")  
  9. #   endif  
  10. #else  
  11. #   ifdef _UNICODE  
  12. #       pragma comment(lib, "DuiLib_u.lib")  
  13. #   else  
  14. #       pragma comment(lib, "DuiLib.lib")  
  15. #   endif  
  16. #endif  

2, adding blog_try.h CMainFrame class, this class inherits from CwindowWnd, INotifyUI, that is, we use this class CMainFrame to implement binding XML, add buttons, etc. in response to control.

[cpp]  view plain copy
  1. class CMainFrame :  
  2.     public DuiLib :: CWindowWnd, public INotifyUI // application window class CWindowWnd  
  3. {  
  4. public:  
  5.     CMainFrame(void);  
  6.     ~CMainFrame(void);  
  7. };  

Add implemented in blog_try.cpp

[cpp]  view plain copy
  1. CMainFrame::CMainFrame(void)  
  2. {  
  3. }  
  4. CMainFrame::~CMainFrame(void)  
  5. {  
  6. }  

Now blog_try.cpp code should be:

3, override the virtual function

Class new implementation, there are three virtual functions that must be rewritten, which are:

[cpp]  view plain copy
  1. LPCTSTR GetWindowClassName () const {} // This is a pure virtual function, we see UIBase.cpp in reference to it you can understand why have to implement it, because  
  2.     // when registering the window class name used in class (classname), is to use GetWindowClassName () to get the;  
  3.     // Analogously, we can () const {} to specify // category, rewrite this function by rewriting UINT GetClassStyle window class is registered in 360Demo in, you can go and see  
  4. void Notify (TNotifyUI & msg) {} // the new class in this class can be implemented to achieve message interceptor, so that when the specified message, a response function we  
  5.                                 // This function is mainly used in response to the control handle to the window message is sent  
  6. LRESULT HandleMessage (UINT uMsg, WPARAM wParam, LPARAM lParam) {} // message processing function, this process is mainly used to generate a message dialog window  

The first is the rewrite of the GetWindowClassName (), that returns an arbitrary string as the class name registered class on it

code show as below:

[cpp]  view plain copy
  1. LPCTSTR CMainFrame :: GetWindowClassName () const // function to rewrite get the class name, which is the class name to specify the new window class  
  2. {   
  3.     return _T("UIMainFrame");   
  4. };  

Then rewrite the Notify

code show as below:

[cpp]  view plain copy
  1. void CMainFrame::OnPrepare()   
  2. {  
  3. }  
  4. void CMainFrame :: Notify (TNotifyUI & msg) // notification message processing window, in response to user input  
  5. {  
  6.     if( msg.sType == _T("windowinit") ) OnPrepare();  
  7.   
  8. }  

Finally, rewriting HandleMessage () is:

3.1 define a variable

[cpp]  view plain copy
  1. CPaintManagerUI m_pm;  

This variable will be used to plot that we draw the various controls and the background image from its type name CPaintManagerUI can see that

3.2 The HandleMessage () {}

[cpp]  view plain copy
  1. LRESULT CMainFrame::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled){  
  2.     LONG styleValue = ::GetWindowLong(*this, GWL_STYLE);  
  3.     styleValue &= ~WS_CAPTION;  
  4.     ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);  
  5.   
  6.     m_pm.Init (m_hWnd); // main window class associated with the window handle  
  7.     CDialogBuilder builder;  
  8.   
  9.     CControlUI * pRoot = builder.Create (_T ( "UISkin.xml"), (UINT) 0, NULL, & m_pm); // load the XML interface and dynamically create the elements, and the layout of interface elements, analysis of the core functions alone  
  10.     // Note: CDialogBuilder not a dialog class  
  11.     ASSERT(pRoot && "Failed to parse XML");  
  12.     if (NULL == pRoot) // If you can not exit the skin file  
  13.     {  
  14.         MessageBox(NULL,TEXT("Cant not find the skin!"),NULL,MB_ICONHAND);  
  15.         return 0;  
  16.     }  
  17.     m_pm.AttachDialog (pRoot); // attach control data to the HASH table of PROOT ...... As the junction box, to create a control tree   
  18.     m_pm.AddNotifier (this); // increase notification processing  
  19.   
  20.     return 0;  
  21. }  
  22. LRESULT CMainFrame::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)  
  23.     {  
  24.         LRESULT lRes = 0;  
  25.         BOOL bHandled = TRUE;  
  26.         switch( uMsg ) {  
  27.         case WM_CREATE:   
  28.             lRes = OnCreate(uMsg, wParam, lParam, bHandled);   
  29.             break;  
  30.         default:  
  31.         bHandled = FALSE;  
  32.         }  
  33.         if( bHandled ) return lRes;  
  34.         if( m_pm.MessageHandler(uMsg, wParam, lParam, lRes) ) return lRes;  
  35.         return CWindowWnd::HandleMessage(uMsg, wParam, lParam);  
  36. }  

4, to achieve the main function WinMain ()

[cpp]  view plain copy
  1. int APIENTRY _tWinMain(HINSTANCE hInstance,  
  2.                      HINSTANCE hPrevInstance,  
  3.                      LPTSTR    lpCmdLine,  
  4.                      int       nCmdShow)  
  5. {  
  6.     CPaintManagerUI :: (hInstance) SetInstance; // setup instance  
  7.     CPaintManagerUI::SetResourcePath(CPaintManagerUI::GetInstancePath()   
  8.         + _T ( "skin")); // instance handle associated with rendering class, get skin file directory (skin file is loaded in the OnCreate)  
  9.   
  10.     HRESULT Hr = :: CoInitialize (NULL); // initialize COM library that provides support to load COM library  
  11.     if( FAILED(Hr) )   
  12.         return 0;  
  13.   
  14.     CMainFrame * pMainFrame = new CMainFrame (); // create the application window class object  
  15.     if( pMainFrame == NULL )   
  16.         return 0;  
  17.     pMainFrame->Create(NULL, _T("AdderCalc"), UI_WNDSTYLE_DIALOG, 0);  
  18.     pMainFrame-> CenterWindow (); // The central window on the desktop  
  19.     pMainFrame-> ShowWindow (true); // display window  
  20.     CPaintManagerUI :: MessageLoop (); // enter the message loop  
  21.   
  22.     :: CoUninitialize (); // exit the program and release the COM library  
  23.     return 0;  
  24. }  

As usual, the code Address: http://download.csdn.net/detail/harvic880925/5367129

 

Attached Reference: "DUIlib program summary .pdf" and the source code Download: http://download.csdn.net/detail/harvic880925/5367161

 

And error handling:

一, IDropTarget GetTxDropTarget * ();

Made an error: error C2143: syntax error: missing ';' (in front of the "*")

Solution: Add the header file: #include "OLEIDL.h"

Guess you like

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