Solution to text coverage when the static control background is transparent

Source: Internet
Author: User
Solution to text coverage when the static control background is transparent

(15:21:24)

Reprinted
It with transparent text coverage Category: VC

 

Hatemath

 

Introduction:

I haven't spent a long time on forum, but I have seen such problems in the VC area many times, and I often fail to discuss them:


After the static control is set to transparent and the text is changed, it will overwrite the previous text. How can this problem be solved?
Use PDC-> setbkmode (transparent );
After the control is set to transparent, the text of the control to be changed will overlap. If the control is not transparent, the text will not overlap. How can I change the text in transparent State?

I did not agree at first. I tried it in my spare time and found that the text does overlap. For example (to better illustrate the problem, I specially set the background and foreground ):

The reason is preliminarily explored. The conjecture should be static.The background of the widget is not refreshed in time.

The solution is force refresh.

Method 1: getdlgitem (idc_static)-> updatewindow ();

Invalid...
Method 2: getdlgitem (idc_static)-> redrawwindow ();

Invalid .......
Method 3: getdlgitem (idc_static)-> invalidate ();
Invalid .........

Method 4: Not yet? Tips

Setdlgitemtext (idc_static, ""); // use multiple spaces to overwrite the original text.

Setdlgitemtext (idc_static, "test ");

Depressed .......

Is it necessary to solve such a small problem in an advanced way?

This problem plagued me for several days and finally suddenly realized at WC: the static background is transparent, so the residual text should be painted in the static parent window. After epiphany, I sighed: I am so stupid.


The solution is as follows:
After setting new text (not before!) Refresh the parent window.

Void cteststaticdlg: ontimer (uint nidevent)

{

Cstring strtime;

Ctime time = ctime: getcurrenttime ();

Strtime = time. Format ("% Y % m month % d % H: % m: % s ");

 

Getdlgitem (idc_static)-> setwindowtext (strtime );

Getdlgitem (idc_static)-> getparent ()-> redrawwindow (); // these two sentences are just used.

Cdialog: ontimer (nidevent );

}

Compile and run, k.o.

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.