OSDN Git Service

Simplify guimain.exe duplicate instance prevention.
authorKeith Marshall <keithmarshall@users.sourceforge.net>
Wed, 21 Aug 2013 15:46:07 +0000 (16:46 +0100)
committerKeith Marshall <keithmarshall@users.sourceforge.net>
Wed, 21 Aug 2013 15:46:07 +0000 (16:46 +0100)
ChangeLog
src/guimain.cpp

index 280fbf9..2f37bbf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2013-08-21  Keith Marshall  <keithmarshall@users.sourceforge.net>
+
+       Simplify guimain.exe duplicate instance prevention.
+
+       * src/guimain.cpp (WinMain): Delegate requisite checking to...
+       (WTK::RaiseAppWindow): ...this external toolkit function.
+
 2013-08-13  Keith Marshall  <keithmarshall@users.sourceforge.net>
 
        Install licence as standard setup component.
index 2b0e11a..f2c1fe3 100644 (file)
@@ -56,30 +56,11 @@ int APIENTRY WinMain
      * so first, we check to ensure that there is no other instance
      * already running...
      */
-    HWND AppWindow = FindWindow(
-       StringResource( Instance, ID_MAIN_WINDOW_CLASS ), NULL
-      );
-    if( (AppWindow != NULL) && IsWindow( AppWindow ) )
-    {
-      /* ...and when one is, we identify its active window...
-       */
-      HWND AppPopup = GetLastActivePopup( AppWindow );
-      if( IsWindow( AppPopup ) )
-       AppWindow = AppPopup;
-
-      /* ...bring it to the foreground...
-       */
-      SetForegroundWindow( AppWindow );
+    if( WTK::RaiseAppWindow( Instance, ID_MAIN_WINDOW_CLASS ) )
       /*
-       * ...restore it from minimised state, if necessary...
-       */
-      if( IsIconic( AppWindow ) )
-       ShowWindow( AppWindow, SW_RESTORE );
-
-      /* ...and defer execution to it.
+       * ...and when one is, we defer execution to it.
        */
       return EXIT_SUCCESS;
-    }
 
     /* There is no running instance of mingw-get; before we create one,
      * ensure we can acquire an exclusive lock for the XML catalogue.
@@ -92,7 +73,7 @@ int APIENTRY WinMain
        * instance of the mingw-get GUI application window.
        */
       AppWindowMaker MainWindow( Instance );
-      AppWindow = MainWindow.Create(
+      HWND AppWindow = MainWindow.Create(
          StringResource( Instance, ID_MAIN_WINDOW_CLASS ), MainWindowCaption
        );