Disabling the Mnemonic on a Disabled Static Text ControlLast reviewed: November 2, 1995Article ID: Q66946 |
The information in this article applies to:
SUMMARYDisabling 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 INFORMATIONWhen 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
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |