Link to home
Start Free TrialLog in
Avatar of holz
holz

asked on

Accelerators for another window

Hi,

I've got an MFC app with MDI interface, keyboard accelerators an some (small) floating windows.

The problem is: Whenever a floating (=modeless) window is active (and thus the MDI document inactive) the keyboard accelerators won't work.

I'd like to change that, but don't know how. Moreover, keyboard shortcuts from the floating window should still work. Only when the user presses a key that the floating window can't handle, the document window should be informed (probaly by receiving a WM_COMMAND).

The floating window has the HWND of the current topmost document windows. But how do I catch and relay the message?

Thanks,

Thomas
Avatar of BogdyPtr
BogdyPtr

Override your floating window OnCommand fnc to pass the accelerator messages that the floating window does not treat to the view via SendMessage or PostMessage.
ASKER CERTIFIED SOLUTION
Avatar of GlennDean
GlennDean

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oops! Ignore the code below my name
Avatar of holz

ASKER

Hello Glen,

thanks, that worked (and was easier than expected). ;)

Just one comment: I didn't use "particular spots", but just overrode the PreTranslateMessage function of the window and inserted the TranslateAccelerator call.

Greetings,

Thomas
Glad it worked!  My code snippet was required because we had message handlers that would execute for hours (no kidding).  So, at strategic spots, we called the function ClearTheMsgQueue.  But, without the TranslateAccelerator call we noticed when the user clicked "Alt+S" nothing happened.  Here's the weird thing - if no message handler was executing when they clicked "Alt+S" then the code for "Alt+S" did execute.  
  Anyway, you might want to test your code under the two situations I described above.  Namely, does the accelerator work when a message handler is currently executing and when there isn't a message handler executing.
   
   Glenn