The simplest Windows GUI program, consisting of WMain.cpp and WinProc.cpp, is responsible for initializing the window and handling the message.
File:WMain.cpp
#include <windows.h>extern LRESULT CALLBACK windowf (HWND, UINT, WPARAM, LPARAM); char szwinname[] = "Mywin"; char SzT Itle[] = "My WINDOW"; int WINAPI WinMain (hinstance hthisinst, hinstance hprevinst, LPSTR lpszargs, int nwinmode) {//Define Window Classhwnd hwnd; MSG msg; Wndclassex Wcl;wcl.cbclsextra = 0;//extra byteswcl.cbsize = sizeof (wndclassex); Wcl.cbwndextra = 0;wcl.hbrBackground = ( Hbrush) Getstockobject (white_brush); wcl.hcursor = LoadCursor (null, idc_arrow); Wcl.hicon = LoadIcon (null, IDI_WINLOGO) ; WCL.HICONSM = Null;wcl.hinstance = Hthisinst;wcl.lpfnwndproc = Windowf;wcl.lpszclassname = SzWinName;wcl.lpszMenuName = Null;wcl.style = 0;//Registration of Classif (! RegisterClassEx (&WCL)) return 0;//Create Windowhwnd = CreateWindow (Szwinname,sztitle,ws_overlappedwindow | Ws_hscroll | Ws_vscroll | Ws_sysmenu,cw_usedefault,cw_usedefault,cw_usedefault,cw_usedefault,hwnd_desktop,null,hthisinst,null); ShowWindow (hwnd, Sw_restore); UpdateWindow (HWND);//Serve Messageswhile (GetMessage (&AMp;msg, NULL, 0, 0) {translatemessage (&msg);D ispatchmessage (&msg);} return Msg.wparam;}
File:WinProc.cpp
#include <windows.h>lresult CALLBACK WINDOWF (HWND hwnd, UINT message, WPARAM WPARAM, LPARAM LPARAM) {switch (message {Case wm_destroy://User Closed the windowpostquitmessage (0); break;default:break;} Call the default window Handlerreturn DefWindowProc (HWND, message, WParam, LParam);}
Examples of running results:
First window GUI program