Can withstand loneliness, can not resist the temptation, this is the process of life
Steps:
1. Define various variables in the WinMain
2. Registration window class RegisterClass
3. Create Window CreateWindow
4. display window and Update window
Copy Code code as follows:
ShowWindow (hwnd, icmdshow);
UpdateWindow (HWND);
5. Message loop
Copy Code code as follows:
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&MSG);
DispatchMessage (&MSG);
}
Complete code:
Copy Code code as follows:
#include <windows.h>
Lresult CALLBACK MyProc (HWND hwnd,uint message,wparam wparam,lparam);
int WINAPI WinMain (hinstance hinstance, hinstance hprevinstance, LPSTR lpcmdline, int nshowcmd)
{
MSG msg;
HWND hwnd;
Static TCHAR szappname[] = "HL";
Wndclass Wndclass;
Wndclass.style = Cs_hredraw | Cs_vredraw;
Wndclass.cbclsextra = 0;
Wndclass.cbwndextra = 0;
Wndclass.lpfnwndproc = MyProc;
Wndclass.hinstance = hinstance;
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))
{
MessageBox (Null,text ("error"), TEXT ("title"), Mb_iconerror);
return 0;
}
hwnd = CreateWindow (Szappname,
TEXT ("Hello"),
Ws_overlappedwindow,
Cw_usedefault,
Cw_usedefault,
Cw_usedefault,
Cw_usedefault,
Null
Null
HINSTANCE,
Null
);
ShowWindow (Hwnd,nshowcmd);
UpdateWindow (HWND);
while (GetMessage (&msg,hwnd,0,0))
{
TranslateMessage (&MSG);
DispatchMessage (&MSG);
}
return msg.wparam;
}
Lresult CALLBACK MyProc (HWND hwnd,uint message,wparam Wparam,lparam)
{
Switch (message)
{
Case Wm_destroy:
PostQuitMessage (0);
return 0;
}
return DefWindowProc (Hwnd,message,wparam,lparam);
}