Program not gaining focus

Started by
4 comments, last by clockwise 18 years, 9 months ago
Here is my problem... Ive made a little menu program in c++, that consists of two seperate programs (I suppose I could condense them into one program but still :P). The first program is the menu, just displays a menu, closes if you click a link, or click off the program (checks it loses focus). The second program hooks the keyboard and detects when you press a key, at which point it will run the first program, making the menu pop up. However, when I press the key to bring up the menu the menu isn't gaining focus, and so if I choose not to click on the menu and click off, the menu isn't deactivated and stays on the screen (forcing me to click on the menu, and then off again)...
Advertisement
I'm a little sketchy on what it is you're trying to do but look up SetFocus and SetForegroundWindow in MSDN I think they might be what you need
Tried AllowSetForegroundWindow, SetForegroundWindow and SetFocus... None of em seem to be doing anything :( Maybe its because they don't have the focus to start with? Not sure im not great at winAPI... Writing it in CBuilder for ease, maybe its that buggering about and I should recode it all in VStudio? or maybe put both progs into one might work better.. dunno :(
putting both progs into one sounds best, is there some reason you wrote it differently? I've never used CBuilder, the problem might just lie within your code somewhere, but combining seems like the best solution and you can still have floating toolbars and menus.
Well there wasn't any particular reason I made it two programs... Just I was messing about making a menu... And then I was experimenting with keyboard hooking and things... Just kinda developed that way lol

But thanks for the info, I'll make them into one program and see if that solves my problem :)

Iki
No prob, I think you can still get the same functionality by making a window for the menu and another for the keyboard to hook into, then detect your key presses in the keyboard hooked window and use ShowWindow(hYourMenuWindowHandle, SW_HIDE) to make the menu disappear, and do the same in the menu's window proc. Then when you press it again, just call

ShowWindow(hYourMenuWindowHandle, SW_SHOW);
SetForegroundWindow(hYourMenuWindowHandle);
SetFocus(hYourMenuWindowHandle);

I'm no Win32 Ace either, but hope that helps, good luck. [grin]

This topic is closed to new replies.

Advertisement