1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

pageant.rc: make a header file of dialog/control ids.

I'm tired of remembering all those fiddly magic numbers and copying
them back and forth between the .rc file and the source code. I'm even
more tired of having to remember that in the long string of numbers
after a dialog item definition, the first one of them _isn't_ one of
the position and size coordinates. I've given them all symbolic names,
like they should have had all along.

I think I originally didn't bother because this was such a small GUI
compared to the much larger one in PuTTY proper. But it's growing!
This commit is contained in:
Simon Tatham 2021-04-04 09:27:47 +01:00
parent 44c084f33f
commit 0f61291f80
3 changed files with 107 additions and 62 deletions

31
windows/pageant-rc.h Executable file
View File

@ -0,0 +1,31 @@
/*
* Constant definitions for the Pageant resource file.
*/
#define IDI_MAINICON 200
#define IDI_TRAYICON 201
#define IDD_KEYLIST 211
#define IDD_LOAD_PASSPHRASE 210
#define IDD_ONDEMAND_PASSPHRASE 212
#define IDD_ABOUT 213
#define IDD_LICENCE 214
#define IDC_PASSPHRASE_STATIC1 100
#define IDC_PASSPHRASE_FINGERPRINT 101
#define IDC_PASSPHRASE_STATIC2 102
#define IDC_PASSPHRASE_EDITBOX 103
#define IDC_KEYLIST_LISTBOX 100
#define IDC_KEYLIST_ADDKEY 101
#define IDC_KEYLIST_ADDKEY_ENC 110
#define IDC_KEYLIST_REMOVE 102
#define IDC_KEYLIST_HELP 103
#define IDC_KEYLIST_FPTYPE_STATIC 104
#define IDC_KEYLIST_FPTYPE 105
#define IDC_ABOUT_LICENCE 101
#define IDC_ABOUT_WEBSITE 102
#define IDC_ABOUT_TEXTBOX 1000
#define IDC_LICENCE_TEXTBOX 1000

View File

