Disabling the Mnemonic on a Disabled Static Text Control

Last reviewed: November 2, 1995
Article ID: Q66946
The information in this article applies to:
  • Microsoft Windows Software Development Kit (SDK) versions 3.0 and 3.1
  • Microsoft Win32 Application Programming Interface (API) included with:

        - Microsoft Windows NT versions 3.5 and 3.51
        - Microsoft Windows 95 version 4.0
    

SUMMARY

Disabling a static text control that contains a mnemonic does not prevent the control from responding to that key. For more information on static text controls with mnemonics, query in this Knowledge Base on the word "mnemonic".

To keep a static text control from processing mnemonics, it must be subclassed. When the control is disabled, WM_GETTEXT messages must be intercepted and the subclass procedure should return an empty string in response to the message.

MORE INFORMATION

When a static text control with a mnemonic is disabled using EnableWindow(), it turns gray but it does not stop responding to the mnemonic. This can cause problems because Windows processes the mnemonic by setting the focus to the next nonstatic, enabled control.

It is necessary to resort to subclassing to prevent the static control from processing the mnemonic. The subclass procedure should process the WM_GETTEXT message as follows:

    ...
    // Windows asks the control, hChild, for its text.
    case WM_GETTEXT:
        if (!IsWindowEnabled(hChild))
            {
            *(LPSTR)(lParam) = 0;    // A null terminated empty string
            return 0L;
            }
        break;
    ....

When the ALT key is held down and a key is pressed, Windows scans the text of each control to see if the key corresponds to a mnemonic. A WM_GETTEXT message is sent to each control. Normally, the control processes this message by returning its text. By returning an empty string in response to this message, Windows does not find the mnemonic.

Because the mnemonic must work when the control is enabled, the IsWindowEnabled() function is used to determine the state of the control. If it is enabled, default processing occurs. Otherwise, the control is disabled and no text is returned, effectively disabling the mnemonic.


Additional reference words: 3.00 3.10 3.50 3.51 4.00 95
KBCategory: kbui
KBSubcategory: UsrCtl


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: November 2, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.