This will diplay the text on the screen with a TRANSPARENT BG and A colored text, but what if i want to change the
text later, how do i do? should i use: SendMessage(); or: SetWindowText( ) If yes, how and if
no, then what then??? and how
case WM_PAINT:
dc = BeginPaint(hwnd, &Ps);
SetBkMode(dc, TRANSPARENT);
SetTextColor(dc, RGB(454,0,0));
TextOut(dc, 10, 200, L"SEE? ", 5);
EndPaint(hwnd, &Ps);
break;
If you want to draw the text associated with your window – this is what you should do:
TextOutwith the hard-coded string. Instead obtain it viaGetWindowText.WM_SETTEXTmessage. Upon receiving it – invalidate your window (or at least the area where the text is assumed to be drawn).Now some explanations about transparency and etc.
I assume your window has an associated background brush (i.e. its
WNDCLASShad non-zerohbrBackgroundmember upon class registration). If not – you’re painting a transparent text above a non-painted area, which may contain any junk.During the call to
BeginPaintyour window procedure receivesWM_ERASEBACKGROUND. Assuming you pass it to theDefWindowProc– the client area of your window will be filled by the background brush. So that every time you begin painting – the client are of your window will be filled by some brush. Then you draw your text transparently on the newly-filled background. So that no smearing should occur.Whenever you want to change something visual on your window – drawing extra things in-place is not enough. Because at any time your window may be requested by the OS to redraw itself. So that your window must be able to paint itself adequately upon receiving
WM_PAINT.A common practice is to invalidate your window (or a part of it, using
InvalidateRector similar function) upon some change. And then, when you receiveWM_PAINT– repaint your window.