I can see this article on the Internet. ondrawitem and drawitem discuss it.

Source: Internet
Author: User

I often encounter drawitem () Rewriting in my studies, but there is another wm_drawitem message. What is the relationship between them.

If we want to override a cbutton and name it cmybutton, we can rewrite the drawitem () function of cmybutton to implement our

Yes, but when is the cmybutton: drawitem () called? It is called in ondrawitem () of its host class,

Ondrawitem (INT nidctl, lpdrawitemstruct) is the corresponding function for wm_drawitem.

The host class can determine the child Control Based on nidctl. In fact, we can draw child controls in the ondrawitem function, but there are many

The child control of the Child class looks bad, so we should plot the Child class in the drawitem of the Child class, for example, cmybutton: drawitem. So you can

In this way, ondrawitem is the Child control in the painting window, because its entry parameter lpdrawitemstruct brings the phase of different child Controls

You must set the word control to the "self-painting" type before calling ondrawitem.

When the owner-draw button, combo box, list box visual attribute, or menu changes,

The Framework calls ondrawitem (send wm_drawitem) for their owner and calls drawitem (send wm_drawitem message) of the subclass in the host class ).

We can reload the drawitem sub-class to draw the required controls. Not all controls set to the self-painting type will call the ondrawitem of the parent window,

For example, in ListBox, you must reload the drawitem and measureitem methods of clistbox.

Ondrawitem. In the SDK, The subclass cannot be affected by wm_drawitem. In MFC, this is designed by the class designer (reflection), which is indeed good.

In learning, another message is also called by the host class, which is wm_ctrcolor. This message is sent to the host when the child control is to be painted.

class sending, the host class uses the launch mechanism to enable the subclass to process itself. onctlcolor (CDC * PDC, cwnd * pwnd, uint nctlcolor)

PDC and pwnd are both child classesRelated: You can set the foreground color, background color, paint brush type, Font, and so on, but you cannot change the interface frame of the element,

This is drawitem What can be done.

If drawitem (subclass), ondrawitem (host class), and onctlcolor (host class) exist at the same time, their call sequence is:

Onctlcolor, ondrawitem, drawitem.

If we have simultaneously processed the wm_paint message of the corresponding subclass, onpaint may have performed some processing internally to determine whether the message is automatically painted to the host class.

Send wm_drawitem, so if the wm_paint subclass responds, wm_drawitem messages will not be sent to the host class.Paint all

If the subclass is a list box, it is very troublesome. The call sequence is onctlcolor and onpaint.

Before sending a wm_paint message, a wm_eraseback message will always be sent first. Here we have a background image.

 

The above section describes how to draw controls at ordinary times. There is also a cview problem, that is, the relationship between onpaint and ondraw,

In fact, this is very simple. The source code of cview: onpaint () is as follows:

[CPP]   View plaincopy
  1. void cview: onpaint ()
  2. {
  3. cpaintdc ( This );
  4. Onpreparedc (& DC );
  5. Ondraw (& DC)
  6. }

from Code , you can understand See their relationship.

Related Article

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.