Windows form initial code comment

Source: Internet
Author: User

 

Winmain

  Hellowin. c

/* ------------------------------------------------------------------------

Hellowin. c -- displays "Hello, Windows 98! "In client area

(C) Charles Petzold, 1998

----------------------------------------------------------------------- */

# Include < Windows. h >


Lresult callback wndproc (hwnd, uint, wparam, lparam );


Int Winapi winmain (hinstance, hinstance hprevinstance,

Pstr szcmdline, Int Icmdshow)

{

Static Tchar szappname [] = Text ( " Hellowin " );

Hwnd;

MSG;

Wndclass;


Wndclass. Style = Cs_hredraw | Cs_vredraw; // The OR operation combines two window class style identifiers. cs_hredrow is the horizontal direction and cs_vredrow is the vertical direction.

Wndclass. lpfnwndproc = Wndproc; // Window Message ProcessingProgramAddress
/////////////// Reserved additional space /////////////// /
Wndclass. cbclsextra = 0 ;

Wndclass. cbwndextra = 0 ;
//////////////////////////////////// /

Wndclass. hinstance = Hinstance; // Program Execution entity handle

Wndclass. hicon = Loadicon (null, idi_application ); // Set an icon

Wndclass. hcursor = Loadcursor (null, idc_arrow ); // Set the cursor

Wndclass. hbrbackground = (Hbrush) getstockobject (white_brush ); // Set background color

Wndclass. lpszmenunam = NULL; // Window category menu

Wndclass. lpszclassname = Szappname; // Name of the window message processing program


If ( ! Registerclass ( & Wndclass ))

{

MessageBox (null, text ( " This program requires Windows NT! " ),

Szappname, mb_iconerror );

Return 0 ;

}

Hwnd = Createwindow (szappname, // Window class name

Text ( " The Hello Program " ), // Window caption

Ws_overlappedwindow, // Window Style

Cw_usedefault, // Initial X position upper left corner x

Cw_usedefault, // Initial y position upper left corner y

Cw_usedefault, // Initial x size width

Cw_usedefault, // Initial y size height

Null, // Parent window handle

Null, // Window menu handle

Hinstance, // Program instance handle

Null ); // Creation Parameters



Showwindow (hwnd, icmdshow );

Updatewindow (hwnd );



While (Getmessage ( & MSG, null, 0 , 0 ))

{

Translatemessage ( & MSG ); // Translate messages

Dispatchmessage ( & MSG ); // Send messages

}

Return MSG. wparam;

}

// The following is the window message processing program.
Lresult callback wndproc (hwnd, uint message, wparam, lparam)

{

HDC;

Paintstruct pS; // Contains some window message processing procedures, which can be used to update the content of the display area.

Rect;



Switch (Message)

{

Case Wm_create:

Playsound (text ( " Hellowin.wav " ), Null, snd_filename | Snd_async );

Return 0 ;


Case Wm_paint:

HDC = Beginpaint (hwnd, & PS );



Getclientrect (hwnd, & Rect );



Drawtext (HDC, text ( " Hello, Windows 98! " ), - 1 , & Rect,

Dt_singleline | Dt_center | Dt_vcenter );

Endpaint (hwnd, & PS );

Return 0 ;



Case Wm_destroy:

Postquitmessage ( 0 );

Return 0 ;

}

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.