1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-03-21 22:28:37 -05:00

Add context help to a couple of message boxes. Unfortunately the ones

I wanted to get to -- "software caused connection abort" and friends --
are going to be more involved (probably requiring some cross-platform
notion of help contexts), and these ones hardly seem worth the effort.
Still, I've done it now.

Side-effect: Pageant now uses the same `hinst' and `hwnd' globals as
everything else. Tested basic functionality.

[originally from svn r5417]
This commit is contained in:
Jacob Nevins 2005-03-01 01:16:57 +00:00
parent f538bd6d4c
commit a2b583f137
7 changed files with 55 additions and 40 deletions

View File

@ -130,9 +130,11 @@ Similarly, any error message starting with \q{Assertion failed} is a
bug in PuTTY. Please report it to us, and include the exact text bug in PuTTY. Please report it to us, and include the exact text
from the error message box. from the error message box.
\H{errors-key-wrong-format} \q{Unable to use this private key file}, \H{errors-cant-load-key} \q{Unable to use this private key file},
\q{Couldn't load private key}, \q{Key is of wrong type} \q{Couldn't load private key}, \q{Key is of wrong type}
\cfg{winhelp-topic}{errors.cantloadkey}
Various forms of this error are printed in the PuTTY window, or Various forms of this error are printed in the PuTTY window, or
written to the PuTTY Event Log (see \k{using-eventlog}) when trying written to the PuTTY Event Log (see \k{using-eventlog}) when trying
public-key authentication, or given by Pageant when trying to load a public-key authentication, or given by Pageant when trying to load a

View File

@ -516,6 +516,8 @@ use the \c{-load} option (described in \k{using-cmdline-load}).
\S{using-cleanup} \i\c{-cleanup} \S{using-cleanup} \i\c{-cleanup}
\cfg{winhelp-topic}{options.cleanup}
If invoked with the \c{-cleanup} option, rather than running as If invoked with the \c{-cleanup} option, rather than running as
normal, PuTTY will remove its \I{removing registry entries}registry normal, PuTTY will remove its \I{removing registry entries}registry
entries and \I{random seed file} from the local machine (after entries and \I{random seed file} from the local machine (after

View File

@ -299,6 +299,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
int guess_width, guess_height; int guess_width, guess_height;
hinst = inst; hinst = inst;
hwnd = NULL;
flags = FLAG_VERBOSE | FLAG_INTERACTIVE; flags = FLAG_VERBOSE | FLAG_INTERACTIVE;
sk_init(); sk_init();
@ -451,8 +452,8 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
"SESSIONS. Are you really sure you want\n" "SESSIONS. Are you really sure you want\n"
"to continue?", appname); "to continue?", appname);
s2 = dupprintf("%s Warning", appname); s2 = dupprintf("%s Warning", appname);
if (MessageBox(NULL, s1, s2, if (message_box(s1, s2, MB_YESNO | MB_ICONWARNING,
MB_YESNO | MB_ICONWARNING) == IDYES) { HELPCTXID(option_cleanup)) == IDYES) {
cleanup_all(); cleanup_all();
} }
sfree(s1); sfree(s1);
@ -597,8 +598,6 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
RegisterClass(&wndclass); RegisterClass(&wndclass);
} }
hwnd = NULL;
memset(&ucsdata, 0, sizeof(ucsdata)); memset(&ucsdata, 0, sizeof(ucsdata));
cfgtopalette(); cfgtopalette();

View File

@ -3,6 +3,7 @@
* the \cfg{winhelp-topic} directives in the Halibut source. * the \cfg{winhelp-topic} directives in the Halibut source.
*/ */
/* Maximum length for WINHELP_CTX_foo strings */
#define WINHELP_CTX_MAXLEN 80 #define WINHELP_CTX_MAXLEN 80
/* These are used in the cross-platform configuration dialog code. */ /* These are used in the cross-platform configuration dialog code. */
@ -137,3 +138,7 @@
#define WINHELP_CTXID_errors_hostkey_absent 1 #define WINHELP_CTXID_errors_hostkey_absent 1
#define WINHELP_CTX_errors_hostkey_changed "errors.hostkey.changed" #define WINHELP_CTX_errors_hostkey_changed "errors.hostkey.changed"
#define WINHELP_CTXID_errors_hostkey_changed 2 #define WINHELP_CTXID_errors_hostkey_changed 2
#define WINHELP_CTX_errors_cantloadkey "errors.cantloadkey"
#define WINHELP_CTXID_errors_cantloadkey 3
#define WINHELP_CTX_option_cleanup "options.cleanup"
#define WINHELP_CTXID_option_cleanup 4

