The code below sends WM_CHANGEUISTATE to the window procedure itself with arguments:
LOWORD (wParam) = UIS_CLEAR
HIWORD (wParam) = UISF_HIDEACCEL
lParam = 0x00000000
when the client window pane left clicked.
According to this blog post by Raymond Chen , this should do a mnemonic in the system menu, which will be displayed when the menu is accessed with the mouse. The following paragraph has been extracted from this article:
Deleting a flag shows the corresponding indicator. For example, if you have UIS_CLEAR for UISF_HIDEFOCUS, this means that you want to show focus indicators.
In my case, I have UIS_CLEAR for UISF_HIDEACCEL, which means that I want to show menu accelerators.
If you run the code below and left-click on the client area of the application, you must make the accelerators visible in the System menu, even if this menu is accessible with the mouse. But this does not happen, i.e. If you activate the system menu by left-clicking on the window icon or by right-clicking on the window title bar, mnemonics in the system menu will not be displayed. What am I missing?
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR pszCmdLine, int nCmdShow)
{
WNDCLASSEX wndclassx;
wchar_t szAppName[] = L"WM_CHANGEUISTATE";
wndclassx.cbSize = sizeof(WNDCLASSEX);
wndclassx.style = CS_HREDRAW | CS_VREDRAW;
wndclassx.lpfnWndProc = WndProc;
wndclassx.cbClsExtra = 0;
wndclassx.cbWndExtra = 0;
wndclassx.hInstance = hInstance;
wndclassx.hIcon = 0;
wndclassx.hCursor = LoadCursor(0, IDC_ARROW);
wndclassx.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wndclassx.lpszClassName = szAppName;
wndclassx.lpszMenuName = nullptr;
wndclassx.hIconSm = 0;
if (!RegisterClassEx(&wndclassx)) return 0;
HWND hWnd = CreateWindow(szAppName, szAppName, WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, hInstance, 0);
ShowWindow(hWnd, SW_MAXIMIZE);
UpdateWindow(hWnd);
MSG msg;
while (GetMessage(&msg, 0, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_LBUTTONUP:
{
BOOL b;
SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &b, 0);
if( !b ) SendMessage(hwnd, WM_CHANGEUISTATE, MAKEWPARAM(UIS_CLEAR, UISF_HIDEACCEL), NULL);
}
break;
case WM_CHANGEUISTATE:
return DefWindowProc(hwnd, message, wParam, lParam);
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, message, wParam, lParam);
}
return 0;
}