OSDN Git Service

apply prevent_multirun_patch for win - ticket #31234
authordis- <dis-@0568b783-4c39-0410-ac80-bf13821ea2a2>
Sat, 27 Apr 2013 14:44:45 +0000 (14:44 +0000)
committerdis- <dis-@0568b783-4c39-0410-ac80-bf13821ea2a2>
Sat, 27 Apr 2013 14:44:45 +0000 (14:44 +0000)
src/main-win.c

index 15d2e7e..835fe8e 100644 (file)
@@ -5339,6 +5339,19 @@ static void init_stuff(void)
        /* validate_dir(ANGBAND_DIR_XTRA_HELP); */
 }
 
+bool is_already_running()
+{
+       bool result = FALSE;
+       HANDLE hMutex;
+
+       hMutex = CreateMutex(NULL, TRUE, VERSION_NAME);
+       if (GetLastError() == ERROR_ALREADY_EXISTS)
+       {
+               result = TRUE;
+       }
+       return result;
+}
+
 
 int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
                       LPSTR lpCmdLine, int nCmdShow)
@@ -5354,6 +5367,17 @@ int FAR PASCAL WinMain(HINSTANCE hInst, HINSTANCE hPrevInst,
 
        /* Save globally */
        hInstance = hInst;
+       
+       
+       /* Prevent multiple run */
+       if (is_already_running())
+       {
+               MessageBox(NULL,
+                               _("ÊѶòÈÚÅܤϤ¹¤Ç¤Ëµ¯Æ°¤·¤Æ¤¤¤Þ¤¹¡£", "Hengband is already running."), 
+                               _("¥¨¥é¡¼¡ª", "Error") ,
+                               MB_ICONEXCLAMATION | MB_OK | MB_ICONSTOP);
+               return FALSE;
+       }
 
        /* Initialize */
        if (hPrevInst == NULL)