Transparent STATIC text changing problem

Hello
I have this STATIC control displayed over a window that has an image as its background. When I initiate the control it displays a text. If I want to change the text inside a WM_TIMER message it is displayed over the initial text (it is not removed) I have tried UpdateWindow and InvalidateRect but id doesn't work.
This is my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
WM_CREATE:
    HWND control = CreateWindowEx(
                                 WS_EX_TRANSPARENT,
                                 L"STATIC",
                                 L"FirstText",
                                 WS_CHILD|WS_VISIBLE|ES_LEFT,
                                 0,
                                 0,
                                 200,
                                 20,
                                 hWnd,
                                 HMENU(LABEL1),
                                 Instance,
                                 NULL
                                 );
break;
case WM_TIMER:
    SetWindowText(GetDlgItem(hWnd, LABEL1), L"SecondText");
    KillTimer(hWnd, MYTIMER);
    // Here I tried UpdateWindow and InvalidateRect but no result
break;


So, the second text is drawn over the first one. It looks like the STATIC content is not updated after changing it. What could be going wrong? Thanks!
Last edited on


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
    case WM_CREATE:
        control = CreateWindowEx(
            WS_EX_TRANSPARENT,
            L"STATIC",
            L"FirstText",
            WS_CHILD|WS_VISIBLE|ES_LEFT,
            0,
            0,
            200,
            20,
            hWnd,
            HMENU(99),
            hInst,
            NULL
            );

    //Create a timer
      SetTimer(hWnd,23, 5000,NULL);  
        break;

    case WM_CTLCOLORSTATIC:
        
        if ( GetDlgItem(hWnd, 99) == (HWND)lParam)
        {
            SetBkMode( (HDC)wParam, TRANSPARENT);
             return (LRESULT) GetStockObject(HOLLOW_BRUSH);
       }
            break;

    case WM_TIMER:
        {
            SetWindowText(GetDlgItem(hWnd, 99), L"Second Text");
            KillTimer(hWnd, 23);
            
            
            RECT rect = {0,0, 200,20};
            InvalidateRect(hWnd, &rect, TRUE);
            UpdateWindow(hWnd);
        }
        break;

    case WM_PAINT:
    {
        hdc = BeginPaint(hWnd, &ps);
        //Load my test bitmap from resources
        HBITMAP hb = LoadBitmap(hInst, MAKEINTRESOURCE(IDB_BITMAP1));
        BITMAP bm;
        GetObject(hb, sizeof(BITMAP), &bm);
        HDC memDC= CreateCompatibleDC(hdc);
        SelectObject(memDC,hb); 
        
        
        // ========================
        //Put the bitmap on the main window to act as a backdrop
        BitBlt(hdc, 0,0, bm.bmWidth,bm.bmHeight,memDC,0,0, SRCCOPY);
        DeleteDC(memDC);

        EndPaint(hWnd, &ps);
    }
    break;


Ok - I hard coded some numbers in there for testing (like the window ID) - but it's just an example to show you.
Thanks man, it works now.
Topic archived. No new replies allowed.