PRB: Inter-thread SetWindowText() Fails to Update Window Text
Article ID: 125687
Article Last Modified on 7/11/2005
APPLIES TO
- Microsoft Platform Software Development Kit-January 2000 Edition, when used with:
- Microsoft Windows 98 Standard Edition
This article was previously published under Q125687
SYMPTOMS
Calling SetWindowText() to set a window's text from a thread other than the
one that created the window fails to display the new text.
CAUSE
When SetWindowText() is called from another thread, instead of sending a
WM_SETTEXT message to the appropriate window procedure, only
DefWindowProc() is called, so the edit and static controls do not paint the
control appropriately because the appropriate code is never executed, so
the text on the screen is never updated. In other words, calling
SetWindowText() updates the buffer internally, but the change is not
reflected on the screen.
RESOLUTION
One obvious workaround is to refrain from calling SetWindowText() from
another thread, if possible.
If design considerations don't allow doing this, do one of the following:
- Send a WM_SETTEXT message directly to the window or control.
- Call InvalidateRect() immediately after the SetWindowText(). This works
because DefWindowProc() updates the buffer where the text is stored.
STATUS
This inter-thread SetWindowText() behavior is by design in Windows version
3.x. It was maintained in Windows 95 for backward compatibility purposes.
Applications written for Windows version 3.x can expect their inter-thread
SetWindowText() calls to behave as they did in Windows version 3.x.
MORE INFORMATION
Calling SetWindowText() from another thread in Windows NT displays the
window text correctly, so it works differently from Windows 95.
Keywords: kbwndw kbprb KB125687