PRB: Inter-thread SetWindowText() Fails to Update Window Text

Last reviewed: September 29, 1995
Article ID: Q125687
The information in this article applies to:
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows 95 version 4.0
    

SYMPTOMS

Calling SetWindowText() to set a static control text from a thread other than the one that created the control fails to display the new text in Windows 95.

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, use one of these workarounds:

  • Send a WM_SETTEXT message directly to the window or control.

    -or-

  • 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.


Additional reference words: 4.00
KBCategory: kbui kbprb
KBSubcategory: UsrWndw


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: September 29, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.