I need simple solution, without using MFC,ATL,AFX etc. Just like you would include only windows.h . I'm now talkin开发者_如何学Gog 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.
Another theory...
Obviously you have some kind of parent window, once you create a child window.
- Create some public/internal static property of main window to identify currently opened window.
- Once user opens child window set that static property to the opened window (i would store pointer to the window)
- 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.
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:
- Enabled "KeyPreview"
- Implement "KeyPress" even in the windows that looses focus once "Alt" key is pressed
- Check if key = "Alt". If it is, cancel the KeyPress event.
精彩评论