@ -7,73 +7,81 @@
#define APPNAME "Pageant"
#define APPDESC "PuTTY SSH authentication agent"
#include "pageant-rc.h"
#include "winhelp.rc2"
200 ICON "pageant.ico"
201 ICON "pageants.ico"
IDI_MAINICON ICON "pageant.ico"
IDI_TRAYICON ICON "pageants.ico"
210 DIALOG DISCARDABLE 0, 0, 140, 60
IDD_LOAD_PASSPHRASE DIALOG DISCARDABLE 0, 0, 140, 60
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Pageant: Loading Encrypted Key"
FONT 8, "MS Shell Dlg"
BEGIN
CTEXT "Enter passphrase to load key", 100, 10, 6, 120, 8
CTEXT "", 101, 10, 16, 120, 8
EDITTEXT 102, 10, 26, 120, 12, ES_PASSWORD | ES_AUTOHSCROLL
CTEXT "Enter passphrase to load key", IDC_PASSPHRASE_STATIC1, 10, 6, 120, 8
CTEXT "", IDC_PASSPHRASE_FINGERPRINT, 10, 16, 120, 8
EDITTEXT IDC_PASSPHRASE_EDITBOX, 10, 26, 120, 12,
ES_PASSWORD | ES_AUTOHSCROLL
DEFPUSHBUTTON "O&K", IDOK, 20, 42, 40, 14
PUSHBUTTON "&Cancel", IDCANCEL, 80, 42, 40, 14
END
212 DIALOG DISCARDABLE 0, 0, 250, 70
IDD_ONDEMAND_PASSPHRASE DIALOG DISCARDABLE 0, 0, 250, 70
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Pageant: Decrypting Stored Key"
FONT 8, "MS Shell Dlg"
BEGIN
CTEXT "A client of Pageant wants to use the following encrypted key:", 100, 10, 6, 230, 8
CTEXT "", 101, 10, 16, 230, 8
CTEXT "If you intended this, enter the passphrase to decrypt the key.", 101, 10, 26, 230, 8
EDITTEXT 102, 10, 36, 230, 12, ES_PASSWORD | ES_AUTOHSCROLL
CTEXT "A client of Pageant wants to use the following encrypted key:",
IDC_PASSPHRASE_STATIC1, 10, 6, 230, 8
CTEXT "", IDC_PASSPHRASE_FINGERPRINT, 10, 16, 230, 8
CTEXT "If you intended this, enter the passphrase to decrypt the key.",
IDC_PASSPHRASE_STATIC2, 10, 26, 230, 8
EDITTEXT IDC_PASSPHRASE_EDITBOX, 10, 36, 230, 12,
ES_PASSWORD | ES_AUTOHSCROLL
DEFPUSHBUTTON "O&K", IDOK, 75, 52, 40, 14
PUSHBUTTON "&Cancel", IDCANCEL, 135, 52, 40, 14
END
211 DIALOG DISCARDABLE 0, 0, 450, 211
IDD_KEYLIST DIALOG DISCARDABLE 0, 0, 450, 211
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Pageant Key List"
FONT 8, "MS Shell Dlg"
BEGIN
LISTBOX 100, 10, 10, 420, 155,
LBS_EXTENDEDSEL | LBS_HASSTRINGS | LBS_USETABSTOPS | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "&Add Key", 101, 75, 187, 60, 14
PUSHBUTTON "Add Key (&encrypted)", 110, 150, 187, 100, 14
PUSHBUTTON "&Remove Key", 102, 315, 187, 60, 14
PUSHBUTTON "&Help", 103, 10, 187, 50, 14
PUSHBUTTON "&Add Key", IDC_KEYLIST_ADDKEY, 75, 187, 60, 14
PUSHBUTTON "Add Key (&encrypted)", IDC_KEYLIST_ADDKEY_ENC, 150, 187, 100, 14
PUSHBUTTON "&Remove Key", IDC_KEYLIST_REMOVE, 315, 187, 60, 14
PUSHBUTTON "&Help", IDC_KEYLIST_HELP, 10, 187, 50, 14
DEFPUSHBUTTON "&Close", IDOK, 390, 187, 50, 14
LTEXT "&Fingerprint type:", 104, 10, 172, 60, 8
COMBOBOX 105, 70, 170, 60, 12, CBS_DROPDOWNLIST
LTEXT "&Fingerprint type:", IDC_KEYLIST_FPTYPE_STATIC, 10, 172, 60, 8
COMBOBOX IDC_KEYLIST_FPTYPE, 70, 170, 60, 12, CBS_DROPDOWNLIST
END
/* Accelerators used: cl */
213 DIALOG DISCARDABLE 140, 40, 270, 136
IDD_ABOUT DIALOG DISCARDABLE 140, 40, 270, 136
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About Pageant"
FONT 8, "MS Shell Dlg"
BEGIN
DEFPUSHBUTTON "&Close", IDOK, 216, 118, 48, 14
PUSHBUTTON "View &Licence", 101, 6, 118, 70, 14
PUSHBUTTON "Visit &Web Site", 102, 140, 118, 70, 14
EDITTEXT 1000, 10, 6, 250, 110, ES_READONLY | ES_MULTILINE | ES_CENTER, WS_EX_STATICEDGE
PUSHBUTTON "View &Licence", IDC_ABOUT_LICENCE, 6, 118, 70, 14
PUSHBUTTON "Visit &Web Site", IDC_ABOUT_WEBSITE, 140, 118, 70, 14
EDITTEXT IDC_ABOUT_TEXTBOX, 10, 6, 250, 110,
ES_READONLY | ES_MULTILINE | ES_CENTER, WS_EX_STATICEDGE
END
/* No accelerators used */
214 DIALOG DISCARDABLE 50, 50, 326, 239
IDD_LICENCE DIALOG DISCARDABLE 50, 50, 326, 239
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "PuTTY Licence"
FONT 8, "MS Shell Dlg"
BEGIN
DEFPUSHBUTTON "OK", IDOK, 148, 219, 44, 14
EDITTEXT 1000, 10, 10, 306, 200, ES_READONLY | ES_MULTILINE | ES_LEFT, WS_EX_STATICEDGE
EDITTEXT IDC_LICENCE_TEXTBOX, 10, 10, 306, 200,
ES_READONLY | ES_MULTILINE | ES_LEFT, WS_EX_STATICEDGE
END
#include "version.rc2"

