First phase of porting. pterm now compiles and runs under Linux+gtk.
[u/mdw/putty] / pageant.c
index d12e02b..71753c0 100644 (file)
--- a/pageant.c
+++ b/pageant.c
@@ -59,6 +59,22 @@ static char *putty_path;
 #define PUTTY_DEFAULT     "Default%20Settings"
 static int initial_menuitems_count;
 
+/*
+ * Print a modal (Really Bad) message box and perform a fatal exit.
+ */
+void modalfatalbox(char *fmt, ...)
+{
+    va_list ap;
+    char stuff[200];
+
+    va_start(ap, fmt);
+    vsprintf(stuff, fmt, ap);
+    va_end(ap);
+    MessageBox(main_hwnd, stuff, "Pageant Fatal Error",
+              MB_SYSTEMMODAL | MB_ICONERROR | MB_OK);
+    exit(1);
+}
+
 /* Un-munge session names out of the registry. */
 static void unmungestr(char *in, char *out, int outlen)
 {
@@ -607,7 +623,7 @@ static void add_keyfile(char *filename)
            agent_query(request, reqlen, &vresponse, &resplen);
            response = vresponse;
            if (resplen < 5 || response[4] != SSH_AGENT_SUCCESS)
-               MessageBox(NULL, "The already running Pageant"
+               MessageBox(NULL, "The already running Pageant "
                           "refused to add the key.", APPNAME,
                           MB_OK | MB_ICONERROR);
 
@@ -1596,14 +1612,17 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
                keylist = CreateDialog(instance, MAKEINTRESOURCE(211),
                                       NULL, KeyListProc);
                ShowWindow(keylist, SW_SHOWNORMAL);
-               /* 
-                * Sometimes the window comes up minimised / hidden
-                * for no obvious reason. Prevent this.
-                */
-               SetForegroundWindow(keylist);
-               SetWindowPos(keylist, HWND_TOP, 0, 0, 0, 0,
-                            SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
            }
+           /* 
+            * Sometimes the window comes up minimised / hidden for
+            * no obvious reason. Prevent this. This also brings it
+            * to the front if it's already present (the user
+            * selected View Keys because they wanted to _see_ the
+            * thing).
+            */
+           SetForegroundWindow(keylist);
+           SetWindowPos(keylist, HWND_TOP, 0, 0, 0, 0,
+                        SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
            break;
          case IDM_ADDKEY:
            if (passphrase_box) {
@@ -1997,8 +2016,11 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
      * Main message loop.
      */
     while (GetMessage(&msg, NULL, 0, 0) == 1) {
-       TranslateMessage(&msg);
-       DispatchMessage(&msg);
+       if (!(IsWindow(keylist) && IsDialogMessage(keylist, &msg)) &&
+           !(IsWindow(aboutbox) && IsDialogMessage(aboutbox, &msg))) {
+           TranslateMessage(&msg);
+           DispatchMessage(&msg);
+       }
     }
 
     /* Clean up the system tray icon */