Modeless dialogs and accelerators
-
06-01-2021 - |
Pregunta
I want to perform some action when the user presses CTRL+S
inside a modeless dialog.
Accelerators would be perfect for this, except that I don't have control over the thread's message loop (think plugin), so I can't call TranslateAccelerator
.
A nested message loop is not an option because the main application does a lot of processing in between calls to PeekMessage
.
- Is there some way I can 'force' the existing message loop to handle my accelerator?
- Is there any other way besides accelerators to catch
CTRL+S
?
I thought about using a Window hooks on WH_GETMESSAGE
, which gets called before returning from GetMessage
or PeekMessage
. But I'm not sure what would happen after I successfully called TranslateAcellerator
, I can't let the application know I handled it.
WH_MSGFILTER
would require the app to implement a call to CallMsgFilter
, which it doesn't from a quick glance with a debugger.
My last idea was subclassing the control which is what I'm trying to avoid. That would require some mechanism to signal the keypress event to the parent window, which I don't think is a great design. Also, if I add more controls I would have to subclass every single one.
Thanks for any hints.
Solución
This is a fairly infamous interop problem, it rears its ugly head also when using Winforms to implement UI in a native program. Microsoft's recommendation is a rough-and-tumble one: start your own thread to display the window so you can pump your own message loop. You'll need SetParent() to avoid Z-order problems. Scary stuff, do consider a modal dialog thrice before committing to this.
Otros consejos
Can you use WM_GETDLGCODE? http://msdn.microsoft.com/en-us/library/ms645425(v=vs.85).aspx