checkbox(&cp, "Close Window on E&xit", IDC0_CLOSEEXIT); checkbox(&cp, "&Warn on Close", IDC0_CLOSEWARN);
staticedit(&cp, "Keepalive inter&val (minutes)", IDC0_PINGSTATIC, IDC0_PINGEDIT, 25);
static int GenericMainDlgProc (HWND hwnd, UINT msg,			       WPARAM wParam, LPARAM lParam,			       int dlgtype) {    HWND hw, tabctl;    TC_ITEMHEADER tab;    OPENFILENAME of;    char filename[sizeof(cfg.keyfile)];    CHOOSEFONT cf;    LOGFONT lf;    char fontstatic[256];    int i;    switch (msg) {      case WM_INITDIALOG:	SetWindowLong(hwnd, GWL_USERDATA, 0);	/*	 * Centre the window.	 */	{			       /* centre the window */	    RECT rs, rd;	    hw = GetDesktopWindow();	    if (GetWindowRect (hw, &rs) && GetWindowRect (hwnd, &rd))		MoveWindow (hwnd, (rs.right + rs.left + rd.left - rd.right)/2,			    (rs.bottom + rs.top + rd.top - rd.bottom)/2,			    rd.right-rd.left, rd.bottom-rd.top, TRUE);	}	/*	 * Create the tab control.	 */        {            RECT r;	    WPARAM font;            r.left = 3; r.right = r.left + 174;            r.top = 3; r.bottom = r.top + 193;            MapDialogRect(hwnd, &r);            tabctl = CreateWindowEx(0, WC_TABCONTROL, "",                                    WS_CHILD | WS_VISIBLE |                                    WS_TABSTOP | TCS_MULTILINE,                                    r.left, r.top,                                    r.right-r.left, r.bottom-r.top,                                    hwnd, (HMENU)IDCX_TAB, hinst, NULL);	    font = SendMessage(hwnd, WM_GETFONT, 0, 0);	    SendMessage(tabctl, WM_SETFONT, font, MAKELPARAM(TRUE, 0));        }	/*	 * Create the various panelfuls of controls.	 */	i = 0;	/* The Connection panel. Accelerators used: [aco] dehlnprstwx */	{	    struct ctlpos cp;	    ctlposinit(&cp, hwnd, 6, 30);	    if (dlgtype == 0) {		multiedit(&cp,			  "Host &Name", IDC0_HOSTSTATIC, IDC0_HOST, 75,			  "&Port", IDC0_PORTSTATIC, IDC0_PORT, 25, NULL);		if (backends[2].backend == NULL) {		    /* this is PuTTYtel, so only two protocols available */		    radioline(&cp, "Protocol:", IDC0_PROTSTATIC, 3,			      "&Raw", IDC0_PROTRAW,			      "&Telnet", IDC0_PROTTELNET, NULL);		} else {		    radioline(&cp, "Protocol:", IDC0_PROTSTATIC, 3,			      "&Raw", IDC0_PROTRAW,			      "&Telnet", IDC0_PROTTELNET,#ifdef FWHACK			      "SS&H/hack",#else			      "SS&H",#endif			      IDC0_PROTSSH, NULL);		}		sesssaver(&cp, "Stor&ed Sessions",			  IDC0_SESSSTATIC, IDC0_SESSEDIT, IDC0_SESSLIST,			  "&Load", IDC0_SESSLOAD,			  "&Save", IDC0_SESSSAVE,			  "&Delete", IDC0_SESSDEL, NULL);	    }	    checkbox(&cp, "Close Window on E&xit", IDC0_CLOSEEXIT);	    checkbox(&cp, "&Warn on Close", IDC0_CLOSEWARN);	    tab.mask = TCIF_TEXT; tab.pszText = "Connection";	    TabCtrl_InsertItem (tabctl, i++, &tab);	}	/* The Keyboard panel. Accelerators used: [aco] 4?ehiklmnprsuvxy */	{	    struct ctlpos cp;	    ctlposinit(&cp, hwnd, 6, 30);	    radioline(&cp, "Action of Backspace:", IDC1_DELSTATIC, 2,		      "Control-&H", IDC1_DEL008,		      "Control-&? (127)", IDC1_DEL127, NULL);	    radioline(&cp, "Action of Home and End:", IDC1_HOMESTATIC, 2,		      "&Standard", IDC1_HOMETILDE,		      "&rxvt", IDC1_HOMERXVT, NULL);	    radioline(&cp, "Function key and keypad layout:", IDC1_FUNCSTATIC, 3,		      "&VT400", IDC1_FUNCTILDE,		      "&Linux", IDC1_FUNCLINUX,		      "&Xterm R6", IDC1_FUNCXTERM, NULL);	    radioline(&cp, "Initial state of cursor keys:", IDC1_CURSTATIC, 2,		      "&Normal", IDC1_CURNORMAL,		      "A&pplication", IDC1_CURAPPLIC, NULL);	    radioline(&cp, "Initial state of numeric keypad:", IDC1_KPSTATIC, 3,		      "Nor&mal", IDC1_KPNORMAL,		      "Appl&ication", IDC1_KPAPPLIC,		      "N&etHack", IDC1_KPNH, NULL);	    checkbox(&cp, "ALT-F&4 is special (closes window)", IDC1_ALTF4);	    checkbox(&cp, "ALT-Space is special (S&ystem menu)", IDC1_ALTSPACE);	    checkbox(&cp, "&Use local terminal line discipline", IDC1_LDISCTERM);	    checkbox(&cp, "Reset scrollback on &keypress", IDC1_SCROLLKEY);	    tab.mask = TCIF_TEXT; tab.pszText = "Keyboard";	    TabCtrl_InsertItem (tabctl, i++, &tab);	}        /* The Terminal panel. Accelerators used: [aco] dghlmnprsw */	{	    struct ctlpos cp;	    ctlposinit(&cp, hwnd, 6, 30);	    multiedit(&cp,		      "&Rows", IDC2_ROWSSTATIC, IDC2_ROWSEDIT, 33,		      "Colu&mns", IDC2_COLSSTATIC, IDC2_COLSEDIT, 33,		      "&Scrollback", IDC2_SAVESTATIC, IDC2_SAVEEDIT, 33,		      NULL);	    staticbtn(&cp, "", IDC2_FONTSTATIC, "C&hange...", IDC2_CHOOSEFONT);	    checkbox(&cp, "Auto &wrap mode initially on", IDC2_WRAPMODE);	    checkbox(&cp, "&DEC Origin Mode initially on", IDC2_DECOM);	    checkbox(&cp, "Implicit CR in every &LF", IDC2_LFHASCR);	    checkbox(&cp, "Bee&p enabled", IDC2_BEEP);	    checkbox(&cp, "Use Back&ground colour erase", IDC2_BCE);	    checkbox(&cp, "Enable bli&nking text", IDC2_BLINKTEXT);	    tab.mask = TCIF_TEXT; tab.pszText = "Terminal";	    TabCtrl_InsertItem (tabctl, i++, &tab);	}        /* The Window panel. Accelerators used: [aco] bikty */	{	    struct ctlpos cp;	    ctlposinit(&cp, hwnd, 6, 30);	    if (dlgtype == 0)		multiedit(&cp,			  "Initial window &title:", IDC3_WINTITLE,			  IDC3_WINEDIT, 100, NULL);	    checkbox(&cp, "Avoid ever using &icon title", IDC3_WINNAME);	    checkbox(&cp, "&Blinking cursor", IDC3_BLINKCUR);	    checkbox(&cp, "Displa&y scrollbar", IDC3_SCROLLBAR);	    checkbox(&cp, "Loc&k Window size", IDC3_LOCKSIZE);	    tab.mask = TCIF_TEXT; tab.pszText = "Window";	    TabCtrl_InsertItem (tabctl, i++, &tab);	}        /* The Telnet panel. Accelerators used: [aco] bdflrstuv */	{	    struct ctlpos cp;	    ctlposinit(&cp, hwnd, 6, 30);	    if (dlgtype == 0) {		staticedit(&cp, "Terminal-&type string", IDC4_TTSTATIC, IDC4_TTEDIT);		staticedit(&cp, "Terminal-&speed string", IDC4_TSSTATIC, IDC4_TSEDIT);		staticedit(&cp, "Auto-login &username", IDC4_LOGSTATIC, IDC4_LOGEDIT);		envsetter(&cp, "Environment variables:", IDC4_ENVSTATIC,			  "&Variable", IDC4_VARSTATIC, IDC4_VAREDIT,			  "Va&lue", IDC4_VALSTATIC, IDC4_VALEDIT,			  IDC4_ENVLIST,			  "A&dd", IDC4_ENVADD, "&Remove", IDC4_ENVREMOVE);		radioline(&cp, "Handling of OLD_ENVIRON ambiguity:", IDC4_EMSTATIC, 2,			  "&BSD (commonplace)", IDC4_EMBSD,			  "R&FC 1408 (unusual)", IDC4_EMRFC, NULL);		tab.mask = TCIF_TEXT; tab.pszText = "Telnet";		TabCtrl_InsertItem (tabctl, i++, &tab);	    }	}	/* The SSH panel. Accelerators used: [aco] 123abdkmprtuw */	{	    struct ctlpos cp;	    ctlposinit(&cp, hwnd, 6, 30);	    if (dlgtype == 0) {		staticedit(&cp, "Terminal-&type string", IDC5_TTSTATIC, IDC5_TTEDIT);		staticedit(&cp, "Auto-login &username", IDC5_LOGSTATIC, IDC5_LOGEDIT);		multiedit(&cp,			  "&Remote command:", IDC5_CMDSTATIC, IDC5_CMDEDIT, 100,			  NULL);		checkbox(&cp, "Don't allocate a &pseudo-terminal", IDC5_NOPTY);		checkbox(&cp, "Atte&mpt TIS or CryptoCard authentication",			 IDC5_AUTHTIS);		checkbox(&cp, "Allow &agent forwarding", IDC5_AGENTFWD);		editbutton(&cp, "Private &key file for authentication:",			   IDC5_PKSTATIC, IDC5_PKEDIT, "Bro&wse...", IDC5_PKBUTTON);		radioline(&cp, "Preferred SSH protocol version:",			  IDC5_SSHPROTSTATIC, 2,			  "&1", IDC5_SSHPROT1, "&2", IDC5_SSHPROT2, NULL);		radioline(&cp, "Preferred encryption algorithm:", IDC5_CIPHERSTATIC, 3,			  "&3DES", IDC5_CIPHER3DES,			  "&Blowfish", IDC5_CIPHERBLOWF,			  "&DES", IDC5_CIPHERDES, NULL);		tab.mask = TCIF_TEXT; tab.pszText = "SSH";		TabCtrl_InsertItem (tabctl, i++, &tab);	    }	}        /* The Selection panel. Accelerators used: [aco] stwx */	{	    struct ctlpos cp;	    ctlposinit(&cp, hwnd, 6, 30);	    radiobig(&cp, "Action of mouse buttons:", IDC6_MBSTATIC,		     "&Windows (Right pastes, Middle extends)", IDC6_MBWINDOWS,		     "&xterm (Right extends, Middle pastes)", IDC6_MBXTERM,		     NULL);	    charclass(&cp, "Character classes:", IDC6_CCSTATIC, IDC6_CCLIST,		      "&Set", IDC6_CCSET, IDC6_CCEDIT,		      "&to class", IDC6_CCSTATIC2);	    tab.mask = TCIF_TEXT; tab.pszText = "Selection";	    TabCtrl_InsertItem (tabctl, i++, &tab);	}        /* The Colours panel. Accelerators used: [aco] bmlu */	{	    struct ctlpos cp;	    ctlposinit(&cp, hwnd, 6, 30);	    checkbox(&cp, "&Bolded text is a different colour", IDC7_BOLDCOLOUR);	    checkbox(&cp, "Attempt to use &logical palettes", IDC7_PALETTE);	    colouredit(&cp, "Select a colo&ur and click to modify it:",		       IDC7_STATIC, IDC7_LIST,		       "&Modify...", IDC7_CHANGE,		       "Red:", IDC7_RSTATIC, IDC7_RVALUE,		       "Green:", IDC7_GSTATIC, IDC7_GVALUE,		       "Blue:", IDC7_BSTATIC, IDC7_BVALUE, NULL);	    tab.mask = TCIF_TEXT; tab.pszText = "Colours";	    TabCtrl_InsertItem (tabctl, i++, &tab);	}	/* The Translation panel. Accelerators used: [aco] beiknpsx */	{	    struct ctlpos cp;	    ctlposinit(&cp, hwnd, 6, 30);	    radiobig(&cp,		     "Handling of VT100 line drawing characters:", IDC8_VTSTATIC,		     "Font has &XWindows encoding", IDC8_VTXWINDOWS,		     "Use font in &both ANSI and OEM modes", IDC8_VTOEMANSI,		     "Use font in O&EM mode only", IDC8_VTOEMONLY,		     "&Poor man's line drawing (""+"", ""-"" and ""|"")",		     IDC8_VTPOORMAN, NULL);	    radiobig(&cp,		     "Character set translation:", IDC8_XLATSTATIC,		     "&None", IDC8_NOXLAT,		     "&KOI8 / Win-1251", IDC8_KOI8WIN1251,		     "&ISO-8859-2 / Win-1250", IDC8_88592WIN1250, NULL);	    checkbox(&cp, "CAP&S LOCK acts as cyrillic switch", IDC8_CAPSLOCKCYR);	    tab.mask = TCIF_TEXT; tab.pszText = "Translation";	    TabCtrl_InsertItem (tabctl, i++, &tab);	}	init_dlg_ctrls(hwnd);	hide(hwnd, TRUE, controlstartvalue, controlendvalue);	hide(hwnd, FALSE, connectionpanelstart, connectionpanelend);        /*         * Set focus into the first available control.         */        {            HWND ctl;            ctl = GetDlgItem(hwnd, IDC0_HOST);            if (!ctl) ctl = GetDlgItem(hwnd, IDC0_CLOSEEXIT);            SetFocus(ctl);        }	SetWindowLong(hwnd, GWL_USERDATA, 1);	return 0;      case WM_LBUTTONUP:        /*         * Button release should trigger WM_OK if there was a         * previous double click on the session list.         */        ReleaseCapture();        if (readytogo)            SendMessage (hwnd, WM_COMMAND, IDOK, 0);        break;      case WM_NOTIFY:	if (LOWORD(wParam) == IDCX_TAB &&	    ((LPNMHDR)lParam)->code == TCN_SELCHANGE) {	    int i = TabCtrl_GetCurSel(((LPNMHDR)lParam)->hwndFrom);	    TCITEM item;	    char buffer[64];	    item.pszText = buffer;	    item.cchTextMax = sizeof(buffer);	    item.mask = TCIF_TEXT;	    TabCtrl_GetItem(((LPNMHDR)lParam)->hwndFrom, i, &item);	    hide(hwnd, TRUE, controlstartvalue, controlendvalue);	    if (!strcmp(buffer, "Connection"))		hide(hwnd, FALSE, connectionpanelstart, connectionpanelend);	    if (!strcmp(buffer, "Keyboard"))		hide(hwnd, FALSE, keyboardpanelstart, keyboardpanelend);	    if (!strcmp(buffer, "Terminal"))		hide(hwnd, FALSE, terminalpanelstart, terminalpanelend);	    if (!strcmp(buffer, "Window"))		hide(hwnd, FALSE, windowpanelstart, windowpanelend);	    if (!strcmp(buffer, "Telnet"))		hide(hwnd, FALSE, telnetpanelstart, telnetpanelend);	    if (!strcmp(buffer, "SSH"))		hide(hwnd, FALSE, sshpanelstart, sshpanelend);	    if (!strcmp(buffer, "Selection"))		hide(hwnd, FALSE, selectionpanelstart, selectionpanelend);	    if (!strcmp(buffer, "Colours"))		hide(hwnd, FALSE, colourspanelstart, colourspanelend);	    if (!strcmp(buffer, "Translation"))		hide(hwnd, FALSE, translationpanelstart, translationpanelend);	    SetFocus (((LPNMHDR)lParam)->hwndFrom);   /* ensure focus stays */	    return 0;	}	break;      case WM_COMMAND:	/*	 * Only process WM_COMMAND once the dialog is fully formed.	 */	if (GetWindowLong(hwnd, GWL_USERDATA) == 1) switch (LOWORD(wParam)) {	  case IDOK:	    if (*cfg.host)		EndDialog (hwnd, 1);	    else		MessageBeep (0);	    return 0;	  case IDCANCEL:	    EndDialog (hwnd, 0);	    return 0;	  case IDC0_PROTTELNET:	  case IDC0_PROTSSH:	  case IDC0_PROTRAW:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED) {		int i = IsDlgButtonChecked (hwnd, IDC0_PROTSSH);		int j = IsDlgButtonChecked (hwnd, IDC0_PROTTELNET);		cfg.protocol = i ? PROT_SSH : j ? PROT_TELNET : PROT_RAW ;		if ((cfg.protocol == PROT_SSH && cfg.port == 23) ||		    (cfg.protocol == PROT_TELNET && cfg.port == 22)) {		    cfg.port = i ? 22 : 23;		    SetDlgItemInt (hwnd, IDC0_PORT, cfg.port, FALSE);		}	    }	    break;	  case IDC0_HOST:	    if (HIWORD(wParam) == EN_CHANGE)		GetDlgItemText (hwnd, IDC0_HOST, cfg.host,				sizeof(cfg.host)-1);	    break;	  case IDC0_PORT:	    if (HIWORD(wParam) == EN_CHANGE)		MyGetDlgItemInt (hwnd, IDC0_PORT, &cfg.port);	    break;	  case IDC0_CLOSEEXIT:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED)		cfg.close_on_exit = IsDlgButtonChecked (hwnd, IDC0_CLOSEEXIT);	    break;	  case IDC0_CLOSEWARN:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED)		cfg.warn_on_close = IsDlgButtonChecked (hwnd, IDC0_CLOSEWARN);	    break;	  case IDC0_SESSEDIT:	    if (HIWORD(wParam) == EN_CHANGE) {		SendDlgItemMessage (hwnd, IDC0_SESSLIST, LB_SETCURSEL,				    (WPARAM) -1, 0);                GetDlgItemText (hwnd, IDC0_SESSEDIT,                                savedsession, sizeof(savedsession)-1);                savedsession[sizeof(savedsession)-1] = '\0';            }	    break;	  case IDC0_SESSSAVE:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED) {		/*		 * Save a session		 */		char str[2048];		GetDlgItemText (hwnd, IDC0_SESSEDIT, str, sizeof(str)-1);		if (!*str) {		    int n = SendDlgItemMessage (hwnd, IDC0_SESSLIST,						LB_GETCURSEL, 0, 0);		    if (n == LB_ERR) {			MessageBeep(0);			break;		    }		    strcpy (str, sessions[n]);		}		save_settings (str, !!strcmp(str, "Default Settings"), &cfg);		get_sesslist (FALSE);		get_sesslist (TRUE);		SendDlgItemMessage (hwnd, IDC0_SESSLIST, LB_RESETCONTENT,				    0, 0);		for (i = 0; i < nsessions; i++)		    SendDlgItemMessage (hwnd, IDC0_SESSLIST, LB_ADDSTRING,					0, (LPARAM) (sessions[i]));		SendDlgItemMessage (hwnd, IDC0_SESSLIST, LB_SETCURSEL,				    (WPARAM) -1, 0);	    }	    break;	  case IDC0_SESSLIST:	  case IDC0_SESSLOAD:	    if (LOWORD(wParam) == IDC0_SESSLOAD &&		HIWORD(wParam) != BN_CLICKED &&		HIWORD(wParam) != BN_DOUBLECLICKED)		break;	    if (LOWORD(wParam) == IDC0_SESSLIST &&		HIWORD(wParam) != LBN_DBLCLK)		break;	    {		int n = SendDlgItemMessage (hwnd, IDC0_SESSLIST,					    LB_GETCURSEL, 0, 0);		if (n == LB_ERR) {		    MessageBeep(0);		    break;		}		load_settings (sessions[n],			       !!strcmp(sessions[n], "Default Settings"),                               &cfg);		init_dlg_ctrls(hwnd);	    }	    if (LOWORD(wParam) == IDC0_SESSLIST) {		/*		 * A double-click on a saved session should		 * actually start the session, not just load it.		 * Unless it's Default Settings or some other		 * host-less set of saved settings.		 */		if (*cfg.host) {                    readytogo = TRUE;                    SetCapture(hwnd);                }	    }	    break;	  case IDC0_SESSDEL:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED) {		int n = SendDlgItemMessage (hwnd, IDC0_SESSLIST,					    LB_GETCURSEL, 0, 0);		if (n == LB_ERR || n == 0) {		    MessageBeep(0);		    break;		}		del_settings(sessions[n]);		get_sesslist (FALSE);		get_sesslist (TRUE);		SendDlgItemMessage (hwnd, IDC0_SESSLIST, LB_RESETCONTENT,				    0, 0);		for (i = 0; i < nsessions; i++)		    SendDlgItemMessage (hwnd, IDC0_SESSLIST, LB_ADDSTRING,					0, (LPARAM) (sessions[i]));		SendDlgItemMessage (hwnd, IDC0_SESSLIST, LB_SETCURSEL,				    (WPARAM) -1, 0);	    }	  case IDC1_DEL008:	  case IDC1_DEL127:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED)		cfg.bksp_is_delete = IsDlgButtonChecked (hwnd, IDC1_DEL127);	    break;	  case IDC1_HOMETILDE:	  case IDC1_HOMERXVT:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED)		cfg.rxvt_homeend = IsDlgButtonChecked (hwnd, IDC1_HOMERXVT);	    break;	  case IDC1_FUNCXTERM:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED)		cfg.funky_type = 2;	    break;	  case IDC1_FUNCTILDE:	  case IDC1_FUNCLINUX:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED)		cfg.funky_type = IsDlgButtonChecked (hwnd, IDC1_FUNCLINUX);	    break;	  case IDC1_KPNORMAL:	  case IDC1_KPAPPLIC:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED) {		cfg.app_keypad = IsDlgButtonChecked (hwnd, IDC1_KPAPPLIC);		cfg.nethack_keypad = FALSE;	    }	    break;	  case IDC1_KPNH:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED) {		cfg.app_keypad = FALSE;		cfg.nethack_keypad = TRUE;	    }	    break;	  case IDC1_CURNORMAL:	  case IDC1_CURAPPLIC:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED)		cfg.app_cursor = IsDlgButtonChecked (hwnd, IDC1_CURAPPLIC);	    break;	  case IDC1_ALTF4:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED)		cfg.alt_f4 = IsDlgButtonChecked (hwnd, IDC1_ALTF4);	    break;	  case IDC1_ALTSPACE:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED)		cfg.alt_space = IsDlgButtonChecked (hwnd, IDC1_ALTSPACE);	    break;	  case IDC1_LDISCTERM:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED)		cfg.ldisc_term = IsDlgButtonChecked (hwnd, IDC1_LDISCTERM);	    break;	  case IDC1_SCROLLKEY:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED)		cfg.scroll_on_key = IsDlgButtonChecked (hwnd, IDC1_SCROLLKEY);	    break;	  case IDC2_WRAPMODE:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED)		cfg.wrap_mode = IsDlgButtonChecked (hwnd, IDC2_WRAPMODE);	    break;	  case IDC2_DECOM:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED)		cfg.dec_om = IsDlgButtonChecked (hwnd, IDC2_DECOM);	    break;	  case IDC2_LFHASCR:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED)		cfg.lfhascr = IsDlgButtonChecked (hwnd, IDC2_LFHASCR);	    break;	  case IDC2_ROWSEDIT:	    if (HIWORD(wParam) == EN_CHANGE)		MyGetDlgItemInt (hwnd, IDC2_ROWSEDIT, &cfg.height);	    break;	  case IDC2_COLSEDIT:	    if (HIWORD(wParam) == EN_CHANGE)		MyGetDlgItemInt (hwnd, IDC2_COLSEDIT, &cfg.width);	    break;	  case IDC2_SAVEEDIT:	    if (HIWORD(wParam) == EN_CHANGE)		MyGetDlgItemInt (hwnd, IDC2_SAVEEDIT, &cfg.savelines);	    break;	  case IDC2_CHOOSEFONT:	    lf.lfHeight = cfg.fontheight;	    lf.lfWidth = lf.lfEscapement = lf.lfOrientation = 0;	    lf.lfItalic = lf.lfUnderline = lf.lfStrikeOut = 0;	    lf.lfWeight = (cfg.fontisbold ? FW_BOLD : 0);	    lf.lfCharSet = cfg.fontcharset;	    lf.lfOutPrecision = OUT_DEFAULT_PRECIS;	    lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;	    lf.lfQuality = DEFAULT_QUALITY;	    lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;	    strncpy (lf.lfFaceName, cfg.font, sizeof(lf.lfFaceName)-1);	    lf.lfFaceName[sizeof(lf.lfFaceName)-1] = '\0';	    cf.lStructSize = sizeof(cf);	    cf.hwndOwner = hwnd;	    cf.lpLogFont = &lf;	    cf.Flags = CF_FIXEDPITCHONLY | CF_FORCEFONTEXIST |		CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS;	    if (ChooseFont (&cf)) {		strncpy (cfg.font, lf.lfFaceName, sizeof(cfg.font)-1);		cfg.font[sizeof(cfg.font)-1] = '\0';		cfg.fontisbold = (lf.lfWeight == FW_BOLD);		cfg.fontcharset = lf.lfCharSet;		cfg.fontheight = lf.lfHeight;		fmtfont (fontstatic);		SetDlgItemText (hwnd, IDC2_FONTSTATIC, fontstatic);	    }	    break;	  case IDC2_BEEP:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED)		cfg.beep = IsDlgButtonChecked (hwnd, IDC2_BEEP);	    break;	  case IDC2_BLINKTEXT:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED)		cfg.blinktext = IsDlgButtonChecked (hwnd, IDC2_BLINKTEXT);	    break;	  case IDC2_BCE:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED)		cfg.bce = IsDlgButtonChecked (hwnd, IDC2_BCE);	    break;	  case IDC3_WINNAME:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED)		cfg.win_name_always = IsDlgButtonChecked (hwnd, IDC3_WINNAME);	    break;          case IDC3_BLINKCUR:            if (HIWORD(wParam) == BN_CLICKED ||                HIWORD(wParam) == BN_DOUBLECLICKED)                cfg.blink_cur = IsDlgButtonChecked (hwnd, IDC3_BLINKCUR);            break;          case IDC3_SCROLLBAR:            if (HIWORD(wParam) == BN_CLICKED ||                HIWORD(wParam) == BN_DOUBLECLICKED)                cfg.scrollbar = IsDlgButtonChecked (hwnd, IDC3_SCROLLBAR);            break;          case IDC3_LOCKSIZE:	     if (HIWORD(wParam) == BN_CLICKED ||		 HIWORD(wParam) == BN_DOUBLECLICKED)                cfg.locksize = IsDlgButtonChecked (hwnd, IDC3_LOCKSIZE);            break;	  case IDC3_WINEDIT:	    if (HIWORD(wParam) == EN_CHANGE)		GetDlgItemText (hwnd, IDC3_WINEDIT, cfg.wintitle,				sizeof(cfg.wintitle)-1);	    break;	  case IDC4_TTEDIT:	    if (HIWORD(wParam) == EN_CHANGE)	    GetDlgItemText (hwnd, IDC4_TTEDIT, cfg.termtype,			    sizeof(cfg.termtype)-1);	    break;	  case IDC4_TSEDIT:	    if (HIWORD(wParam) == EN_CHANGE)		GetDlgItemText (hwnd, IDC4_TSEDIT, cfg.termspeed,				sizeof(cfg.termspeed)-1);	    break;	  case IDC4_LOGEDIT:	    if (HIWORD(wParam) == EN_CHANGE) {		GetDlgItemText (hwnd, IDC4_LOGEDIT, cfg.username,				sizeof(cfg.username)-1);		cfg.username[sizeof(cfg.username)-1] = '\0';		SetWindowLong(hwnd, GWL_USERDATA, 0);		SetDlgItemText (hwnd, IDC5_LOGEDIT, cfg.username);		SetWindowLong(hwnd, GWL_USERDATA, 1);	    }	    break;	  case IDC4_EMBSD:	  case IDC4_EMRFC:	    cfg.rfc_environ = IsDlgButtonChecked (hwnd, IDC4_EMRFC);	    break;	  case IDC4_ENVADD:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED) {              char str[sizeof(cfg.environmt)];		char *p;		GetDlgItemText (hwnd, IDC4_VAREDIT, str, sizeof(str)-1);		if (!*str) {		    MessageBeep(0);		    break;		}		p = str + strlen(str);		*p++ = '\t';		GetDlgItemText (hwnd, IDC4_VALEDIT, p, sizeof(str)-1-(p-str));		if (!*p) {		    MessageBeep(0);		    break;		}              p = cfg.environmt;		while (*p) {		    while (*p) p++;		    p++;		}              if ((p-cfg.environmt) + strlen(str) + 2 < sizeof(cfg.environmt)) {		    strcpy (p, str);		    p[strlen(str)+1] = '\0';		    SendDlgItemMessage (hwnd, IDC4_ENVLIST, LB_ADDSTRING,					0, (LPARAM)str);		    SetDlgItemText (hwnd, IDC4_VAREDIT, "");		    SetDlgItemText (hwnd, IDC4_VALEDIT, "");		} else {		    MessageBox(hwnd, "Environment too big", "PuTTY Error",			       MB_OK | MB_ICONERROR);		}	    }	    break;	  case IDC4_ENVREMOVE:	    if (HIWORD(wParam) != BN_CLICKED &&		HIWORD(wParam) != BN_DOUBLECLICKED)		break;	    i = SendDlgItemMessage (hwnd, IDC4_ENVLIST, LB_GETCURSEL, 0, 0);	    if (i == LB_ERR)		MessageBeep (0);	    else {		char *p, *q;	        SendDlgItemMessage (hwnd, IDC4_ENVLIST, LB_DELETESTRING,				    i, 0);              p = cfg.environmt;		while (i > 0) {		    if (!*p)			goto disaster;		    while (*p) p++;		    p++;		    i--;		}		q = p;		if (!*p)		    goto disaster;		while (*p) p++;		p++;		while (*p) {		    while (*p)			*q++ = *p++;		    *q++ = *p++;		}		*q = '\0';		disaster:;	    }	    break;	  case IDC5_TTEDIT:	    if (HIWORD(wParam) == EN_CHANGE)	    GetDlgItemText (hwnd, IDC5_TTEDIT, cfg.termtype,			    sizeof(cfg.termtype)-1);	    break;	  case IDC5_LOGEDIT:	    if (HIWORD(wParam) == EN_CHANGE) {		GetDlgItemText (hwnd, IDC5_LOGEDIT, cfg.username,				sizeof(cfg.username)-1);		cfg.username[sizeof(cfg.username)-1] = '\0';		SetWindowLong(hwnd, GWL_USERDATA, 0);		SetDlgItemText (hwnd, IDC4_LOGEDIT, cfg.username);		SetWindowLong(hwnd, GWL_USERDATA, 1);	    }	    break;	  case IDC5_NOPTY:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED)		cfg.nopty = IsDlgButtonChecked (hwnd, IDC5_NOPTY);	    break;	  case IDC5_AGENTFWD:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED)		cfg.agentfwd = IsDlgButtonChecked (hwnd, IDC5_AGENTFWD);	    break;	  case IDC5_CIPHER3DES:	  case IDC5_CIPHERBLOWF:	  case IDC5_CIPHERDES:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED) {		if (IsDlgButtonChecked (hwnd, IDC5_CIPHER3DES))		    cfg.cipher = CIPHER_3DES;		else if (IsDlgButtonChecked (hwnd, IDC5_CIPHERBLOWF))		    cfg.cipher = CIPHER_BLOWFISH;		else if (IsDlgButtonChecked (hwnd, IDC5_CIPHERDES))		    cfg.cipher = CIPHER_DES;	    }	    break;	  case IDC5_SSHPROT1:	  case IDC5_SSHPROT2:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED) {		if (IsDlgButtonChecked (hwnd, IDC5_SSHPROT1))		    cfg.sshprot = 1;		else if (IsDlgButtonChecked (hwnd, IDC5_SSHPROT2))		    cfg.sshprot = 2;	    }	    break;	  case IDC5_AUTHTIS:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED)		cfg.try_tis_auth = IsDlgButtonChecked (hwnd, IDC5_AUTHTIS);	    break;	  case IDC5_PKEDIT:	    if (HIWORD(wParam) == EN_CHANGE)		GetDlgItemText (hwnd, IDC5_PKEDIT, cfg.keyfile,				sizeof(cfg.keyfile)-1);	    break;	  case IDC5_CMDEDIT:	    if (HIWORD(wParam) == EN_CHANGE)		GetDlgItemText (hwnd, IDC5_CMDEDIT, cfg.remote_cmd,				sizeof(cfg.remote_cmd)-1);	    break;	  case IDC5_PKBUTTON:            memset(&of, 0, sizeof(of));#ifdef OPENFILENAME_SIZE_VERSION_400            of.lStructSize = OPENFILENAME_SIZE_VERSION_400;#else            of.lStructSize = sizeof(of);#endif            of.hwndOwner = hwnd;            of.lpstrFilter = "All Files\0*\0\0\0";            of.lpstrCustomFilter = NULL;            of.nFilterIndex = 1;            of.lpstrFile = filename; strcpy(filename, cfg.keyfile);            of.nMaxFile = sizeof(filename);            of.lpstrFileTitle = NULL;            of.lpstrInitialDir = NULL;            of.lpstrTitle = "Select Public Key File";            of.Flags = 0;            if (GetOpenFileName(&of)) {                strcpy(cfg.keyfile, filename);                SetDlgItemText (hwnd, IDC5_PKEDIT, cfg.keyfile);            }	    break;	  case IDC6_MBWINDOWS:	  case IDC6_MBXTERM:	    cfg.mouse_is_xterm = IsDlgButtonChecked (hwnd, IDC6_MBXTERM);	    break;	  case IDC6_CCSET:	    {		BOOL ok;		int i;		int n = GetDlgItemInt (hwnd, IDC6_CCEDIT, &ok, FALSE);		if (!ok)		    MessageBeep (0);		else {		    for (i=0; i<256; i++)			if (SendDlgItemMessage (hwnd, IDC6_CCLIST, LB_GETSEL,						i, 0)) {			    char str[100];			    cfg.wordness[i] = n;			    SendDlgItemMessage (hwnd, IDC6_CCLIST,						LB_DELETESTRING, i, 0);			    sprintf(str, "%d\t(0x%02X)\t%c\t%d", i, i,				    (i>=0x21 && i != 0x7F) ? i : ' ',				    cfg.wordness[i]);			    SendDlgItemMessage (hwnd, IDC6_CCLIST,						LB_INSERTSTRING, i,						(LPARAM)str);			}		}	    }	    break;	  case IDC7_BOLDCOLOUR:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED) {		int n, i;		cfg.bold_colour = IsDlgButtonChecked (hwnd, IDC7_BOLDCOLOUR);		n = SendDlgItemMessage (hwnd, IDC7_LIST, LB_GETCOUNT, 0, 0);		if (cfg.bold_colour && n!=22) {		    for (i=0; i<22; i++)			if (!permcolour[i])			    SendDlgItemMessage (hwnd, IDC7_LIST,						LB_INSERTSTRING, i,						(LPARAM) colours[i]);		} else if (!cfg.bold_colour && n!=12) {		    for (i=22; i-- ;)			if (!permcolour[i])			    SendDlgItemMessage (hwnd, IDC7_LIST,						LB_DELETESTRING, i, 0);		}	    }	    break;	  case IDC7_PALETTE:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED)		cfg.try_palette = IsDlgButtonChecked (hwnd, IDC7_PALETTE);	    break;	  case IDC7_LIST:	    if (HIWORD(wParam) == LBN_DBLCLK ||		HIWORD(wParam) == LBN_SELCHANGE) {		int i = SendDlgItemMessage (hwnd, IDC7_LIST, LB_GETCURSEL,					    0, 0);		if (!cfg.bold_colour)		    i = (i < 3 ? i*2 : i == 3 ? 5 : i*2-2);		SetDlgItemInt (hwnd, IDC7_RVALUE, cfg.colours[i][0], FALSE);		SetDlgItemInt (hwnd, IDC7_GVALUE, cfg.colours[i][1], FALSE);		SetDlgItemInt (hwnd, IDC7_BVALUE, cfg.colours[i][2], FALSE);	    }	    break;	  case IDC7_CHANGE:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED) {		static CHOOSECOLOR cc;		static DWORD custom[16] = {0};   /* zero initialisers */		int i = SendDlgItemMessage (hwnd, IDC7_LIST, LB_GETCURSEL,					    0, 0);		if (!cfg.bold_colour)		    i = (i < 3 ? i*2 : i == 3 ? 5 : i*2-2);		cc.lStructSize = sizeof(cc);		cc.hwndOwner = hwnd;		cc.hInstance = (HWND)hinst;		cc.lpCustColors = custom;		cc.rgbResult = RGB (cfg.colours[i][0], cfg.colours[i][1],				    cfg.colours[i][2]);		cc.Flags = CC_FULLOPEN | CC_RGBINIT;		if (ChooseColor(&cc)) {		    cfg.colours[i][0] =			(unsigned char) (cc.rgbResult & 0xFF);		    cfg.colours[i][1] =			(unsigned char) (cc.rgbResult >> 8) & 0xFF;		    cfg.colours[i][2] =			(unsigned char) (cc.rgbResult >> 16) & 0xFF;		    SetDlgItemInt (hwnd, IDC7_RVALUE, cfg.colours[i][0],				   FALSE);		    SetDlgItemInt (hwnd, IDC7_GVALUE, cfg.colours[i][1],				   FALSE);		    SetDlgItemInt (hwnd, IDC7_BVALUE, cfg.colours[i][2],				   FALSE);		}	    }	    break;	  case IDC8_NOXLAT:	  case IDC8_KOI8WIN1251:	  case IDC8_88592WIN1250:	    cfg.xlat_enablekoiwin =		IsDlgButtonChecked (hwnd, IDC8_KOI8WIN1251);	    cfg.xlat_88592w1250 =		IsDlgButtonChecked (hwnd, IDC8_88592WIN1250);	    break;	  case IDC8_CAPSLOCKCYR:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED) {		cfg.xlat_capslockcyr =		    IsDlgButtonChecked (hwnd, IDC8_CAPSLOCKCYR);	    }	    break;	  case IDC8_VTXWINDOWS:	  case IDC8_VTOEMANSI:	  case IDC8_VTOEMONLY:	  case IDC8_VTPOORMAN:	    cfg.vtmode =		(IsDlgButtonChecked (hwnd, IDC8_VTXWINDOWS) ? VT_XWINDOWS :		 IsDlgButtonChecked (hwnd, IDC8_VTOEMANSI) ? VT_OEMANSI :		 IsDlgButtonChecked (hwnd, IDC8_VTOEMONLY) ? VT_OEMONLY :		 VT_POORMAN);	    break;	}	return 0;      case WM_CLOSE:	EndDialog (hwnd, 0);	return 0;	/* Grrr Explorer will maximize Dialogs! */      case WM_SIZE:	if (wParam == SIZE_MAXIMIZED)	   force_normal(hwnd);	return 0;    }    return 0;}