Windows program running process, windows program running

Source: Internet
Author: User
Tags textout

Windows program running process, windows program running

Windows applications:

WinMain function (entry function ):

1. Design window class, register window class; WNDCLASS

2. Create, display, and update Windows;

3. Message loop;

Window procedure function (callback function): WindowProc

PS: the Dos program entry function is main, and the Windows program entry is WinMain, which is directly called by the system.

Windows program running 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 entry HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {WNDCLASS wndcls; // instantiate a window class object and set the wndcls attributes. cbClsExtra = 0; wndcls. cbWndExtra = 0; wndcls. hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH); wndcl S. 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 (& wndcls); // register the window class HWND hwnd; hwnd = CreateWindow ("hepengtao", "window title", WS_OVERLAPPEDWINDOW, // create a window of 600,400, NULL, NULL, hInstance, NULL); ShowWindow (hwn D, SW_SHOWNORMAL); // display the window UpdateWindow (hwnd); // update the window MSG msg; while (GetMessage (& msg, NULL, 0, 0 )) // retrieve the message from the message queue. When the WM_QUIT message is obtained, 0 {TranslateMessage (& msg) is returned; // when the keyboard is pressed, The system receives the WM_KEYDOWN and WM_KEYUP messages, after this function is converted to the WM_CHAR message DispatchMessage (& msg); // pass the obtained message to the callback function} return 0 ;} lresult callback WinSunProc (// defines the window procedure function (CALLBACK function) HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {switch (uMsg) {case WM_CHAR: // send the WM_CHAR message after pressing the letter on the keyboard Char szChar [20]; sprintf (szChar, "char is % d", wParam); MessageBox (hwnd, szChar, "pop-up window title", 0); break; case WM_LBUTTONDOWN: // after pressing the left mouse button, send the 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: // send the WM_PAINT message HDC hDC; PAINTSTRUCT ps; hDC = BeginPaint (hwnd, hdc, & ps); TextOut (hDC, 0, 0, "Hello, world! ", Strlen (" Hello, world! "); EndPaint (hwnd, & ps); break; case WM_CLOSE: // After the button is pressed, send the WM_CLOSE message if (IDYES = MessageBox (hwnd, "Are you sure you want to close the window? "," Pop-up window title ", MB_YESNO) {DestroyWindow (hwnd); // destroy the window and send the WM_DESTORY message} break; case WM_DESTROY: // when the DestoryWindow () function is executed, send the WM_DESTORY message PostQuitMessage (0); // exit the program request and send the WM_QUIT message break; default: return DefWindowProc (hwnd, uMsg, wParam, lParam); // the message that the user does not care about, processed by the operating system by default} return 0 ;}



Who can explain the process of running a program in windows?

This is not the case. compilers are generally divided into compilation and interpretation types. The compiled type, such as the C language program, is compiled with links to form executable binary code, which can be run directly in windows. The interpreted type, such as java, is an intermediate code, during execution, the java Runtime Environment (jre) must be used to explain and execute. This is also the reason why jre must be used to run java program computers.

How to obtain the input and output data during windows application execution?

Generally, you can use VC to open the program text. After studying the program's working principles, you will naturally know when the program inputs and outputs data.
 

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.