Sign in to follow this  
Iki

Program not gaining focus

Recommended Posts

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)...

Share this post


Link to post
Share on other sites
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 :(

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this