The first Windows Application

Source: Internet
Author: User
# Include < Windows. h >

//Window Process Declaration
Lresult callback wndproc (hwnd, uint, wparam, lparam );

Int _ Stdcall winmain (hinstance, hinstance hprevinstance, lpstr lpcmdline, Int Ncmdshow)
{
Const   Char * Szwindowname =   " First Windows ApplicationProgram " ; // Window title
Const   Char * Szclassname =   " Windowclass " ; // Window class name

// Create a wndclassex struct variable and set the member value for it.
Wndclassex wndclass;
Wndclass. cbsize =   Sizeof (Wndclassex ); // Structure Size
Wndclass. Style = Cs_hredraw | Cs_vredraw; // Horizontal and vertical
Wndclass. lpfnwndproc = (Wndproc) wndproc; // Window Process
Wndclass. cbclsextra =   0 ; // No additional class memory
Wndclass. cbwndextra =   0 ; // No additional window memory
Wndclass. hinstance = Hinstance; // Instance handle
Wndclass. hicon = Loadicon (null, idi_application ); // Program icon
Wndclass. hcursor = Loadcursor (null, idc_cross ); // Mouse Style
Wndclass. hbrbackground = (Hbrush): getstockobject (white_brush ); // White Background
Wndclass. lpszmenuname = NULL; // No menu name
Wndclass. lpszclassname = Szclassname; // Window class name
Wndclass. hiconsm = NULL; // No small icon for the class

//Register the wndclassex struct
: Registerclassex (&Wndclass );

// Create Main Window
Hwnd = : Createmediawex (
0 , // Dwexstyle, extended Style
Szclassname, // Lpclassname, Class Name
Szwindowname, // Lpwindowname, title
Ws_overlappedwindow, // Dwstyle, window style
Cw_usedefault, // X, initial X coordinate
Cw_usedefault, // Y, initial y coordinate
Cw_usedefault, // Nwidth, width
Cw_usedefault, // Nheight, height
Null, // Hwndparent, parent window handle
Null, // Hmenu, menu handle
Hinstance, // Hinstance, program instance handle
Null ); // Lpparam, user data

If (Hwnd = Null)
{
: MessageBox (null, " An error occurred while creating the window! " , " Error " , Mb_ OK );
Return False;
}

//Display window
: Showwindow (hwnd, ncmdshow );

//Refresh window
: Updatewindow (hwnd );

// message loop
MSG;
while (: getmessage ( & MSG, null, 0 , 0 ))
{< BR >:: translatemessage ( & MSG);
:: dispatchmessage ( & MSG);
}

ReturnMSG. wparam;
}

//Window Process Functions
Lresult callback wndproc (hwnd, uint message, wparam, lparam)
{
Const Char*Szhello= "Hello World";

Switch (Message)
{
// Redraw window
Case Wm_paint:
HDC;
Paintstruct pS;
HDC = : Beginpaint (hwnd, & PS );
: Textout (HDC, 10 , 10 , Szhello, strlen (szhello ));
: Endpaint (hwnd, & PS );
Break ;
// Destruction window
Case Wm_destroy:
: Postquitmessage ( 0 );
Break ;
}

//Hand over to the system for default Processing
Return: Defwindowproc (hwnd, message, wparam, lparam );
}

 

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.