// Set the enabled state of the window void SetEnable(HWND hWnd, UINT id, bool b) { // Validate arguments if (hWnd == NULL) { return; } if (b == false) { if (IsEnable(hWnd, id)) { EnableWindow(DlgItem(hWnd, id), false); Refresh(DlgItem(hWnd, id)); } } else { if (IsDisable(hWnd, id)) { EnableWindow(DlgItem(hWnd, id), true); Refresh(DlgItem(hWnd, id)); } } }
// Set the window style void SetStyle(HWND hWnd, UINT id, UINT style) { UINT old; // Validate arguments if (hWnd == NULL) { return; } old = GetStyle(hWnd, id); if (old & style) { return; } SetWindowLong(DlgItem(hWnd, id), GWL_STYLE, old | style); Refresh(DlgItem(hWnd, id)); }
// Remove the window style void RemoveExStyle(HWND hWnd, UINT id, UINT style) { UINT old; // Validate arguments if (hWnd == NULL) { return; } old = GetExStyle(hWnd, id); if ((old & style) == 0) { return; } SetWindowLong(DlgItem(hWnd, id), GWL_EXSTYLE, old & ~style); Refresh(DlgItem(hWnd, id)); }
// Set the string to window void SetText(HWND hWnd, UINT id, wchar_t *str) { wchar_t tmp[512]; // Validate arguments if (hWnd == NULL || str == NULL) { return; } Zero(tmp, sizeof(tmp)); GetWindowTextW(DlgItem(hWnd, id), tmp, sizeof(tmp) - 1); if (lstrcmpW(tmp, str) == 0) { return; } SetWindowTextW(DlgItem(hWnd, id), str); }
// Transmit a message to the control UINT SendMsg(HWND hWnd, UINT id, UINT msg, WPARAM wParam, LPARAM lParam) { // Validate arguments if (hWnd == NULL) { return 0; } return (UINT)SendMessageA(DlgItem(hWnd, id), msg, wParam, lParam); }
// Examine whether the window is enabled bool IsEnable(HWND hWnd, UINT id) { // Validate arguments if (hWnd == NULL) { return false; } return IsWindowEnabled(DlgItem(hWnd, id)); }
// Get the window style UINT GetStyle(HWND hWnd, UINT id) { // Validate arguments if (hWnd == NULL) { return 0; } return GetWindowLong(DlgItem(hWnd, id), GWL_STYLE); }
// Display the window void Show(HWND hWnd, UINT id) { // Validate arguments if (hWnd == NULL) { return; } if (IsHide(hWnd, id)) { ShowWindow(DlgItem(hWnd, id), SW_SHOW); } }
// Hide the window void Hide(HWND hWnd, UINT id) { // Validate arguments if (hWnd == NULL) { return; } if (IsShow(hWnd, id)) { ShowWindow(DlgItem(hWnd, id), SW_HIDE); } }
// Connecting dialog UINT NmConnectDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam, void *param) { NM_CONNECT *t = (NM_CONNECT *)param; RPC *rpc; NM_LOGIN login; UINT err; // Validate arguments if (hWnd == NULL) { return 0; } switch (msg) { case WM_INITDIALOG: FormatText(hWnd, S_TITLE, t->Hostname); SetTimer(hWnd, 1, 50, NULL); break; case WM_TIMER: switch (wParam) { case 1: KillTimer(hWnd, 1); while (true) { bool flag = false; RETRY_PASSWORD: // Password input dialog Zero(&login, sizeof(login)); login.Hostname = t->Hostname; login.Port = t->Port; Hash(login.hashed_password, "", 0, true); if (flag) { if (Dialog(hWnd, D_NM_LOGIN, NmLogin, &login) == false) { EndDialog(hWnd, false); break; } } RETRY_CONNECT: Refresh(DlgItem(hWnd, S_TITLE)); Refresh(hWnd); // Connection rpc = NatAdminConnect(nm->Cedar, t->Hostname, t->Port, login.hashed_password, &err); if (rpc != NULL) { t->Rpc = rpc; EndDialog(hWnd, true); break; } // Error if (err == ERR_ACCESS_DENIED || err == ERR_AUTH_FAILED) { if (flag) { if (MsgBox(hWnd, MB_ICONEXCLAMATION | MB_RETRYCANCEL, _E(err)) == IDCANCEL) { EndDialog(hWnd, false); break; } } flag = true; goto RETRY_PASSWORD; } else { if (MsgBox(hWnd, MB_ICONEXCLAMATION | MB_RETRYCANCEL, _E(err)) == IDCANCEL) { EndDialog(hWnd, false); break; } goto RETRY_CONNECT; } } break; } break; } return 0; }