When we use a non-system default color or picture in the window when the background, the above label and other controls are really affecting the beautiful
This issue, as long as the setting of the label background for Transparent can be resolved, the code is as follows:
C + + code?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
Hbrush Ctransparentctldlg::onctlcolor (cdc* PDC, cwnd* pWnd, UINT nctlcolor) {//Control background transparent processing begins----------------------- ------------------if (nctlcolor== ctlcolor_static)//If it is a static label {Pdc->setbkmode (TRANSPARENT) ; Set the background mode to transparent return (Hbrush) getstockobject (Null_brush); Returns an empty paint brush}//control background transparent processing end-----------------------------------------Hbrush HBR = Cdialog::onctlcolor (PDC, PWnd, nCtlColor); return HBR; } |
But then there is a problem, when we need to update the text above the label, will cause overlap, first look at the effect:
Setdlgitemtext (idc_static1,_t ("first text"));
Setdlgitemtext (idc_static1,_t ("second text"));
Workaround:Notifies the parent window to refresh after the text has been modified
C + + code?
1 2 3 4 5 6 7 8 9 10 11 12 13 |
void Ctransparentctldlg::onbnclickedbutton2 () {//2 times Modified label text Setdlgitemtext (idc_static1,_t ("first text")); Setdlgitemtext (idc_static1,_t ("second text")); Gets the rectangle position of the label CRect RC; GetDlgItem (IDC_STATIC1)->getwindowrect (&RC); Convert to relative coordinate screentoclient (&RC); Refreshes the specified area, noting that the 2nd parameter is true, that is, refreshing the background invalidaterect (&rc,true); } |
Final Result:
SOURCE Download:
http://blog.csdn.net/cometnet/article/details/8706086
If you feel that the button above is not working well, refer to another post
Self-drawing realizes semi-transparent crystal button