Windows program run Process

Source: Internet
Author: User
Tags textout

Windows application:

WinMain function (entry function):

1. Design window class, register window class; wndclass

2. Create Windows, display and update windows;

3. Message loops;

Window 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 run Process

#include <windows.h> #include <stdio.h>lresult CALLBACK winsunproc (//Window procedure function (callback function) declares HWND hwnd, UINT umsg, WPARAM WPARAM, LPARAM LPARAM); int WINAPI WinMain (//winmain function, Windows application portal HInstance hinstance, HINST          Ance hprevinstance, LPSTR lpcmdline, int ncmdshow) {wndclass wndcls; Instantiate a window 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); Register window class hwnd Hwnd;hwnd = CreateWindow ("Hepengtao", "window caption", Ws_overlappedwindow,//Create window 0,0,600,400,null,null,hinstance , NULL);  ShowWindow (Hwnd,sw_shownormal);             Display window UpdateWindow (HWND); Update window MSG msg;while (GetMessage (&msg,null,0,0))//Remove message from Message queue, return 0 when Wm_quit message is obtained{TranslateMessage (&msg);//When the keyboard key is pressed, the system gets wm_keydown and Wm_keyup message, which is transformed into WM_CHAR message dispatchmessage (&AMP;MSG); Pass the resulting message to the callback function}return 0;}  LRESULT CALLBACK Winsunproc (//Define window 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 "," Pop-up window 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://Window redraw, 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 window?" "," popup title ", Mb_yesno)) {DestroyWindow (HWND);//Destroy window and send wm_destory message}break;case Wm_destroy://execute 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 run 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.