Solve the overlap problem of transparent static controls

Source: Internet
Author: User

 

  1. Hbrush cstadus: onctlcolor (CDC * PDC, cwnd * pwnd, uint nctlcolor)
  2. {
  3. Hbrush HBr = cdialog: onctlcolor (PDC, pwnd, nctlcolor );
  4. // Todo: change any attributes of the DC here
  5. If (nctlcolor = ctlcolor_static)
  6. {
  7. PDC-> settextcolor (RGB (0, 0, 0); // set it to the color of your background.
  8. PDC-> setbkmode (0); // transparent
  9. Return (hbrush): getstockobject (null_brush );
  10. }
  11. // Todo: return a different brush if the default is not desired
  12. Return HBr;
  13. }
Hbrush cstadus: onctlcolor (CDC * PDC, cwnd * pwnd, uint nctlcolor) {hbrush HBr = cdialog: onctlcolor (PDC, pwnd, nctlcolor); // todo: change any attributes of the DC hereif (nctlcolor = ctlcolor_static) {PDC-> settextcolor (RGB (0, 0, 0 )); // set the color of your background to PDC-> setbkmode (0); // transparent return (hbrush): getstockobject (null_brush);} // todo: return a different brush if the default is not desiredreturn HBr ;}

The above Code makes the static control transparent, but when the content of the static control is changed through setwindowtext (), it is found that the text is overlapped, the more calls, the more serious the overlap is, the more black it is. After studying for a long time, I finally found a solution

Method 1: redrawwindow ()
Add this function after the code of the control that needs to change the text, as shown below:

  1. Getdlgitem (idc_static)-> setwindowtext ("your string ");
  2. Getdlgitem (idc_static)-> getparent ()-> redrawwindow ();
Getdlgitem (idc_static)-> setwindowtext ("your string"); getdlgitem (idc_static)-> getparent ()-> redrawwindow ();

This method works well, but sometimes the window is refreshed too frequently with a flash, and the effect is not very good. Fortunately, we have some tips and can use partial refresh.
Method 2: Partial refresh
You can customize a function as follows: void yourdlg: refreshcontrol (uint uctlid)

  1. {
  2. Crect RC;
  3. Getdlgitem (uctlid)-> getwindowrect (& rc );
  4. Screentoclient (& rc );
  5. Invalidaterect (RC );
  6. }
Void yourdlg: refreshcontrol (uint uctlid) {crect RC; getdlgitem (uctlid)-> getwindowrect (& rc); screentoclient (& rc); invalidaterect (RC );}

Call this function every time you change the control content. This method is recommended.

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.