Fix a typo in r9214 that plausibly explains a resizing weirdness I had with
[u/mdw/putty] / windows / winpgen.c
index baaf3d9..550cdfc 100644 (file)
@@ -17,7 +17,7 @@
 #define ICON_BIG        1
 #endif
 
-#define WM_DONEKEY (WM_XUSER + 1)
+#define WM_DONEKEY (WM_APP + 1)
 
 #define DEFAULT_KEYSIZE 1024
 
@@ -800,16 +800,16 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
 
     switch (msg) {
       case WM_INITDIALOG:
-        if (help_path)
-            SetWindowLong(hwnd, GWL_EXSTYLE,
-                          GetWindowLong(hwnd, GWL_EXSTYLE) | WS_EX_CONTEXTHELP);
+        if (has_help())
+            SetWindowLongPtr(hwnd, GWL_EXSTYLE,
+                            GetWindowLongPtr(hwnd, GWL_EXSTYLE) |
+                            WS_EX_CONTEXTHELP);
         else {
             /*
              * If we add a Help button, this is where we destroy it
              * if the help file isn't present.
              */
         }
-        requested_help = FALSE;
        SendMessage(hwnd, WM_SETICON, (WPARAM) ICON_BIG,
                    (LPARAM) LoadIcon(hinst, MAKEINTRESOURCE(200)));
 
@@ -818,7 +818,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
        state->collecting_entropy = FALSE;
        state->entropy = NULL;
        state->key_exists = FALSE;
-       SetWindowLong(hwnd, GWL_USERDATA, (LONG) state);
+       SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR) state);
        {
            HMENU menu, menu1;
 
@@ -855,7 +855,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
 
            menu1 = CreateMenu();
            AppendMenu(menu1, MF_ENABLED, IDC_ABOUT, "&About");
-           if (help_path)
+           if (has_help())
                AppendMenu(menu1, MF_ENABLED, IDC_GIVEHELP, "&Help");
            AppendMenu(menu, MF_POPUP | MF_ENABLED, (UINT) menu1, "&Help");
 
@@ -943,7 +943,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
 
        return 1;
       case WM_MOUSEMOVE:
-       state = (struct MainDlgState *) GetWindowLong(hwnd, GWL_USERDATA);
+       state = (struct MainDlgState *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
        if (state->collecting_entropy &&
            state->entropy && state->entropy_got < state->entropy_required) {
            state->entropy[state->entropy_got++] = lParam;
@@ -994,7 +994,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
          case IDC_KEYSSH2DSA:
            {
                state = (struct MainDlgState *)
-                   GetWindowLong(hwnd, GWL_USERDATA);
+                   GetWindowLongPtr(hwnd, GWLP_USERDATA);
                if (!IsDlgButtonChecked(hwnd, LOWORD(wParam)))
                    CheckRadioButton(hwnd, IDC_KEYSSH1, IDC_KEYSSH2DSA,
                                     LOWORD(wParam));
@@ -1008,7 +1008,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
          case IDC_COMMENTEDIT:
            if (HIWORD(wParam) == EN_CHANGE) {
                state = (struct MainDlgState *)
-                   GetWindowLong(hwnd, GWL_USERDATA);
+                   GetWindowLongPtr(hwnd, GWLP_USERDATA);
                if (state->key_exists) {
                    HWND editctl = GetDlgItem(hwnd, IDC_COMMENTEDIT);
                    int len = GetWindowTextLength(editctl);
@@ -1035,11 +1035,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
          case IDC_GIVEHELP:
             if (HIWORD(wParam) == BN_CLICKED ||
                 HIWORD(wParam) == BN_DOUBLECLICKED) {
-                if (help_path) {
-                    WinHelp(hwnd, help_path, HELP_COMMAND,
-                            (DWORD)"JI(`',`puttygen.general')");
-                    requested_help = TRUE;
-                }
+               launch_help(hwnd, WINHELP_CTX_puttygen_general);
             }
            return 0;
          case IDC_GENERATE:
@@ -1047,7 +1043,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
                 HIWORD(wParam) != BN_DOUBLECLICKED)
                break;
            state =
-               (struct MainDlgState *) GetWindowLong(hwnd, GWL_USERDATA);
+               (struct MainDlgState *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
            if (!state->generation_thread_exists) {
                BOOL ok;
                state->keysize = GetDlgItemInt(hwnd, IDC_BITS, &ok, FALSE);
@@ -1103,7 +1099,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
            if (HIWORD(wParam) != BN_CLICKED)
                break;
            state =
-               (struct MainDlgState *) GetWindowLong(hwnd, GWL_USERDATA);
+               (struct MainDlgState *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
            if (state->key_exists) {
                char filename[FILENAME_MAX];
                char passphrase[PASSPHRASE_MAXLEN];
@@ -1198,7 +1194,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
            if (HIWORD(wParam) != BN_CLICKED)
                break;
            state =
-               (struct MainDlgState *) GetWindowLong(hwnd, GWL_USERDATA);
+               (struct MainDlgState *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
            if (state->key_exists) {
                char filename[FILENAME_MAX];
                if (prompt_keyfile(hwnd, "Save public key as:",
@@ -1233,7 +1229,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
            if (HIWORD(wParam) != BN_CLICKED)
                break;
            state =
-               (struct MainDlgState *) GetWindowLong(hwnd, GWL_USERDATA);
+               (struct MainDlgState *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
            if (!state->generation_thread_exists) {
                char filename[FILENAME_MAX];
                if (prompt_keyfile(hwnd, "Load private key:",
@@ -1245,7 +1241,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
        }
        return 0;
       case WM_DONEKEY:
-       state = (struct MainDlgState *) GetWindowLong(hwnd, GWL_USERDATA);
+       state = (struct MainDlgState *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
        state->generation_thread_exists = FALSE;
        state->key_exists = TRUE;
        SendDlgItemMessage(hwnd, IDC_PROGRESS, PBM_SETRANGE, 0,
@@ -1330,7 +1326,7 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
        ui_set_state(hwnd, state, 2);
        break;
       case WM_HELP:
-        if (help_path) {
+        {
             int id = ((LPHELPINFO)lParam)->iCtrlId;
             char *topic = NULL;
             switch (id) {
@@ -1338,81 +1334,70 @@ static int CALLBACK MainDlgProc(HWND hwnd, UINT msg,
               case IDC_PROGRESS:
               case IDC_GENSTATIC:
               case IDC_GENERATE:
-                topic = "puttygen.generate"; break;
+                topic = WINHELP_CTX_puttygen_generate; break;
               case IDC_PKSTATIC:
               case IDC_KEYDISPLAY:
-                topic = "puttygen.pastekey"; break;
+                topic = WINHELP_CTX_puttygen_pastekey; break;
               case IDC_FPSTATIC:
               case IDC_FINGERPRINT:
-                topic = "puttygen.fingerprint"; break;
+                topic = WINHELP_CTX_puttygen_fingerprint; break;
               case IDC_COMMENTSTATIC:
               case IDC_COMMENTEDIT:
-                topic = "puttygen.comment"; break;
+                topic = WINHELP_CTX_puttygen_comment; break;
               case IDC_PASSPHRASE1STATIC:
               case IDC_PASSPHRASE1EDIT:
               case IDC_PASSPHRASE2STATIC:
               case IDC_PASSPHRASE2EDIT:
-                topic = "puttygen.passphrase"; break;
+                topic = WINHELP_CTX_puttygen_passphrase; break;
               case IDC_LOADSTATIC:
               case IDC_LOAD:
-                topic = "puttygen.load"; break;
+                topic = WINHELP_CTX_puttygen_load; break;
               case IDC_SAVESTATIC:
               case IDC_SAVE:
-                topic = "puttygen.savepriv"; break;
+                topic = WINHELP_CTX_puttygen_savepriv; break;
               case IDC_SAVEPUB:
-                topic = "puttygen.savepub"; break;
+                topic = WINHELP_CTX_puttygen_savepub; break;
               case IDC_TYPESTATIC:
               case IDC_KEYSSH1:
               case IDC_KEYSSH2RSA:
               case IDC_KEYSSH2DSA:
-                topic = "puttygen.keytype"; break;
+                topic = WINHELP_CTX_puttygen_keytype; break;
               case IDC_BITSSTATIC:
               case IDC_BITS:
-                topic = "puttygen.bits"; break;
+                topic = WINHELP_CTX_puttygen_bits; break;
               case IDC_IMPORT:
               case IDC_EXPORT_OPENSSH:
               case IDC_EXPORT_SSHCOM:
-                topic = "puttygen.conversions"; break;
+                topic = WINHELP_CTX_puttygen_conversions; break;
             }
             if (topic) {
-               char *cmd = dupprintf("JI(`',`%s')", topic);
-                WinHelp(hwnd, help_path, HELP_COMMAND, (DWORD)cmd);
-               sfree(cmd);
-                requested_help = TRUE;
+                launch_help(hwnd, topic);
             } else {
                 MessageBeep(0);
             }
         }
         break;
       case WM_CLOSE:
-       state = (struct MainDlgState *) GetWindowLong(hwnd, GWL_USERDATA);
+       state = (struct MainDlgState *) GetWindowLongPtr(hwnd, GWLP_USERDATA);
        sfree(state);
-        if (requested_help) {
-            WinHelp(hwnd, help_path, HELP_QUIT, 0);
-            requested_help = FALSE;
-        }
+       quit_help(hwnd);
        EndDialog(hwnd, 1);
        return 0;
     }
     return 0;
 }
 
-void cleanup_exit(int code) { exit(code); }
+void cleanup_exit(int code)
+{
+    shutdown_help();
+    exit(code);
+}
 
 int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
 {
     int argc;
     char **argv;
-
-    split_into_argv(cmdline, &argc, &argv, NULL);
-
-    if (argc > 0) {
-       /*
-        * Assume the first argument to be a private key file, and
-        * attempt to load it.
-        */
-       cmdline_keyfile = argv[0];
-    }
+    int ret;
 
     InitCommonControls();
     hinst = inst;
@@ -1421,24 +1406,26 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
     /*
      * See if we can find our Help file.
      */
-    {
-        char b[2048], *p, *q, *r;
-        FILE *fp;
-        GetModuleFileName(NULL, b, sizeof(b) - 1);
-        r = b;
-        p = strrchr(b, '\\');
-        if (p && p >= r) r = p+1;
-        q = strrchr(b, ':');
-        if (q && q >= r) r = q+1;
-        strcpy(r, PUTTY_HELP_FILE);
-        if ( (fp = fopen(b, "r")) != NULL) {
-            help_path = dupstr(b);
-            fclose(fp);
-        } else
-            help_path = NULL;
+    init_help();
+
+    split_into_argv(cmdline, &argc, &argv, NULL);
+
+    if (argc > 0) {
+       if (!strcmp(argv[0], "-pgpfp")) {
+           pgp_fingerprints();
+           exit(1);
+       } else {
+           /*
+            * Assume the first argument to be a private key file, and
+            * attempt to load it.
+            */
+           cmdline_keyfile = argv[0];
+       }
     }
 
     random_ref();
-    return DialogBox(hinst, MAKEINTRESOURCE(201), NULL,
-                    MainDlgProc) != IDOK;
+    ret = DialogBox(hinst, MAKEINTRESOURCE(201), NULL, MainDlgProc) != IDOK;
+
+    cleanup_exit(ret);
+    return ret;                               /* just in case optimiser complains */
 }