From: amitmane82 on
Hi All,

I have one MDI application. There is menu option on MDI application to
launch popup window. I successfully written the code to create pop-up
window on menu click.

This pop-up window have it's own menu-bar. This menu have options like
File->New, File->Open. I have assigned short cut keys CTRL+N, CTRL+O
to these options respectively.

But when I launch pop-up window and enter CTRL key (CTRL+N), at that
time focus goes back to parent window as soon as I enter CTRL key and
pop-up window didn't receive any short-cut key combination. CTRL+N
then opens menu for parent window.

Would any one solve this problem?? I want to support shortcut keys for
menu bar of popup window.

Thanks in advance.

Thanks and regards,
Amit
From: Joseph M. Newcomer on
See below...
On Mon, 31 May 2010 06:29:17 -0700 (PDT), "amitmane82(a)gmail.com" <amitmane82(a)gmail.com>
wrote:

>Hi All,
>
>I have one MDI application. There is menu option on MDI application to
>launch popup window. I successfully written the code to create pop-up
>window on menu click.
>
>This pop-up window have it's own menu-bar. This menu have options like
>File->New, File->Open. I have assigned short cut keys CTRL+N, CTRL+O
>to these options respectively.
>
>But when I launch pop-up window and enter CTRL key (CTRL+N), at that
>time focus goes back to parent window as soon as I enter CTRL key and
>pop-up window didn't receive any short-cut key combination. CTRL+N
>then opens menu for parent window.
****
This is because Ctrl+N is mapped to a function in the parent window, and the way things
route, that will get preference. Generally, it is a Really Bad Idea to use shortcuts on
menus in child windows, because of all the effort you have to go through to make them
work. It is not an easy problem to solve.

Note first that the CTRL+N is completely and utterly irrelevant to the problem; what is
key is the ID it maps to. You seem to have given the text of the menu, which is
completely and utterly irrelevant, and the shortcut key, which is mostly irrelevant, and
failed to specify what the menu IDs were, which is critical, or the accelerator tables,
which is also crtitical.

Note also that the only "popup" window that you can have in an MDI application is
typically a dialog, and that's yet another can of worms; if you meant an MDI child window,
that's different, and if you were creating a window by some means outside the MDI
framework, that's yet a DIFFERENT problem, and by saying "popup window" you leave us
confused as to what you really did.

You said nothing about accelerator tables and their relationship to any of this.

Therefore, anything necessary to explain what has been going on has been omitted from your
description.
****
>
>Would any one solve this problem?? I want to support shortcut keys for
>menu bar of popup window.
****
Since I have no clue as to what you mean by a "popup window" no answer is possible.
joe
*****
>
>Thanks in advance.
>
>Thanks and regards,
>Amit
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: amitmane82 on
Hi Joseph,

Thanks for your inputs.

I have class CDesigner which is inherited from CWnd. I have object of
this class named m_Designer.
Using m_Designer object I create window using method
m_Designer.CreateEx(.......). This method have parameter DWORD
dwStyle. Here I set the value WS_POPUPWINDOW.

This is what I mean by POPUP window. POPUP window is similar to child
window but child window don't have menu but POPUP window can have
menu.

Now only problem I have is that when I launch the POPUP window and
press the CTRL key at that time POPUP window gets deactivated and it's
parent window becomes active. So please suggest me any solution for
this problem.
From: Joseph M. Newcomer on
See below...
On Tue, 1 Jun 2010 05:52:35 -0700 (PDT), "amitmane82(a)gmail.com" <amitmane82(a)gmail.com>
wrote:

>Hi Joseph,
>
>Thanks for your inputs.
>
>I have class CDesigner which is inherited from CWnd. I have object of
>this class named m_Designer.
>Using m_Designer object I create window using method
>m_Designer.CreateEx(.......). This method have parameter DWORD
>dwStyle. Here I set the value WS_POPUPWINDOW.
****
It would be useful to show the actual code.

Now, it starts getting weird, because this window is NOT in the MFC message-routing
mechanism and therefore the message from an accelerator will never arrive at it. A
WM_COMMAND message is routed to the current view, the current document, the main frame,
etc. in a canonical order (these are just a few of the CCmdTarget elements in the routing,
you need to read the full details about command routing in the MSDN), but windows created
outside this framework, as your window is, are never part of that routing, so the message
will never get there. I'm not sure I'd even try this trick, because it would require a
lot of research and experimentation to figure out how to get the messages to route the way
I want, but overall, you should assume that the message will not get routed to your window
without a LOT of effort.

One simple way around this is to put a handler in the mainframe, and if the popup window
is available, simply calling a method of the popup class from a suitable handler in the
mainframe. Otherwise it starts getting messy.
joe
****
>
>This is what I mean by POPUP window. POPUP window is similar to child
>window but child window don't have menu but POPUP window can have
>menu.
****
Key here is understanding how menus, accelerator tables, and MFC WM_COMMAND-routing work.
And figuring out how to extend this beyond the framework is probably going to be a lot of
work.
****
>
>Now only problem I have is that when I launch the POPUP window and
>press the CTRL key at that time POPUP window gets deactivated and it's
>parent window becomes active. So please suggest me any solution for
>this problem.
****
Probably not surprising. that the CTRL key does things; for example, you probably have the
focus set to the wrong window. Once you buy into CWnd as your base class, you have a LOT
of work to do to handle simple things like focus setting, which are normally handled by
the MFC framework.
joe
****
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm