Window Instances
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 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.
}
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.
}
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement