Directui Study notes 2-dui Hellowworld Program

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.