Roman Pompejus's suggestion: do sensible things with focus when the
[u/mdw/putty] / windlg.c
index 737305d..6b7314d 100644 (file)
--- a/windlg.c
+++ b/windlg.c
@@ -13,8 +13,6 @@
 static char **events = NULL;
 static int nevents = 0, negsize = 0;
 
-static HWND logbox = NULL, abtbox = NULL;
-
 static int readytogo;
 
 void force_normal(HWND hwnd)
@@ -56,7 +54,9 @@ static int CALLBACK LogProc (HWND hwnd, UINT msg,
       case WM_COMMAND:
        switch (LOWORD(wParam)) {
          case IDOK:
+         case IDCANCEL:
            logbox = NULL;
+            SetActiveWindow(GetParent(hwnd));
            DestroyWindow (hwnd);
            return 0;
           case IDN_COPY:
@@ -111,6 +111,7 @@ static int CALLBACK LogProc (HWND hwnd, UINT msg,
        return 0;
       case WM_CLOSE:
        logbox = NULL;
+        SetActiveWindow(GetParent(hwnd));
        DestroyWindow (hwnd);
        return 0;
     }
@@ -145,8 +146,8 @@ static int CALLBACK AboutProc (HWND hwnd, UINT msg,
       case WM_COMMAND:
        switch (LOWORD(wParam)) {
          case IDOK:
-           abtbox = NULL;
-           DestroyWindow (hwnd);
+          case IDCANCEL:
+            EndDialog(hwnd, TRUE);
            return 0;
          case IDA_LICENCE:
            EnableWindow(hwnd, 0);
@@ -158,8 +159,7 @@ static int CALLBACK AboutProc (HWND hwnd, UINT msg,
        }
        return 0;
       case WM_CLOSE:
-       abtbox = NULL;
-       DestroyWindow (hwnd);
+        EndDialog(hwnd, TRUE);
        return 0;
     }
     return 0;
@@ -1092,9 +1092,10 @@ static int GenericMainDlgProc (HWND hwnd, UINT msg,
         if (dlgtype == 0) {
             treeview_insert(&tvfaff, 1, "Telnet");
             treeview_insert(&tvfaff, 1, "Rlogin");
-            if (backends[3].backend != NULL)
+            if (backends[3].backend != NULL) {
                 treeview_insert(&tvfaff, 1, "SSH");
-            treeview_insert(&tvfaff, 2, "Tunnels");
+                treeview_insert(&tvfaff, 2, "Tunnels");
+            }
         }
 
         /*
@@ -1992,14 +1993,11 @@ void showeventlog (HWND hwnd) {
                               hwnd, LogProc);
        ShowWindow (logbox, SW_SHOWNORMAL);
     }
+    SetActiveWindow(logbox);
 }
 
 void showabout (HWND hwnd) {
-    if (!abtbox) {
-       abtbox = CreateDialog (hinst, MAKEINTRESOURCE(IDD_ABOUTBOX),
-                              hwnd, AboutProc);
-       ShowWindow (abtbox, SW_SHOWNORMAL);
-    }
+    DialogBox(hinst, MAKEINTRESOURCE(IDD_ABOUTBOX),hwnd, AboutProc);
 }
 
 void verify_ssh_host_key(char *host, int port, char *keytype,