After the last chapter of the configuration, we have a duilib environment, now we can start to write a DUI program.
If you do not yet how to download and configure Duilib, please visit the DIRECTUI study Note 1-Source download and environment configuration
A: We create a new class to inherit the base class that DUI provides to us
#include pragma once#include<UIlib.h>//If you attach the directory to the correct settings, you will not find it hereusing namespaceDuilib;//The following preprocessing directives are used to determine whether the project uses Unicode with corresponding LIB libraries for debug in release#ifdef _debug# ifdef _unicode# pragma comment (lib,"Duilib_ud.lib")# Else# pragma comment (lib,"Duilib_d.lib") # endif#else# ifdef _unicode# pragma comment (lib,"Duilib_u.lib")# Else# pragma comment (lib,"DuiLib.lib") # endif#endifclassCmyduiwnd: PublicCwindowwnd, Publicinotifyui{ Public: Cmyduiwnd () {}~Cmyduiwnd () {}//Getwindowclassname is a pure virtual function of the base class and must be implemented after we inherit it. VirtualLPCTSTR Getwindowclassname ()Const{return_t ("Duimainframe"); } //overriding a virtual function of a base class the following 2 are Virtual voidNotify (tnotifyui&msg) {} VirtualLRESULT handlemessage (UINT umsg, WPARAM WPARAM, LPARAM LPARAM) {LRESULT lres=0; if(umsg = = wm_create)//If a window creates a message { //Create a buttonCcontrolui *pbutton =NewCbuttonui; PWnd->settext (_t ("Hello world!"));//Set TextPwnd->setbkcolor (0xffff0000);//set a gray backgroundM_paintmanager.init (m_hwnd); M_paintmanager.attachdialog (Pbutton); returnLres; } if(M_paintmanager.messagehandler (umsg, WParam, LParam, lres))returnLres; return__super::handlemessage (umsg, WParam, LParam); }
B: The code in the main function
int int ncmdshow) { cpaintmanagerui::setinstance (hinstance);
Cmyduiwnd Framewnd; Framewnd (NULL, _t ("directui"), Ui_wndstyle_frame, Ws_ex_windowedge); Framewnd.showmodal ();
Framewnd.centerwindow ();
return 0 ;}
C: Post-run effects
Directui Study notes 2-dui Hellowworld Program