Windows program execution Process

Source: Internet
Author: User
Tags textout

Windows application:

WinMain function (entry function):

1.

Design Form class, brochure form class. Wndclass

2.

Create forms, display and update forms.

3.

Message loops.

Form procedure function (callback function): WindowProc

Ps:dos Program entry function for the Main,windows program entry is WinMain, which is called directly by the system.

Windows program execution Process

#include <windows.h> #include <stdio.h>lresult CALLBACK winsunproc (//Form procedure function (callback function) declares HWND hwnd, UINT umsg, WPARAM WPARAM, LPARAM LPARAM); int WINAPI WinMain (//winmain function.          Windows Application Entry hinstance hinstance, hinstance hprevinstance, LPSTR lpcmdline, int ncmdshow) {wndclass wndcls; Instantiate a form class object and set individual properties Wndcls.cbclsextra = 0;wndcls.cbwndextra = 0;wndcls.hbrbackground = (hbrush) getstockobject (BLACK_ BRUSH); wndcls.hcursor = LoadCursor (null,idc_cross); Wndcls.hicon = LoadIcon (null,idi_error); wndcls.hinstance = Hinstance;wndcls.lpfnwndproc = Winsunproc;wndcls.lpszclassname = "Hepengtao"; wndcls.lpszmenuname = NULL;wndcls.style = Cs_hredraw | Cs_vredraw;  RegisterClass (&AMP;WNDCLS); Brochure Form class hwnd Hwnd;hwnd = CreateWindow ("Hepengtao", "form title", Ws_overlappedwindow,//Create form 0,0,600,400,null,null,hinstance , NULL);  ShowWindow (Hwnd,sw_shownormal);             Display Form UpdateWindow (HWND); Update Form MSG msg;while (GetMessage (&msg,null,0,0))//Remove message from Message queue, return 0 when Wm_quit message is obtained{TranslateMessage (&msg);//When you press the keyboard key. The system gets wm_keydown and WM_KEYUP messages. The function is transformed into WM_CHAR message dispatchmessage (&AMP;MSG); Pass the resulting message to the callback function}return 0;}  LRESULT CALLBACK Winsunproc (//Define form procedure function (callback function) HWND hwnd, UINT umsg, WPARAM WPARAM, LPARAM LPARAM) {switch (umsg) {case WM_CHAR://keyboard pressed letter, send WM_CHAR message CHAR szchar[20];sprintf (Szchar, "char is%d", wParam); MessageBox (Hwnd,szchar, "popup title", 0); Break;case wm_lbuttondown://left mouse button pressed. Send WM_LBUTTONDOWN message MessageBox (hwnd, "Mouse clicked", "popup title", 0); HDC HDC;HDC = GetDC (hwnd); TextOut (hdc,0,50, "I am Hepengtao.", strlen ("I am Hepengtao."); ReleaseDC (HWND,HDC); Break;case WM_PAINT://When the form is redrawn, send WM_PAINT message hdc hdc; Paintstruct PS;HDC = BeginPaint (HWND,&AMP;PS); TextOut (hdc,0,0, "hello,world!", strlen ("hello,world!")); EndPaint (HWND,&AMP;PS); Break;case wm_close://Close button pressed, send Wm_close message if (Idyes = = MessageBox (hwnd), "OK to close the form?" "," popup title ", Mb_yesno)) {DestroyWindow (HWND);//Destroy form and send Wm_destory message}break;case Wm_destroy://Run Destorywindow () function. Send Wm_destory message postquitmessage (0); Program request exit, send Wm_quit message Break;default:return DefWindowProc (Hwnd,umsg,wparam,lparam); The user does not care about the message, which is handled by the operating system by default}return 0;}


Windows program execution Process

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.