Fix double-keystrokes by wrapping CreateDialog
authorowen <owen@cda61777-01e9-0310-a592-d414129be87e>
Mon, 16 Jun 2003 23:55:26 +0000 (23:55 +0000)
committerowen <owen@cda61777-01e9-0310-a592-d414129be87e>
Mon, 16 Jun 2003 23:55:26 +0000 (23:55 +0000)
git-svn-id: svn://svn.tartarus.org/sgt/putty@3267 cda61777-01e9-0310-a592-d414129be87e

windlg.c
winmisc.c
winstuff.h

index c9f96fe..277b2c0 100644 (file)
--- a/windlg.c
+++ b/windlg.c
@@ -471,7 +471,7 @@ static int CALLBACK GenericMainDlgProc(HWND hwnd, UINT msg,
         */
        ReleaseCapture();
        if (dp.ended)
-           EndDialog(hwnd, dp.endresult ? 1 : 0);
+           SaneEndDialog(hwnd, dp.endresult ? 1 : 0);
        break;
       case WM_NOTIFY:
        if (LOWORD(wParam) == IDCX_TREEVIEW &&
@@ -526,7 +526,7 @@ static int CALLBACK GenericMainDlgProc(HWND hwnd, UINT msg,
        if (GetWindowLong(hwnd, GWL_USERDATA) == 1) {
            ret = winctrl_handle_command(&dp, msg, wParam, lParam);
            if (dp.ended && GetCapture() != hwnd)
-               EndDialog(hwnd, dp.endresult ? 1 : 0);
+               SaneEndDialog(hwnd, dp.endresult ? 1 : 0);
        } else
            ret = 0;
        return ret;
@@ -544,7 +544,7 @@ static int CALLBACK GenericMainDlgProc(HWND hwnd, UINT msg,
             WinHelp(hwnd, help_path, HELP_QUIT, 0);
             requested_help = FALSE;
         }
-       EndDialog(hwnd, 0);
+       SaneEndDialog(hwnd, 0);
        return 0;
 
        /* Grrr Explorer will maximize Dialogs! */
@@ -611,7 +611,7 @@ int do_config(void)
 
     get_sesslist(&sesslist, TRUE);
     ret =
-       DialogBox(hinst, MAKEINTRESOURCE(IDD_MAINBOX), NULL,
+       SaneDialogBox(hinst, MAKEINTRESOURCE(IDD_MAINBOX), NULL,
                  GenericMainDlgProc);
     get_sesslist(&sesslist, FALSE);
 
@@ -643,8 +643,7 @@ int do_reconfig(HWND hwnd)
     dp.data = &cfg;
     dp.shortcuts['g'] = TRUE;         /* the treeview: `Cate&gory' */
 
-    ret =
-       DialogBox(hinst, MAKEINTRESOURCE(IDD_MAINBOX), NULL,
+    ret = SaneDialogBox(hinst, MAKEINTRESOURCE(IDD_MAINBOX), NULL,
                  GenericMainDlgProc);
 
     ctrl_free_box(ctrlbox);
index 2590bef..d3d372d 100644 (file)
--- a/winmisc.c
+++ b/winmisc.c
@@ -6,6 +6,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include "putty.h"
+#include "winstuff.h"
 
 void platform_get_x11_auth(char *display, int *proto,
                            unsigned char *data, int *datalen)
@@ -36,6 +37,31 @@ int filename_is_null(Filename fn)
     return !*fn.path;
 }
 
+int SaneDialogBox(HINSTANCE hinst,
+                 LPCTSTR tmpl,
+                 HWND hwndparent,
+                 DLGPROC lpDialogFunc)
+{
+    HWND boxhwnd;
+    MSG msg;
+    
+    boxhwnd = CreateDialog(hinst, tmpl, hwndparent, lpDialogFunc);
+    while (GetMessage(&msg, NULL, 0, 0)) {
+       if (!(boxinfo.flags & DF_END) && !IsDialogMessage(boxhwnd, &msg))
+           DispatchMessage(&msg);
+       if (boxinfo.flags & DF_END) break;
+    }
+    boxinfo.flags=0;
+    return boxinfo.result;
+}
+
+void SaneEndDialog(HWND hwnd, int ret)
+{
+    boxinfo.result = ret;
+    boxinfo.flags |= DF_END;
+    DestroyWindow(hwnd);
+}
+
 #ifdef DEBUG
 static FILE *debug_fp = NULL;
 static HANDLE debug_hdl = INVALID_HANDLE_VALUE;
index 33b604f..4bc90db 100644 (file)
@@ -23,6 +23,13 @@ struct FontSpec {
     int charset;
 };
 
+struct dlgboxinfo {
+    int result;
+    int flags;
+};
+
+#define DF_END 0x0001
+
 /*
  * Global variables. Most modules declare these `extern', but
  * window.c will do `#define PUTTY_DO_GLOBALS' before including this
@@ -64,6 +71,11 @@ typedef HDC Context;
 GLOBAL HWND logbox;
 
 /*
+ * Global structure to hold return values from the config box.
+ */
+GLOBAL struct dlgboxinfo boxinfo;
+
+/*
  * The all-important instance handle.
  */
 GLOBAL HINSTANCE hinst;
@@ -308,6 +320,17 @@ void modal_about_box(HWND hwnd);
 void show_help(HWND hwnd);
 
 /*
+ * Exports from winmisc.c.
+ */
+
+int SaneDialogBox(HINSTANCE hinst,
+                 LPCTSTR tmpl,
+                 HWND hwndparent,
+                 DLGPROC lpDialogFunc);
+
+void SaneEndDialog(HWND hwnd, int ret);
+
+/*
  * Exports from sizetip.c.
  */
 void UpdateSizeTip(HWND src, int cx, int cy);