Windows GDI related (excerpt) + windows

Source: Internet
Author: User

processing non-> wm_paint when a message is sent, use the Program to obtain the handle of the device description table in the window user area getdc function, which is often used to provide feedback on certain user actions. For example, you can draw a line on the screen when you move the cursor over the window. getdc the function returns a display buffer handle, which can be used for any GDI output function.

use getdc the function obtains the display buffer handle, process in the window function wm_paint message. When the window function receives the wm_paint when a message is sent, the content previously drawn in the user area may be erased. This is because wm_paint , Windows send wm_erasebkgnd the message is sent to the window function. If wm_erasebkgnd send the message to defwindowproc function processing , defwindowproc The function uses the background color of this window class to fill the affected area and erase the previously drawn content.


When Windows sends a wm_paint message, it is placed at the end of the application queue, so that other input can be processed before the wm_paint message. The getmessage function also obtains other messages after the wm_paint message in the queue. That is, the wm_paint message is extracted from the queue only when there are other messages. This is done to allow the application to first complete other operations that affect the Display Results of the window, so that the display will not flash due to frequent output operations. This is why Windows puts the wm_paint message in the queue.

(Here we use queues such as priority queue to ensure priority)

if you do not want to wait for the wm_paint message in the application queue, use the updatewindow function to directly send the wm_paint message to the window function of the specified window. If an invalid user partition exists, the updatewindow function extracts the wm_paint message from the queue and sends it directly to the window function of the specified window. The updatewindow function is usually used in the user area where the window needs to be updated immediately, for example, when the window is just created.


what is the difference between GDI and GDI ++? Does it only provide support for some graphic formats?


For Windows, to create a window, you must first register a window class with registerclass. Windows has already created some standard, such as button and label.

Then you can use createwindow to generate this window.

In Windows, message queues are measured in threads. Each interface thread has one,

While (getmessage (& MSG, null, 0, 0 ))
{
Translatemessage (& MSG); // translate the message
Dispatchmessage (& MSG); // remove the message
}

This Infinite Loop is used to receive the sending and splitting messages. Then, each window registers a callback function through registerclass, In the dispatchmessage

Find the wndproc in the specific window according to the hwnd of MSG, and then call it. After the call is complete, continue to the next getmessage.

Turn: Once the above work is completed, we will pass the message to dispatchmessage (). dispatchmessage () first.
Check the window to which the signal is sent, and then find the window process. Then call the process. The parameter is window.
Handle, message, wparam, and lparam.

While (getmessage (& MSG, null, 0, 0)> 0)
{
Wndproc fwndproc = (wndproc) getwindowlong (msg. hwnd, gwl_wndproc );
Fwndproc (msg. hwnd, MSG. Message, MSG. wparam, MSG. lparam );
}

After all, the on_command macro generates a struct.

Windows provides a default window message processing function for defwindowproc. wndproc can be called to process all messages that you do not want to care about.


When you click the mouse over a menu such as file, a message wm_initmenupopup is generated, and the border window responds to the message before the menu drop-down to update the status of all items in the menu.

When the application starts running, the border will also receive the wm_initmenupopup message.

When the application enters the idle processing status, the wm_idleupdatecmdui message is sent, causing the status processing function of all tool bar user objects to be called, thus changing its status. Wm_idleupdatecmdui is a message defined and used by MFC.

You can also actively send a message to update the interface status postmessage (wm_idleupdatecmdui, true, 0 );

The default idle processing provided by MFC sends the message wm_idleupdatecmdui to all sub-windows in the top-level window (Framework Window). The control window (tool bar, status bar, etc.) of MFC processes the message, result In calling of the object state processing function.

Message Processing in the framework is forwarded through ondomainmsg. In childframe, View> ondomainmsg is called, and view calls document> ondomainmsg.

During window initialization, the toolbar also receives the wm_idleupdatecmdui message.


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.