Sign in to follow this  

Win32 API: Given hInstance get hWnd

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

This topic is 3864 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.

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