Shortcut key in win32 programming

I'm trying to have my windows to handle keyboard shortcuts such as "F10" while I select a listview / textbox / etc... within the window. At first I tried WM_KEYUP in the message loop; however it only captures the event when I hit the key while selecting the window itself, not the controls within it. Then I tried the RegisterHotKey function and handles WM_HOTKEY in the loop. This time it works, but it only works for one instance of my project. If I open another instance it won't work on the 2nd instance. Are there any way to have it capture a keyboard input from whatever control within the window, but only have it localized within its own instance?

1st method
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
RegisterHotKey(window_hwnd<win_type>, 1, 0, VK_F10);
while (GetMessage(&Msg, NULL, 0, 0) > 0)
{
	if (NULL == hDlgCurrent || !IsDialogMessage(hDlgCurrent, &Msg)) {
		TranslateMessage(&Msg);
		DispatchMessage(&Msg);
	}
}

... within the message loop
case WM_HOTKEY:
{
	HWND focused_window = GetFocus();
	if (focused_window == control_list<IDC_MS_TABLE>->getCtrlHWND()) {
		PostMessage(hwnd, WM_COMMAND, (WPARAM)SHORTCUT_COMMAND, 0);
	}
	break;
}


2nd method
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
... within the message loop
case WM_KEYUP:
{
	switch (wParam)
	{
		case VK_F10:
		{
			HWND focused_window = GetFocus();
			if (focused_window == control_list<IDC_MS_TABLE>->getCtrlHWND()) {
				PostMessage(hwnd, WM_COMMAND, (WPARAM)SHORTCUT_COMMAND, 0);
			}
			break;
		}
	}
	break;
}

Last edited on
Topic archived. No new replies allowed.