Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Correctly updating UI state to hide keyboard accelerator underlines

6 views
Skip to first unread message

Ehsan Akhgari

unread,
Sep 27, 2008, 1:41:50 PM9/27/08
to
Hi all,

I'm trying to understand how to correctly implement the showing and
hiding of access keys for an application which does not use any native
Win32 controls. I've been following the docs at <http://
msdn.microsoft.com/en-us/library/ms646335(VS.
85).aspx#_win32_UI_State>. Here is what I've been doing:

On initialization, I call SystemParametersInfo with
SPI_GETKEYBOARDCUES in order to determine whether or not to show the
cues, which returns false (correct). After calling CreateWindowEx, I
send WM_QUERYUISTATE to the newly created window in order to determine
the initial UI state for the window. This call *always* returns 0, no
matter if the window has been invoked via a keyboard command or using
the mouse. I also handle WM_UPDATEUISTATE in the window proc like
this:

case WM_UPDATEUISTATE:
{
short action = LOWORD(wParam);
short state = HIWORD(wParam);
switch (action) {
case UIS_SET:
if (state & UISF_HIDEACCEL)
mShowAccelerators = PR_FALSE;
break;
case UIS_CLEAR:
if (state & UISF_HIDEACCEL)
mShowAccelerators = PR_TRUE;
break;
case UIS_INITIALIZE:
{
HWND parent = ::GetParent(mWnd);
if (parent)
::SendMessageW(parent, WM_CHANGEUISTATE, wParam, 0);
}
break;
}
Invalidate(PR_FALSE);
}
break;

But no matter which keys pressed (Alt, Tab, arrow keys), I never get
WM_UPDATEUISTATE, so the above code actually never executes. When
drawing, I use mShowAccelerators (which is always true in my case) to
determine whether to show the accelerators or not. This results the
application to always show the underlines for accelerators, which is
not desirable.

Can anyone shed some light on how these messages are supposed to work,
and what do I need to do in order to handle them properly, so that I
get the native-equivalent behavior?

Thanks!
Ehsan

0 new messages