Jump to content
  • Advertisement
Sign in to follow this  
Iki

Program not gaining focus

This topic is 4909 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!