Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass through accelerator key while modeless dialog window up

We have a very large in-house MFC app. It has a main window with a menubar, and hundreds of unique subwindows (without menubars) that display on top of the main window (not all simultaneously). These subwindows are implemented as CDialogs but run modelessly (via CreateWindow, not DoModal). Their parent HWND is set to NULL.

We recently got a feature request--allow a particular menubar accelerator from the main window to work, even when one of the subwindows is the active window. It would make sense from a user perspective.

This could be faked pretty easily with an application-wide keyboard hook, watching for that exact keystroke, but I was wondering if there is a cleaner way?

like image 750
StilesCrisis Avatar asked Nov 09 '22 13:11

StilesCrisis


1 Answers

You can as well use RegisterHotKey() in your main window. That will have a side effect that the new hotkey will trigger even if pressed in a different application. You can work around that by comparing GetCurrentProcessId() with GetWindowThreadProcessId(GetForegroundWindow())

like image 194
Codeguard Avatar answered Nov 15 '22 04:11

Codeguard