We need to create a project independently and add skin to our project. This is the original intention. My new Project name: duilibtest
There is a duilib 文 .doc under the duilib root directory. Let's start with this tutorial.
Create a Win32 Project
Go to the duilib root directory and copy the duilib folder under the directory to the root directory of the new project. Add this project to our solution.
Paste the following code from the tutorial to stdafx. h of our project.
// Duilib settings # pragma once # define win32_lean_and_mean # DEFINE _ crt_secure_no_deprecate # include <windows. h> # include <objbase. h> # include ".. \ duilib \ uilib. H "using namespace duilib; # ifdef _ debug # ifdef _ Unicode # pragma comment (Lib ,".. \ bin \ duilib_ud.lib ") # else # pragma comment (Lib ,".. \ bin \ duilib_d.lib ") # endif # else # ifdef _ Unicode # pragma comment (Lib ,".. \ bin \ duilib_u.lib ") # else # pragma comment (Lib ,".. \ bin \ duilib. lib ") # endif
Delete all the code referenced by the header file in duilibtest. cpp, And Then paste the following code into duilibtest. cpp.
// Class cframeworkwwnd: Public cshortwwnd, public inotifyui {public: cframeworkwwnd () {}; lpctstr getwindowclassname () const {return _ T ("uimainframe") ;}; uint getclassstyle () const {return ui_classstyle_frame | cs_dblclks ;}; void onfinalmessage (hwnd/* hwnd */) {Delete this ;}; void Policy (tpolicyui & MSG) {If (MSG. stype = _ T ("click") {If (MSG. psender-> getname () = _ T ("closebtn") {close () ;}} lresult handlemessage (uint umsg, wparam, lparam) {If (umsg = wm_create) {m_pm.init (m_hwnd); ccontrolui * pbutton = new cbuttonui; pbutton-> setname (_ T ("closebtn ")); pbutton-> setbkcolor (0xffff0000); m_pm.attachdialog (pbutton); equals (this); Return 0;} else if (umsg = wm_destroy) {: postquitmessage (0 );} lresult lres = 0; If (m_pm.messagehandler (umsg, wparam, lparam, lres) return lres; return c0000wwnd: handlemessage (umsg, wparam, lparam);} public: cpaintmanagerui m_pm;}; // program entry and duilib initialization part int apientry winmain (hinstance, hinstance/* hprevinstance */, lpstr/* lpcmdline */, int ncmdshow) {cpaintmanagerui:: setinstance (hinstance); cpaintmanagerui: setresourcepath (cpaintmanagerui: getinstancepath (); cframeworkwwnd * pframe = new cframeworkwwnd (); If (pframe = NULL) return 0; pframe-> Create (null, _ T ("test"), ui_wndstyle_frame, ws_ex_1_wedge); pframe-> showwindow (true); cpaintmanagerui: messageloop (); Return 0 ;}
At this time, the compilation may report an error: Link: Fatal error lnk1104: the file ".. \ bin \ duilib_ud.lib" cannot be opened"
On the one hand, we did not copy the Lib file. On the other hand, we should use the unicodedebug mode when compiling duilib.
After recompiling duilib, find duilib_ud.lib In the Lib folder and copy it to the bin folder. Copy duilib_ud.dll from the bin folder to the debug folder.
Compile duilibtest again. The running result is as follows:
This step shows that your duilib is ready for use. Next, follow the document to read the xml configuration.
First, change the code in handlemessage to the new one.
//CControlUI *pButton = new CButtonUI;//pButton->SetName(_T("closebtn"));//pButton->SetBkColor(0xFFFF0000);//m_pm.AttachDialog(pButton);CDialogBuilder builder;CControlUI* pRoot = builder.Create(_T("test1.xml"), (UINT)0, NULL, &m_pm);ASSERT(pRoot && "Failed to parse XML");m_pm.AttachDialog(pRoot);
Create a test1.xml file and use vs to directly create an XML file to ensure that the XML file is encoded in UTF-8 format.
Write the following code in XML:
<? XML version = "1.0" encoding = "UTF-8"?> <Window mininfo = "200,360" size = "480,320"> <font name = "" size = "16" default = "true"/> <verticallayout bkcolor = "# ffff00ff "> <button name =" closebutton "Height =" 20 "text =" test button "maxwidth =" 120 "/> <RichEdit name =" testrichedit "bordercolor =" # ff0000" bordersize = "0" borderround = "18, 18" Inset = "4, 2, 4, 2 "bkcolor =" # a0f2f5fa "bkcolor2 =" # a0ff0000 "bkcolor3 =" # a0f2f5fa "font =" 1 "multiline =" true "vscrollbar =" true "autovscroll =" true" enabled = "true" Rich = "true" readonly = "false" text = "test RichEdit"> </RichEdit> <edit name = "testedit" text = "test edit box" /> </verticallayout> </WINDOW>
Copy the XML file to debug and debug the program. The following results are displayed:
OK. Now, the UI part probably knows how to write it, but we still have a very important entry, that is, event response. In fact, I really like the introductory documents written by the authors of this library.
There are two methods for Event Response in duilib:
1. Implement the inotifyui interface in the event processing class (usually the window class), and then process the event in the notify function.
Processing in the notify function is what we saw earlier, through if (MSG. stype = _ T ("click") to determine whether it is a click event, and then use MSG. psender-> getname () = _ T ("closebutton") to determine the name and determine which button triggers the event
2. Use a proxy mechanism to process events
It's complicated. If you don't understand what you are, you won't miss it.