View File

@ -17,6 +17,7 @@
#include "wincapi.h"
#include "pageant.h"
#include "licence.h"
#include "pageant-rc.h"
#include <shellapi.h>
@ -28,9 +29,6 @@
#endif
#endif
#define IDI_MAINICON 200
#define IDI_TRAYICON 201
#define WM_SYSTRAY (WM_APP + 6)
#define WM_SYSTRAY2 (WM_APP + 7)
@ -113,7 +111,7 @@ static INT_PTR CALLBACK LicenceProc(HWND hwnd, UINT msg,
{
switch (msg) {
case WM_INITDIALOG:
SetDlgItemText(hwnd, 1000, LICENCE_TEXT("\r\n\r\n"));
SetDlgItemText(hwnd, IDC_LICENCE_TEXTBOX, LICENCE_TEXT("\r\n\r\n"));
return 1;
case WM_COMMAND:
switch (LOWORD(wParam)) {
@ -144,7 +142,7 @@ static INT_PTR CALLBACK AboutProc(HWND hwnd, UINT msg,
ver, buildinfo_text,
"\251 " SHORT_COPYRIGHT_DETAILS ". All rights reserved.");
sfree(buildinfo_text);
SetDlgItemText(hwnd, 1000, text);
SetDlgItemText(hwnd, IDC_ABOUT_TEXTBOX, text);
sfree(text);
return 1;
}
@ -155,13 +153,13 @@ static INT_PTR CALLBACK AboutProc(HWND hwnd, UINT msg,
aboutbox = NULL;
DestroyWindow(hwnd);
return 0;
case 101:
case IDC_ABOUT_LICENCE:
EnableWindow(hwnd, 0);
DialogBox(hinst, MAKEINTRESOURCE(214), hwnd, LicenceProc);
DialogBox(hinst, MAKEINTRESOURCE(IDD_LICENCE), hwnd, LicenceProc);
EnableWindow(hwnd, 1);
SetActiveWindow(hwnd);
return 0;
case 102:
case IDC_ABOUT_WEBSITE:
/* Load web browser */
ShellExecute(hwnd, "open",
"https://www.chiark.greenend.org.uk/~sgtatham/putty/",
@ -242,10 +240,10 @@ static INT_PTR CALLBACK PassphraseProc(HWND hwnd, UINT msg,
if (!p->modal)
SetActiveWindow(hwnd); /* this won't have happened automatically */
if (p->comment)
SetDlgItemText(hwnd, 101, p->comment);
SetDlgItemText(hwnd, IDC_PASSPHRASE_FINGERPRINT, p->comment);
burnstr(p->passphrase);
p->passphrase = dupstr("");
SetDlgItemText(hwnd, 102, p->passphrase);
SetDlgItemText(hwnd, IDC_PASSPHRASE_EDITBOX, p->passphrase);
return 0;
}
case WM_COMMAND:
@ -259,10 +257,11 @@ static INT_PTR CALLBACK PassphraseProc(HWND hwnd, UINT msg,
case IDCANCEL:
end_passphrase_dialog(hwnd, 0);
return 0;
case 102: /* edit box */
case IDC_PASSPHRASE_EDITBOX:
if ((HIWORD(wParam) == EN_CHANGE) && p->passphrase) {
burnstr(p->passphrase);
p->passphrase = GetDlgItemText_alloc(hwnd, 102);
p->passphrase = GetDlgItemText_alloc(
hwnd, IDC_PASSPHRASE_EDITBOX);
}
return 0;
}
@ -369,7 +368,8 @@ static void keylist_update_callback(
else if (ext_flags & LIST_EXTENDED_FLAG_HAS_ENCRYPTED_KEY_FILE)
strbuf_catf(listentry, "\t(re-encryptable)");
SendDlgItemMessage(keylist, 100, LB_ADDSTRING, 0, (LPARAM)listentry->s);
SendDlgItemMessage(keylist, IDC_KEYLIST_LISTBOX,
LB_ADDSTRING, 0, (LPARAM)listentry->s);
strbuf_free(listentry);
}
@ -379,14 +379,16 @@ static void keylist_update_callback(
void keylist_update(void)
{
if (keylist) {
SendDlgItemMessage(keylist, 100, LB_RESETCONTENT, 0, 0);
SendDlgItemMessage(keylist, IDC_KEYLIST_LISTBOX,
LB_RESETCONTENT, 0, 0);
char *errmsg;
int status = pageant_enum_keys(keylist_update_callback, NULL, &errmsg);
assert(status == PAGEANT_ACTION_OK);
assert(!errmsg);
SendDlgItemMessage(keylist, 100, LB_SETCURSEL, (WPARAM) - 1, 0);
SendDlgItemMessage(keylist, IDC_KEYLIST_LISTBOX,
LB_SETCURSEL, (WPARAM) - 1, 0);
}
}
@ -418,8 +420,9 @@ static void win_add_keyfile(Filename *filename, bool encrypted)
pps.dlgid = NULL;
pps.passphrase = NULL;
pps.comment = err;
dlgret = DialogBoxParam(hinst, MAKEINTRESOURCE(210),
NULL, PassphraseProc, (LPARAM) &pps);
dlgret = DialogBoxParam(
hinst, MAKEINTRESOURCE(IDD_LOAD_PASSPHRASE),
NULL, PassphraseProc, (LPARAM) &pps);
modal_passphrase_hwnd = NULL;
if (!dlgret) {
@ -533,7 +536,7 @@ static INT_PTR CALLBACK KeyListProc(HWND hwnd, UINT msg,
GetWindowLongPtr(hwnd, GWL_EXSTYLE) |
WS_EX_CONTEXTHELP);
else {
HWND item = GetDlgItem(hwnd, 103); /* the Help button */
HWND item = GetDlgItem(hwnd, IDC_KEYLIST_HELP);
if (item)
DestroyWindow(item);
}
@ -541,19 +544,20 @@ static INT_PTR CALLBACK KeyListProc(HWND hwnd, UINT msg,
keylist = hwnd;
{
static int tabs[] = { 35, 75, 300 };
SendDlgItemMessage(hwnd, 100, LB_SETTABSTOPS,
SendDlgItemMessage(hwnd, IDC_KEYLIST_LISTBOX, LB_SETTABSTOPS,
sizeof(tabs) / sizeof(*tabs),
(LPARAM) tabs);
}
int selection = 0;
for (size_t i = 0; i < lenof(fptypes); i++) {
SendDlgItemMessage(hwnd, 105, CB_ADDSTRING,
SendDlgItemMessage(hwnd, IDC_KEYLIST_FPTYPE, CB_ADDSTRING,
0, (LPARAM)fptypes[i].name);
if (fptype == fptypes[i].value)
selection = (int)i;
}
SendDlgItemMessage(hwnd, 105, CB_SETCURSEL, 0, selection);
SendDlgItemMessage(hwnd, IDC_KEYLIST_FPTYPE,
CB_SETCURSEL, 0, selection);
keylist_update();
return 0;
@ -565,8 +569,8 @@ static INT_PTR CALLBACK KeyListProc(HWND hwnd, UINT msg,
keylist = NULL;
DestroyWindow(hwnd);
return 0;
case 101: /* add key */
case 110: /* add key encrypted */
case IDC_KEYLIST_ADDKEY:
case IDC_KEYLIST_ADDKEY_ENC:
if (HIWORD(wParam) == BN_CLICKED ||
HIWORD(wParam) == BN_DOUBLECLICKED) {
if (modal_passphrase_hwnd) {
@ -574,10 +578,10 @@ static INT_PTR CALLBACK KeyListProc(HWND hwnd, UINT msg,
SetForegroundWindow(modal_passphrase_hwnd);
break;
}
prompt_add_keyfile(LOWORD(wParam) == 110);
prompt_add_keyfile(LOWORD(wParam) == IDC_KEYLIST_ADDKEY_ENC);
}
return 0;
case 102: /* remove key */
case IDC_KEYLIST_REMOVE:
if (HIWORD(wParam) == BN_CLICKED ||
HIWORD(wParam) == BN_DOUBLECLICKED) {
int i;
@ -588,8 +592,8 @@ static INT_PTR CALLBACK KeyListProc(HWND hwnd, UINT msg,
int itemNum;
/* get the number of items selected in the list */
int numSelected =
SendDlgItemMessage(hwnd, 100, LB_GETSELCOUNT, 0, 0);
int numSelected = SendDlgItemMessage(
hwnd, IDC_KEYLIST_LISTBOX, LB_GETSELCOUNT, 0, 0);
/* none selected? that was silly */
if (numSelected == 0) {
@ -599,8 +603,8 @@ static INT_PTR CALLBACK KeyListProc(HWND hwnd, UINT msg,
/* get item indices in an array */
selectedArray = snewn(numSelected, int);
SendDlgItemMessage(hwnd, 100, LB_GETSELITEMS,
numSelected, (WPARAM)selectedArray);
SendDlgItemMessage(hwnd, IDC_KEYLIST_LISTBOX, LB_GETSELITEMS,
numSelected, (WPARAM)selectedArray);
itemNum = numSelected - 1;
rCount = pageant_count_ssh1_keys();
@ -630,16 +634,16 @@ static INT_PTR CALLBACK KeyListProc(HWND hwnd, UINT msg,
keylist_update();
}
return 0;
case 103: /* help */
case IDC_KEYLIST_HELP:
if (HIWORD(wParam) == BN_CLICKED ||
HIWORD(wParam) == BN_DOUBLECLICKED) {
launch_help(hwnd, WINHELP_CTX_pageant_general);
}
return 0;
case 105: /* fingerprint type */
case IDC_KEYLIST_FPTYPE:
if (HIWORD(wParam) == CBN_SELCHANGE) {
int selection = SendDlgItemMessage(
hwnd, 105, CB_GETCURSEL, 0, 0);
hwnd, IDC_KEYLIST_FPTYPE, CB_GETCURSEL, 0, 0);
if (selection >= 0 && (size_t)selection < lenof(fptypes)) {
fptype = fptypes[selection].value;
keylist_update();
@ -652,9 +656,9 @@ static INT_PTR CALLBACK KeyListProc(HWND hwnd, UINT msg,
int id = ((LPHELPINFO)lParam)->iCtrlId;
const char *topic = NULL;
switch (id) {
case 100: topic = WINHELP_CTX_pageant_keylist; break;
case 101: topic = WINHELP_CTX_pageant_addkey; break;
case 102: topic = WINHELP_CTX_pageant_remkey; break;
case IDC_KEYLIST_LISTBOX: topic = WINHELP_CTX_pageant_keylist; break;
case IDC_KEYLIST_ADDKEY: topic = WINHELP_CTX_pageant_addkey; break;
case IDC_KEYLIST_REMOVE: topic = WINHELP_CTX_pageant_remkey; break;
}
if (topic) {
launch_help(hwnd, topic);
@ -846,7 +850,8 @@ static bool ask_passphrase_common(PageantClientDialogId *dlgid,
pps->comment = comment;
nonmodal_passphrase_hwnd = CreateDialogParam(
hinst, MAKEINTRESOURCE(212), NULL, PassphraseProc, (LPARAM)pps);
hinst, MAKEINTRESOURCE(IDD_ONDEMAND_PASSPHRASE),
NULL, PassphraseProc, (LPARAM)pps);
/*
* Try to put this passphrase prompt into the foreground.
@ -1060,7 +1065,8 @@ static void create_keylist_window(void)
if (keylist)
return;
keylist = CreateDialog(hinst, MAKEINTRESOURCE(211), NULL, KeyListProc);
keylist = CreateDialog(hinst, MAKEINTRESOURCE(IDD_KEYLIST),
NULL, KeyListProc);
ShowWindow(keylist, SW_SHOWNORMAL);
}
@ -1154,7 +1160,7 @@ static LRESULT CALLBACK TrayWndProc(HWND hwnd, UINT message,
break;
case IDM_ABOUT:
if (!aboutbox) {
aboutbox = CreateDialog(hinst, MAKEINTRESOURCE(213),
aboutbox = CreateDialog(hinst, MAKEINTRESOURCE(IDD_ABOUT),
NULL, AboutProc);
ShowWindow(aboutbox, SW_SHOWNORMAL);
/*