Windows core Programming (1)

Source: Internet
Author: User
Tags terminates

I. Creating a process message loop

1.WinMain First call the API function registerclass Register a window class, this class defines

The window's important properties, such as window procedure address, default background color, icon. by WNDCLASS structure Fields

To define, when a program generates a window, it must make a window class that must be registered before the class is used.

This is why RegisterClass is called at the beginning of the program,

2. Once WNDCLASS is registered, WinMain calls the most important CreateWindow function to build the application

3. An MFC program you do not see the WinMain function, he also does not call registerclass or CreateWindow

The ShowWindow is called after CreateWindow because the build has no ws_visible

It is visible to the window and ensures that the WM_PAINT message handler executes immediately.

4. Next is the message loop, in order to retrieve and dispatch the message, WinMain executes a simple repeated call

Getmessage,translatemessage, and DispatchMessage these 3 API-speaking while loop statements of functions

GetMessage checks Message Queuing, if a message is valid, it is removed from the queue and copied to the MSG

Otherwise the getmessage will stay on the message queue knowing that the message is valid, and MSG is an instance of MSG

It knows that the warranty contains the relevant message parameters,

For example, the message ID and the time that the message was placed in the queue, the TranslateMessage function takes a keyboard that indicates a character key

The message is converted into an easy-to-use WM_CHAR message, and the DispatchMessage function sends a message to the window procedure,

5. The message loop loops until the GetMessage function returns a value of 0, which is the only wm_quit message from the message queue

Occurs only when it is retrieved. This is the end of the WinMain, the program terminates.

6. Messages dispatched by the DispatchMessage function will produce calls to the window procedure WinProc, others are not processed

Message is passed to the DEFWINDOWPROC function for default processing.

7. Window class is the data structure of Windows System, window class contains important information of window, such as window style, window message processing WndProc

The cursor of the window, etc.




Ii. Application objects

    1. MFC application core is based on the CWinApp class object, CWinApp provides a message loop and to retrieve the message,

and dispatches the message to the application window

2. Overwrite ExitInstance called after the application terminates, is the perfect place to release resources, overwriting to ensure that the base class is called






Iii. frame Window Object

1.MFC CWnd class machine derived class provides an object-oriented interface for Windows or application-created Windows

The window class is derived from the CFrameWnd class from CMainWindow, and the latter is derived from CWnd

CFrameWnd the behavior of the Mimic box window,

2. Customer and non-client areas

The non-client area of the window contains the title bar. Menu bar, window border

Customer area refers to areas outside the customer area, which are customer areas

3. Window styles are a set of properties that affect the appearance and behavior of a window

Macro definition with WS prefix

Ws_border Creating a window with borders

Ws_caption Creating a window with a title bar

Ws_child Create a sub-window and so on ...

4. window extension samples are generally defined with a ws_ex_-prefixed macro

Ws_ex_clientedge indicates that the window has a 3D appearance

Ws_ex_appwindow when the window is visible, place the window in the taskbar

Ws_ex_controlparent allows the user to tab through child windows ...



Iv. window z-order and Desktop window

    1. The concept of window Z-order

The general x-Axis Y-axis represents the planar position, and the z-axis represents the front and back position, and the x-axis is left-to-right

The Z-axis points from the screen to the outside of the screen, the Z-order value indicates the order of the window, the larger the Z-order value, the closer the screen appears to the user

2. Desktop Window

The desktop window is the corresponding window of the system desktop, the desktop window and other relationships are, the desktop window at the bottom, other windows

On top of it, all of its z-order values are minimal.



V. Parent window and Owner window

    1. Parent window and owner window rank

There are two kinds of relationships between windows, one is Owner-owner relationship and parent-child relationship

The former is all/by all relationships, the latter is a parent/child relationship, owner is called All windows, and parent is parented window


2. Relationship of parent window to child window

The child window is embedded in the parent window, as if it were pinned to the parent window, and the Subwindow display area cannot exceed

The display area of the parent window is not displayed, and when the parent window is hidden, all its child windows are also hidden,

When the parent window is destroyed, it owns all the child windows that are destroyed.


3. Relationship between the owner window and the owner window

All windows are always displayed on top of the owner window and are automatically hidden by all windows when the owner window is minimized

When all windows are destroyed, all windows are destroyed, and when the owner window is moved, all windows are not moved together,

All windows can be displayed outside the owner window area.






Windows core Programming (1)

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.