My own windows window

Source: Internet
Author: User

/*
Hellowin. C displays "Hello, Windows XP! "In client area
*/

# 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 ");
/*
Typedef handle hwnd;
Typedef pvoid handle;
Typedef void * pvoid;
*/
Hwnd;
/*
Typedef struct tagmsg {
Hwnd;
Uint message;
Wparam;
Lparam;
DWORD time;
Point pt;
} MSG;
*/
MSG;
/*
Typedef struct _ wndclass {
Uint style;
Wndproc lpfnwndproc;
Int cbclsextra;
Int cbwndextra;
Handle hinstance;
Hicon;
Hcursor;
Hbrush hbrbackground;
Lpctstr lpszmenuname;
Lpctstr lpszclassname;
} Wndclass;
Window struct
*/
Wndclass; // use wndclass (wndclassex) to define a window object

Wndclass. Style = cs_hredraw | cs_vredraw ;//
Wndclass. lpfnwndproc = wndproc;
Wndclass. cbclsextra = 0;
Wndclass. cbwndextra = 0;
Wndclass. hinstance = 0;
Wndclass. hicon = loadicon (null, idi_application );
Wndclass. hcursor = loadcursor (null, idc_arrow );
Wndclass. hbrbackground = (hbrush) getstockobject (white_brush );
Wndclass. lpszmenuname = NULL;
Wndclass. lpszclassname = szappname;

If (! Registerclass (& wndclass) // registration window
{
MessageBox (null, text ("this program requires Windows NT! "), Szappname, mb_iconerror );

Return 0;
}
// Create a window
Hwnd = createwindow (szappname, // window class name
Text ("the hello program"), // window caption
Ws_overlappedwindow, // window style
Cw_usedefault, // initial X position
Cw_usedefault, // initial y position
Cw_usedefault, // initial X size
Cw_usedefault, // initial y size
Null, // parent window handle
Null, // Window menu handle
Hinstance, // program instance handle
Null); // creation Parameters
// Set the detailed display status of the window
Showwindow (hwnd, icmdshow );
// Refresh and display the window
Updatewindow (hwnd );
 
While (getmessage (& MSG, null, 0, 0 ))
{
Translatemessage (& MSG );
Dispatchmessage (& MSG );
}
Return msg. wparam;
}
/* # Define callback _ stdcall;
Typedef long_ptr lresult;
# If defined (_ win64)
Typedef _ int64 long_ptr;
# Else
Typedef long long_ptr;
# Endif
*/
Lresult callback wndproc (hwnd, uint message, wparam, lparam)
{
HDC;
Paintstruct pS;
Rect;

Switch (Message) // Message Processing Switch
{
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 XP! "),-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); // call the default Processing Method
}

 

Unsolved problem: unable to understand callback, check the msdn display # define callback _ stdcall; I do not understand it !!!

Related Article

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.