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 );
}