Re-painting in the dialog box

Source: Internet
Author: User

1) Reload onpaint () in the dialog box. The cpaintdc DC (this) has its own coordinate system. You can use mapdialogrect to remove the template unit from the screen unit on the network. This is on the network, and then I used cpaintdc (this ),

Cpaintdc DC (this); // device context for painting
// Todo: add the message processing program code here
// Do not call cdialogex: onpaint () for the drawing message ();
Crect RC;
Getdlgitem (idc_line_static)-> getwindowrect (RC );
Screentoclient (RC );
Cpen pen (m_linetype, m_linewidth, m_linecolor );
Cpen * oldpen = Dc. SelectObject (& pen );
DC. moveTo (RC. Left + 10, (RC. Bottom + RC. Top)/2 );
DC. lineto (RC. Right-10, (RC. Bottom + RC. Top)/2 );
DC. SelectObject (oldpen );

Getdlgitem (idc_fill_static)-> getwindowrect (RC );
Screentoclient (RC );
Cbrush writebrush;
If (m_filltype = 6)
{
Writebrush. createsolidbrush (m_fillcolor );
} Else
{
Writebrush. createhatchbrush (m_filltype, m_fillcolor );
}
Crect clientrect;
Clientrect. Left = RC. Left + 10;
Clientrect. Right = RC. Right-10;
Clientrect. Top = RC. Top + 10;
Clientrect. Bottom = RC. Bottom-10;
DC. fillrect (clientrect, & writebrush );

This process is correct, but when I draw a line, the line is overwritten by a control and cannot be displayed. Later I removed the control, but I don't know why it is overwritten?

The following method uses the DC of the control to draw lines on the control. However, when the mode dialog box is displayed in another pop-up mode, the dialog box cannot be displayed due to re-painting!

Explanation: cpaintdc is used to redraw the Drawing Output when the message (wm_paint) is returned in the window. Cpaintdc calls beginpaint () in the constructor to obtain the device context, and CALLS endpaint () in the destructor to release the device context. In addition to releasing the device context, endpaint () is also responsible for clearing the wm_paint message from the message queue. Therefore, you must use cpaintdc when processing the window re-painting. Otherwise, the wm_paint message cannot be cleared from the message queue and will cause constant window re-painting. Cpaintdc can only be used in wm_paint message processing.

2) implementation method:

// Cpaintdc (this );

CDC * PDC = m_lineedit.getdc ();
Crect RC;
M_lineedit.getrect (& rc );

Cpen pen (m_linetype, m_linewidth, m_linecolor );
Cpen * oldpen = PDC-> SelectObject (& pen );

PDC-> moveTo (RC. Left + 5, RC. Bottom + RC. Top + 20 );
PDC-> lineto (RC. Right-5, RC. Bottom + RC. Top + 20 );
PDC-> SelectObject (oldpen );
M_lineedit.releasedc (PDC );

Updatewindow () is used for force re-painting ();

Invalidate and updatewindow are different: invalidate refreshes the customer zone, and updatewindow refreshes the window elements.

 

//// Other comparisons collected on the Internet

Invalidate () and updatewindow ()

Void invalidate (bool berase = true );
This function is used to invalidate the entire window client area. If the customer area of the window is invalid, it indicates that re-painting is required. For example, if a window that is covered by other windows is changed to a front-end window, the originally covered window is invalid and needs to be re-painted. In this case, Windows will place the wm_paint message in the message queue of the application. MFC provides the message processing function onpaint of wm_paint for the window class. onpaint is responsible for repainting the window. There are some exceptions to the View class. The ondraw function is called in the onpaint function of the View class, and the actual re-painting is completed by ondraw. If the berase parameter is true, the background in the repainting area is erased. Otherwise, the background remains unchanged.

It differs from updatewindow () in the following ways:

Updatewindow () is used to re-paint the window immediately. After the invalidate and other functions are called, the window will not be re-painted immediately. This is because the priority of the wm_paint message is very low. It must be processed after other messages in the message queue are sent. You can call the updatewindow function to send wm_paint directly to the target window, causing the window to be re-painted immediately.

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.