views:

41

answers:

2

I need simple solution, without using MFC,ATL,AFX etc. Just like you would include only windows.h . I'm now talking about Windows solution.

My problem is that I want to be able set focus back on the view part of a window. My window for example consist of view part, title bar and menu bar. After you press alt, focus jumps to the menu bar for navigation. I need to be able to give that focus back to view part. I already asked on MSDN, but solution they provided isn't what I'm looking for because it uses MFC. MSDN tread.

If this can't be acomplished could you describe me why and provide some kind of solution? I'm looking for shortest solution, which won't affect whole app. Thanks.

A: 

Hello,

I did C++ windows stuff a while ago... work in C# mostly now. So, if something is off don't judge too hard.

The window should have "KeyPreview" property, if set to true all pressed keys will be registered with form first. The windows should have "KeyPress" event, once the even is implemented and "KeyPreview" is enabled the windows will be handling the press event before the application gets it.

Algo is as follows:

  1. Enabled "KeyPreview"
  2. Implement "KeyPress" even in the windows that looses focus once "Alt" key is pressed
  3. Check if key = "Alt". If it is, cancel the KeyPress event.
Alex
A: 

Another theory...

Obviously you have some kind of parent window, once you create a child window.

  1. Create some public/internal static property of main window to identify currently opened window.
  2. Once user opens child window set that static property to the opened window (i would store pointer to the window)
  3. When user presses alt, the menu will receive focus. You can use the "onFocus" event of the menu to check which form is current by checking the static property of main window. If the window is the one that should keep the focus, set the focus back. (you might need to code public/internal method in the child window to receive focus for certain control from different window)

Also, you might need to set the focus twice, first time to make the form active and the other to make specific control active.

Alex