Jump to content
  • Advertisement
Sign in to follow this  
AngleWyrm

Win32 API: Given hInstance get hWnd

This topic is 4077 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

Hi, WinMain provides a hPrevInstance that indicates a previous instance of my app is running. I want my current instance to switch focus to the previous insance, and then quit. Given that it is my app, is it possible to get a HWND for the previous instance's main window, and then ShowWindow()? Or is there a better way? -- Theyr ken onlee be wun.

Share this post


Link to post
Share on other sites
Advertisement
Actually, if you read the documentation of WinMain, you'd see, that the hPrevInstance parameter is always NULL. It was used in Windows 3.X versions, I think. But it is NULL in all versions of Windows since Windows 95...

Share this post


Link to post
Share on other sites
Wow, thanks. I'm gonna start calling it hUseless.

Or maybe just hDepreciated.

[Edited by - AngleWyrm on May 20, 2007 4:20:52 PM]

Share this post


Link to post
Share on other sites
Because it's your application you should know what the class name and window text for the main window are, thus enabling the use of FindWindow.

However, you can't count on hPrevInstance to indicate whether there is a previous instance of your program running. That is actually a vestige of Windows 3.

In my view, the best way to determine whether there is a previous instance is with a named mutex.

This topic has come up before, here and here.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!