View File

@ -633,8 +633,8 @@ void load_key_file(HWND hwnd, struct MainDlgState *state,
!import_possible(type)) { !import_possible(type)) {
char *msg = dupprintf("Couldn't load private key (%s)", char *msg = dupprintf("Couldn't load private key (%s)",
key_type_to_str(type)); key_type_to_str(type));
MessageBox(NULL, msg, message_box(msg, "PuTTYgen Error", MB_OK | MB_ICONERROR,
"PuTTYgen Error", MB_OK | MB_ICONERROR); HELPCTXID(errors_cantloadkey));
sfree(msg); sfree(msg);
return; return;
} }
@ -695,7 +695,8 @@ void load_key_file(HWND hwnd, struct MainDlgState *state,
sfree(comment); sfree(comment);
if (ret == 0) { if (ret == 0) {
char *msg = dupprintf("Couldn't load private key (%s)", errmsg); char *msg = dupprintf("Couldn't load private key (%s)", errmsg);
MessageBox(NULL, msg, "PuTTYgen Error", MB_OK | MB_ICONERROR); message_box(msg, "PuTTYgen Error", MB_OK | MB_ICONERROR,
HELPCTXID(errors_cantloadkey));
sfree(msg); sfree(msg);
} else if (ret == 1) { } else if (ret == 1) {
/* /*
@ -1415,6 +1416,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
InitCommonControls(); InitCommonControls();
hinst = inst; hinst = inst;
hwnd = NULL;
/* /*
* See if we can find our Help file. * See if we can find our Help file.

View File

@ -50,8 +50,6 @@
extern char ver[]; extern char ver[];
static HINSTANCE instance;
static HWND main_hwnd;
static HWND keylist; static HWND keylist;
static HWND aboutbox; static HWND aboutbox;
static HMENU systray_menu, session_menu; static HMENU systray_menu, session_menu;
@ -80,7 +78,7 @@ void modalfatalbox(char *fmt, ...)
va_start(ap, fmt); va_start(ap, fmt);
buf = dupvprintf(fmt, ap); buf = dupvprintf(fmt, ap);
va_end(ap); va_end(ap);
MessageBox(main_hwnd, buf, "Pageant Fatal Error", MessageBox(hwnd, buf, "Pageant Fatal Error",
MB_SYSTEMMODAL | MB_ICONERROR | MB_OK); MB_SYSTEMMODAL | MB_ICONERROR | MB_OK);
sfree(buf); sfree(buf);
exit(1); exit(1);
@ -142,7 +140,7 @@ static void *get_keylist2(int *length);
*/ */
int random_byte(void) int random_byte(void)
{ {
MessageBox(main_hwnd, "Internal Error", APPNAME, MB_OK | MB_ICONERROR); MessageBox(hwnd, "Internal Error", APPNAME, MB_OK | MB_ICONERROR);
exit(0); exit(0);
/* this line can't be reached but it placates MSVC's warnings :-) */ /* this line can't be reached but it placates MSVC's warnings :-) */
return 0; return 0;
@ -236,7 +234,7 @@ static int CALLBACK AboutProc(HWND hwnd, UINT msg,
return 0; return 0;
case 101: case 101:
EnableWindow(hwnd, 0); EnableWindow(hwnd, 0);
DialogBox(instance, MAKEINTRESOURCE(214), hwnd, LicenceProc); DialogBox(hinst, MAKEINTRESOURCE(214), hwnd, LicenceProc);
EnableWindow(hwnd, 1); EnableWindow(hwnd, 1);
SetActiveWindow(hwnd); SetActiveWindow(hwnd);
return 0; return 0;
@ -412,9 +410,11 @@ static void add_keyfile(Filename filename)
type = key_type(&filename); type = key_type(&filename);
if (type != SSH_KEYTYPE_SSH1 && type != SSH_KEYTYPE_SSH2) { if (type != SSH_KEYTYPE_SSH1 && type != SSH_KEYTYPE_SSH2) {
char msg[256]; char *msg = dupprintf("Couldn't load this key (%s)",
sprintf(msg, "Couldn't load this key (%s)", key_type_to_str(type)); key_type_to_str(type));
MessageBox(NULL, msg, APPNAME, MB_OK | MB_ICONERROR); message_box(msg, APPNAME, MB_OK | MB_ICONERROR,
HELPCTXID(errors_cantloadkey));
sfree(msg);
return; return;
} }
@ -430,7 +430,8 @@ static void add_keyfile(Filename filename)
if (type == SSH_KEYTYPE_SSH1) { if (type == SSH_KEYTYPE_SSH1) {
if (!rsakey_pubblob(&filename, &blob, &bloblen, &error)) { if (!rsakey_pubblob(&filename, &blob, &bloblen, &error)) {
char *msg = dupprintf("Couldn't load private key (%s)", error); char *msg = dupprintf("Couldn't load private key (%s)", error);
MessageBox(NULL, msg, APPNAME, MB_OK | MB_ICONERROR); message_box(msg, APPNAME, MB_OK | MB_ICONERROR,
HELPCTXID(errors_cantloadkey));
sfree(msg); sfree(msg);
return; return;
} }
@ -440,7 +441,8 @@ static void add_keyfile(Filename filename)
blob = ssh2_userkey_loadpub(&filename, NULL, &bloblen, &error); blob = ssh2_userkey_loadpub(&filename, NULL, &bloblen, &error);
if (!blob) { if (!blob) {
char *msg = dupprintf("Couldn't load private key (%s)", error); char *msg = dupprintf("Couldn't load private key (%s)", error);
MessageBox(NULL, msg, APPNAME, MB_OK | MB_ICONERROR); message_box(msg, APPNAME, MB_OK | MB_ICONERROR,
HELPCTXID(errors_cantloadkey));
sfree(msg); sfree(msg);
return; return;
} }
@ -541,7 +543,7 @@ static void add_keyfile(Filename filename)
} else { } else {
int dlgret; int dlgret;
original_pass = 1; original_pass = 1;
dlgret = DialogBoxParam(instance, MAKEINTRESOURCE(210), dlgret = DialogBoxParam(hinst, MAKEINTRESOURCE(210),
NULL, PassphraseProc, (LPARAM) & pps); NULL, PassphraseProc, (LPARAM) & pps);
passphrase_box = NULL; passphrase_box = NULL;
if (!dlgret) { if (!dlgret) {
@ -578,7 +580,8 @@ static void add_keyfile(Filename filename)
sfree(comment); sfree(comment);
if (ret == 0) { if (ret == 0) {
char *msg = dupprintf("Couldn't load private key (%s)", error); char *msg = dupprintf("Couldn't load private key (%s)", error);
MessageBox(NULL, msg, APPNAME, MB_OK | MB_ICONERROR); message_box(msg, APPNAME, MB_OK | MB_ICONERROR,
HELPCTXID(errors_cantloadkey));
sfree(msg); sfree(msg);
if (type == SSH_KEYTYPE_SSH1) if (type == SSH_KEYTYPE_SSH1)
sfree(rkey); sfree(rkey);
@ -1417,7 +1420,7 @@ static void prompt_add_keyfile(void)
if (!keypath) keypath = filereq_new(); if (!keypath) keypath = filereq_new();
memset(&of, 0, sizeof(of)); memset(&of, 0, sizeof(of));
of.hwndOwner = main_hwnd; of.hwndOwner = hwnd;
of.lpstrFilter = FILTER_KEY_FILES; of.lpstrFilter = FILTER_KEY_FILES;
of.lpstrCustomFilter = NULL; of.lpstrCustomFilter = NULL;
of.nFilterIndex = 1; of.nFilterIndex = 1;
@ -1581,7 +1584,7 @@ static int CALLBACK KeyListProc(HWND hwnd, UINT msg,
if (HIWORD(wParam) == BN_CLICKED || if (HIWORD(wParam) == BN_CLICKED ||
HIWORD(wParam) == BN_DOUBLECLICKED) { HIWORD(wParam) == BN_DOUBLECLICKED) {
if (help_path) { if (help_path) {
WinHelp(main_hwnd, help_path, HELP_COMMAND, WinHelp(hwnd, help_path, HELP_COMMAND,
(DWORD)"JI(`',`pageant.general')"); (DWORD)"JI(`',`pageant.general')");
requested_help = TRUE; requested_help = TRUE;
} }
@ -1600,7 +1603,7 @@ static int CALLBACK KeyListProc(HWND hwnd, UINT msg,
} }
if (topic) { if (topic) {
char *cmd = dupprintf("JI(`',`%s')", topic); char *cmd = dupprintf("JI(`',`%s')", topic);
WinHelp(main_hwnd, help_path, HELP_COMMAND, (DWORD)cmd); WinHelp(hwnd, help_path, HELP_COMMAND, (DWORD)cmd);
sfree(cmd); sfree(cmd);
requested_help = TRUE; requested_help = TRUE;
} else { } else {
@ -1633,7 +1636,7 @@ static BOOL AddTrayIcon(HWND hwnd)
tnid.uID = 1; /* unique within this systray use */ tnid.uID = 1; /* unique within this systray use */
tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP; tnid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
tnid.uCallbackMessage = WM_SYSTRAY; tnid.uCallbackMessage = WM_SYSTRAY;
tnid.hIcon = hicon = LoadIcon(instance, MAKEINTRESOURCE(201)); tnid.hIcon = hicon = LoadIcon(hinst, MAKEINTRESOURCE(201));
strcpy(tnid.szTip, "Pageant (PuTTY authentication agent)"); strcpy(tnid.szTip, "Pageant (PuTTY authentication agent)");
res = Shell_NotifyIcon(NIM_ADD, &tnid); res = Shell_NotifyIcon(NIM_ADD, &tnid);
@ -1758,7 +1761,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
break; break;
case IDM_VIEWKEYS: case IDM_VIEWKEYS:
if (!keylist) { if (!keylist) {
keylist = CreateDialog(instance, MAKEINTRESOURCE(211), keylist = CreateDialog(hinst, MAKEINTRESOURCE(211),
NULL, KeyListProc); NULL, KeyListProc);
ShowWindow(keylist, SW_SHOWNORMAL); ShowWindow(keylist, SW_SHOWNORMAL);
} }
@ -1783,7 +1786,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
break; break;
case IDM_ABOUT: case IDM_ABOUT:
if (!aboutbox) { if (!aboutbox) {
aboutbox = CreateDialog(instance, MAKEINTRESOURCE(213), aboutbox = CreateDialog(hinst, MAKEINTRESOURCE(213),
NULL, AboutProc); NULL, AboutProc);
ShowWindow(aboutbox, SW_SHOWNORMAL); ShowWindow(aboutbox, SW_SHOWNORMAL);
/* /*
@ -1797,7 +1800,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
break; break;
case IDM_HELP: case IDM_HELP:
if (help_path) { if (help_path) {
WinHelp(main_hwnd, help_path, HELP_COMMAND, WinHelp(hwnd, help_path, HELP_COMMAND,
(DWORD)"JI(`',`pageant.general')"); (DWORD)"JI(`',`pageant.general')");
requested_help = TRUE; requested_help = TRUE;
} }
@ -1828,7 +1831,7 @@ static LRESULT CALLBACK WndProc(HWND hwnd, UINT message,
break; break;
case WM_DESTROY: case WM_DESTROY:
if (requested_help) { if (requested_help) {
WinHelp(main_hwnd, help_path, HELP_QUIT, 0); WinHelp(hwnd, help_path, HELP_QUIT, 0);
requested_help = FALSE; requested_help = FALSE;
} }
PostQuitMessage(0); PostQuitMessage(0);
@ -1970,6 +1973,9 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
int argc, i; int argc, i;
char **argv, **argstart; char **argv, **argstart;
hinst = inst;
hwnd = NULL;
/* /*
* Determine whether we're an NT system (should have security * Determine whether we're an NT system (should have security
* APIs) or a non-NT system (don't do security). * APIs) or a non-NT system (don't do security).
@ -2008,8 +2014,6 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
} else } else
advapi = NULL; advapi = NULL;
instance = inst;
/* /*
* See if we can find our Help file. * See if we can find our Help file.
*/ */
@ -2074,15 +2078,15 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
RegisterClass(&wndclass); RegisterClass(&wndclass);
} }
main_hwnd = keylist = NULL; keylist = NULL;
main_hwnd = CreateWindow(APPNAME, APPNAME, hwnd = CreateWindow(APPNAME, APPNAME,
WS_OVERLAPPEDWINDOW | WS_VSCROLL, WS_OVERLAPPEDWINDOW | WS_VSCROLL,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
100, 100, NULL, NULL, inst, NULL); 100, 100, NULL, NULL, inst, NULL);
/* Set up a system tray icon */ /* Set up a system tray icon */
AddTrayIcon(main_hwnd); AddTrayIcon(hwnd);
/* Accelerators used: nsvkxa */ /* Accelerators used: nsvkxa */
systray_menu = CreatePopupMenu(); systray_menu = CreatePopupMenu();
@ -2107,7 +2111,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
/* Set the default menu item. */ /* Set the default menu item. */
SetMenuDefaultItem(systray_menu, IDM_VIEWKEYS, FALSE); SetMenuDefaultItem(systray_menu, IDM_VIEWKEYS, FALSE);
ShowWindow(main_hwnd, SW_HIDE); ShowWindow(hwnd, SW_HIDE);
/* /*
* Initialise storage for RSA keys. * Initialise storage for RSA keys.
@ -2194,7 +2198,7 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
NOTIFYICONDATA tnid; NOTIFYICONDATA tnid;
tnid.cbSize = sizeof(NOTIFYICONDATA); tnid.cbSize = sizeof(NOTIFYICONDATA);
tnid.hWnd = main_hwnd; tnid.hWnd = hwnd;
tnid.uID = 1; tnid.uID = 1;
Shell_NotifyIcon(NIM_DELETE, &tnid); Shell_NotifyIcon(NIM_DELETE, &tnid);

View File

@ -104,6 +104,8 @@ static VOID CALLBACK message_box_help_callback(LPHELPINFO lpHelpInfo)
} while (0) } while (0)
CHECK_CTX(errors_hostkey_absent); CHECK_CTX(errors_hostkey_absent);
CHECK_CTX(errors_hostkey_changed); CHECK_CTX(errors_hostkey_changed);
CHECK_CTX(errors_cantloadkey);
CHECK_CTX(option_cleanup);
#undef CHECK_CTX #undef CHECK_CTX
if (context) { if (context) {
/* We avoid using malloc, in case we're in a situation where /* We avoid using malloc, in case we're in a situation where
@ -125,8 +127,7 @@ int message_box(LPCTSTR text, LPCTSTR caption, DWORD style, DWORD helpctxid)
* callback function for the Help button. * callback function for the Help button.
*/ */
mbox.cbSize = sizeof(mbox); mbox.cbSize = sizeof(mbox);
/* FIXME: assumes global hwnd and hinst are always the Right Thing; /* Assumes the globals `hinst' and `hwnd' have sensible values. */
* are they? */
mbox.hInstance = hinst; mbox.hInstance = hinst;
mbox.hwndOwner = hwnd; mbox.hwndOwner = hwnd;
mbox.lpfnMsgBoxCallback = &message_box_help_callback; mbox.lpfnMsgBoxCallback = &message_box_help_callback;