if (*cfg.host) SendMessage (GetParent(hwnd), WM_COMMAND, IDOK, 0);
if (*cfg.host) { readytogo = TRUE; SetCapture(hwnd); }
static int CALLBACK ConnectionProc (HWND hwnd, UINT msg,				    WPARAM wParam, LPARAM lParam) {    int i;    switch (msg) {      case WM_INITDIALOG:	SetDlgItemText (hwnd, IDC0_HOST, cfg.host);	SetDlgItemInt (hwnd, IDC0_PORT, cfg.port, FALSE);	for (i = 0; i < nsessions; i++)	    SendDlgItemMessage (hwnd, IDC0_SESSLIST, LB_ADDSTRING,				0, (LPARAM) (sessions[i]));	CheckRadioButton (hwnd, IDC0_PROTTELNET, IDC0_PROTSSH,			  cfg.protocol==PROT_SSH ? IDC0_PROTSSH : IDC0_PROTTELNET);	CheckDlgButton (hwnd, IDC0_CLOSEEXIT, cfg.close_on_exit);	break;      case WM_COMMAND:	switch (LOWORD(wParam)) {	  case IDC0_PROTTELNET:	  case IDC0_PROTSSH:	    if (HIWORD(wParam) == BN_CLICKED ||		HIWORD(wParam) == BN_DOUBLECLICKED) {		int i = IsDlgButtonChecked (hwnd, IDC0_PROTSSH);		cfg.protocol = i ? PROT_SSH : PROT_TELNET;		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_SESSEDIT:	    if (HIWORD(wParam) == EN_CHANGE)		SendDlgItemMessage (hwnd, IDC0_SESSLIST, LB_SETCURSEL,				    (WPARAM) -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"));		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"));		SetDlgItemText (hwnd, IDC0_HOST, cfg.host);		SetDlgItemInt (hwnd, IDC0_PORT, cfg.port, FALSE);		CheckRadioButton (hwnd, IDC0_PROTTELNET, IDC0_PROTSSH,				  (cfg.protocol==PROT_SSH ? IDC0_PROTSSH :				   IDC0_PROTTELNET));		CheckDlgButton (hwnd, IDC0_CLOSEEXIT, cfg.close_on_exit);		SendDlgItemMessage (hwnd, IDC0_SESSLIST, LB_SETCURSEL,				    (WPARAM) -1, 0);	    }	    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)		    SendMessage (GetParent(hwnd), WM_COMMAND, IDOK, 0);	    }	    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_session(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);	    }	}    }    return GeneralPanelProc (hwnd, msg, wParam, lParam);}