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.