Advertisement

Window Instances

Started by August 16, 2000 10:02 PM
2 comments, last by atreyu 24 years, 3 months ago
A program I''m working on requires that it ONLY have one instance of itself running at a given time. That is, if I double click the program''s icon it starts. Then if I double click the icon again (or any number of times) it does nothing. Any one know how to do this? Funny, I can''t think of a good programming term that represents my question, otherwise I''d just run a search
I forgot to say. I''m using Win32, and my compiler is msvc++6.
--Thanks
Advertisement
I think what you''re asking is how to make your app only allow one instance and bring the instance already running to the foreground if the user tries to run another instance. If I''m correct, this code will take care of that--put it _before_ you create your app''s window:


HWND hwndTemp;


hwndTemp = FindWindow(WND_CLASS, NULL);
if(hwndTemp != NULL) // if we found another instance...
{
SetForegroundWindow(hwndTemp); // ...bring it up...
FlashWindow(hwndTemp, TRUE); // ...flash it...
SetFocus(hwndTemp); // ...give it the input focus...

return 0; // ...and let''s get the hell out of here.
}
Thanks alot merlin. That''s exactly what I was looking for and better.

This topic is closed to new replies.

Advertisement