First window GUI program

Source: Internet
Author: User

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 (&AMP;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

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.