Question

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;
Was it helpful?

Solution

If you want to draw the text associated with your window - this is what you should do:

  1. Don't call TextOut with the hard-coded string. Instead obtain it via GetWindowText.
  2. Add a hander to WM_SETTEXT message. 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 WNDCLASS had non-zero hbrBackground member 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 BeginPaint your window procedure receives WM_ERASEBACKGROUND. Assuming you pass it to the DefWindowProc - 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 InvalidateRect or similar function) upon some change. And then, when you receive WM_PAINT - repaint your window.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top