LRESULT CALLBACK EditTagsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { static HANDLE hwndText; static int sizeX, sizeY; int len, newSizeX, newSizeY, flags; char *str; RECT rect; MINMAXINFO *mmi; int err; switch (message) { case WM_INITDIALOG: /* message: initialize dialog box */ /* Initialize the dialog items */ Translate(hDlg, DLG_EditTags); hwndText = GetDlgItem(hDlg, OPT_TagsText); SendMessage(hwndText, WM_SETFONT, (WPARAM)font[boardSize][EDITTAGS_FONT]->hf, MAKELPARAM(FALSE, 0)); SetDlgItemText(hDlg, OPT_TagsText, editTagsText); EnableWindow(GetDlgItem(hDlg, OPT_TagsCancel), canEditTags); EnableWindow(GetDlgItem(hDlg, OPT_EditTags), !canEditTags); SendMessage(hwndText, EM_SETREADONLY, !canEditTags, 0); if (bookUp) { SetWindowText(hDlg, _("Edit Book")); SetFocus(hwndText); } else if (canEditTags) { SetWindowText(hDlg, _("Edit Tags")); SetFocus(hwndText); } else { SetWindowText(hDlg, _("Tags")); SetFocus(GetDlgItem(hDlg, IDOK)); } if (!editTagsDialog) { editTagsDialog = hDlg; flags = SWP_NOZORDER; GetClientRect(hDlg, &rect); sizeX = rect.right; sizeY = rect.bottom; if (wpTags.x != CW_USEDEFAULT && wpTags.y != CW_USEDEFAULT && wpTags.width != CW_USEDEFAULT && wpTags.height != CW_USEDEFAULT) { WINDOWPLACEMENT wp; EnsureOnScreen(&wpTags.x, &wpTags.y, 0, 0); wp.length = sizeof(WINDOWPLACEMENT); wp.flags = 0; wp.showCmd = SW_SHOW; wp.ptMaxPosition.x = wp.ptMaxPosition.y = 0; wp.rcNormalPosition.left = wpTags.x; wp.rcNormalPosition.right = wpTags.x + wpTags.width; wp.rcNormalPosition.top = wpTags.y; wp.rcNormalPosition.bottom = wpTags.y + wpTags.height; SetWindowPlacement(hDlg, &wp); GetClientRect(hDlg, &rect); newSizeX = rect.right; newSizeY = rect.bottom; ResizeEditPlusButtons(hDlg, hwndText, sizeX, sizeY, newSizeX, newSizeY); sizeX = newSizeX; sizeY = newSizeY; } } return FALSE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: if (canEditTags) { char *p, *q; /* Read changed options from the dialog box */ len = GetWindowTextLength(hwndText); str = (char *) malloc(len + 1); GetWindowText(hwndText, str, len + 1); p = q = str; while (*q) { if (*q == '\r') q++; else *p++ = *q++; } *p = NULLCHAR; err = 0; if(resPtr) *resPtr = strdup(str); else if(bookUp) SaveToBook(str); else err = ReplaceTags(str, &gameInfo); if (err) DisplayError(_("Error replacing tags."), err); free(str); } TagsPopDown(); return TRUE; case IDCANCEL: case OPT_TagsCancel: TagsPopDown(); return TRUE; case OPT_EditTags: EditTagsEvent(); return TRUE; default: break; } break; case WM_SIZE: newSizeX = LOWORD(lParam); newSizeY = HIWORD(lParam); ResizeEditPlusButtons(hDlg, hwndText, sizeX, sizeY, newSizeX, newSizeY); sizeX = newSizeX; sizeY = newSizeY; break; case WM_GETMINMAXINFO: /* Prevent resizing window too small */ mmi = (MINMAXINFO *) lParam; mmi->ptMinTrackSize.x = 100; mmi->ptMinTrackSize.y = 100; break; } return FALSE; }
// This seems pure front end LRESULT CALLBACK ChatProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam ) { static SnapData sd; char buf[MSG_SIZ], mess[MSG_SIZ]; int partner = -1, i, x, y; static BOOL filterHasFocus[MAX_CHAT]; WORD wMask; HWND hMemo; for(i=0; i<MAX_CHAT; i++) if(hDlg == chatHandle[i]) { partner = i; break; } switch (message) { case WM_INITDIALOG: Translate(hDlg, DLG_Chat); if(partner<0) { for(i=0; i<MAX_CHAT; i++) if(chatHandle[i] == NULL) { partner = i; break; } chatHandle[partner] = hDlg; snprintf(buf, MSG_SIZ, T_("Chat Window %s"), ics_handle[0] ? ics_handle : first.tidy); SetWindowText(hDlg, buf); } for(i=0; i<MAX_CHAT; i++) if(chatHandle[i]) { if(i == partner) continue; // set our button in other open chats SetDlgItemText(chatHandle[i], IDC_Focus1+partner-(i<partner), chatPartner[partner]); EnableWindow( GetDlgItem(chatHandle[i], IDC_Focus1+partner-(i<partner)), 1 ); // and buttons for other chats in ours SetDlgItemText(hDlg, IDC_Focus1+i-(i>partner), chatPartner[i]); } else EnableWindow( GetDlgItem(hDlg, IDC_Focus1+i-(i>partner)), 0 ); for(i=0; i<MAX_CHAT-1; i++) { Button_SetStyle(GetDlgItem(hDlg, IDC_Focus1+i), BS_PUSHBUTTON|BS_LEFT, TRUE); } x = wpConsole.x; y = wpConsole.y; EnsureOnScreen(&x, &y, 0, 0); SetWindowPos(hDlg, NULL, x, y, 0, 0, SWP_NOZORDER|SWP_NOSIZE); SendMessage( GetDlgItem(hDlg, IDC_ChatPartner), // [HGM] clickbox: initialize with requested handle WM_SETTEXT, 0, (LPARAM) chatPartner[partner] ); filterHasFocus[partner] = TRUE; onTop = partner; // a newly opened box becomes top one if(chatPartner[partner][0]) { filterHasFocus[partner] = FALSE; SetFocus( GetDlgItem(hDlg, OPT_ChatInput) ); } hMemo = GetDlgItem(hDlg, IDC_ChatMemo); wMask = (WORD) SendMessage(hMemo, EM_GETEVENTMASK, 0, 0L); SendMessage(hMemo, EM_SETEVENTMASK, 0, wMask | ENM_LINK); SendMessage(hMemo, EM_AUTOURLDETECT, TRUE, 0L); chatInputWindowProc = (WNDPROC) // cloned from ConsoleWndProc(). Assume they all share same proc. SetWindowLongPtr(GetDlgItem(hDlg, OPT_ChatInput), GWLP_WNDPROC, (LONG_PTR) InterceptArrowKeys); return FALSE; case WM_NOTIFY: if (((NMHDR*)lParam)->code == EN_LINK) { ENLINK *pLink = (ENLINK*)lParam; if (pLink->msg == WM_LBUTTONUP) { TEXTRANGE tr; tr.chrg = pLink->chrg; tr.lpstrText = malloc(1+tr.chrg.cpMax-tr.chrg.cpMin); SendMessage( GetDlgItem(hDlg, IDC_ChatMemo), EM_GETTEXTRANGE, 0, (LPARAM)&tr); ShellExecute(NULL, "open", tr.lpstrText, NULL, NULL, SW_SHOW); free(tr.lpstrText); } } break; case WM_COMMAND: /* [AS] If <Enter> is pressed while editing the filter, it's better to apply the filter rather than selecting the current game. */ if( LOWORD(wParam) == IDC_ChatPartner ) { switch( HIWORD(wParam) ) { case EN_SETFOCUS: filterHasFocus[partner] = TRUE; break; case EN_KILLFOCUS: filterHasFocus[partner] = FALSE; break; } } if( filterHasFocus[partner] && (LOWORD(wParam) == IDC_Send) ) { SetFocus(GetDlgItem(hDlg, OPT_ChatInput)); wParam = IDC_Change; } /* [AS] End command replacement */ switch (LOWORD(wParam)) { case IDCANCEL: /* let Esc key switch focus back to console */ SetFocus(GetDlgItem(hwndConsole, OPT_ConsoleInput)); break; case IDC_Clear: SendMessage( GetDlgItem(hDlg, IDC_ChatMemo), WM_SETTEXT, 0, (LPARAM) "" ); break; case IDC_Change: GetDlgItemText(hDlg, IDC_ChatPartner, chatPartner[partner], MSG_SIZ); for(i=0; i<MAX_CHAT; i++) if(chatHandle[i] && i != partner) { // set our button in other open chats SetDlgItemText(chatHandle[i], IDC_Focus1+partner-(i<partner), chatPartner[partner]); } break; case IDC_Send: GetDlgItemText(hDlg, OPT_ChatInput, mess, MSG_SIZ); SetDlgItemText(hDlg, OPT_ChatInput, ""); // from here on it could be back-end SaveInHistory(mess); if(!strcmp("whispers", chatPartner[partner])) snprintf(buf, MSG_SIZ, "whisper %s\n", mess); // WHISPER box uses "whisper" to send else if(!strcmp("shouts", chatPartner[partner])) snprintf(buf, MSG_SIZ, "shout %s\n", mess); // SHOUT box uses "shout" to send else { if(!atoi(chatPartner[partner])) { snprintf(buf, MSG_SIZ, "> %s\r\n", mess); // echo only tells to handle, not channel InsertIntoMemo(hDlg, buf); snprintf(buf, MSG_SIZ, "xtell %s %s\n", chatPartner[partner], mess); } else snprintf(buf, MSG_SIZ, "tell %s %s\n", chatPartner[partner], mess); } SendToICS(buf); break; case IDC_Focus1: case IDC_Focus2: case IDC_Focus3: case IDC_Focus4: i = LOWORD(wParam) - IDC_Focus1; if(i >= partner) i++; onTop = i; SetFocus(GetDlgItem(hDlg, IDC_Send)); if(chatHandle[i]) { int j; for(j=0; j<MAX_CHAT; j++) if(i != j && chatHandle[j]) Button_SetState(GetDlgItem(chatHandle[j], IDC_Focus1+i-(j<i)), FALSE); SetFocus(GetDlgItem(chatHandle[i], OPT_ChatInput)); } break; default: break; } break; case WM_CLOSE: chatHandle[partner] = 0; chatPartner[partner][0] = 0; ChatPopDown(); for(i=0; i<MAX_CHAT; i++) if(chatHandle[i] && i != partner) { // set our button in other open chats SetDlgItemText(chatHandle[i], IDC_Focus1+partner-(i<partner), ""); EnableWindow( GetDlgItem(chatHandle[i], IDC_Focus1+partner-(i<partner)), 0 ); } EndDialog(hDlg, TRUE); break; case WM_SIZE: ResizeWindowControls( hDlg ); break; case WM_ENTERSIZEMOVE: return OnEnterSizeMove( &sd, hDlg, wParam, lParam ); case WM_SIZING: return OnSizing( &sd, hDlg, wParam, lParam ); case WM_MOVING: return OnMoving( &sd, hDlg, wParam, lParam ); case WM_EXITSIZEMOVE: return OnExitSizeMove( &sd, hDlg, wParam, lParam ); } return FALSE; }
void CBadTrustDialog::OnInitDialog() { // // Get the background brush for our edit controls // m_hbrBackground = CreateSolidBrush(GetSysColor(COLOR_BTNFACE)); // Load the icon LPSTR idi; switch (m_rrn.hrValid) { case HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND): case TRUST_E_NOSIGNATURE: idi = IDI_EXCLAMATION; break; default: idi = IDI_HAND; break; } HICON hicon = LoadIcon(NULL, idi); ::SendDlgItemMessage(m_hWnd, IDC_BADTRUSTICON, STM_SETICON, (WPARAM)hicon, (LPARAM)0); // Set the window title { TCHAR sz[128]; WideCharToMultiByte(CP_ACP, 0, m_rrn.wszDialogTitle, -1, (LPSTR)sz, 128, NULL, NULL); ::SetWindowText(GetWindow(), sz); } // Set the banter text int cchBanter2; { const int cchMax = INTERNET_MAX_URL_LENGTH+64; TCHAR sz[cchMax]; // Set the top level banter ::LoadString(hinst, IDS_BADTRUSTBANTER1, &sz[0], cchMax); ::SetWindowText(WindowOf(IDC_BADTRUSTBANTER1), &sz[0]); // Set the program name { // // The 'program' name we see can in fact often be a full URL. URLs // can be very long, up to 1024 or so. // if (m_rrn.wszProgramName) { WideCharToMultiByte(CP_ACP, 0, m_rrn.wszProgramName, -1, &sz[0], cchMax, NULL, NULL); } else ::LoadString(hinst, IDS_UNKNOWNPROGRAM, &sz[0], cchMax); TCHAR szF[cchMax]; ::FormatMessage(hinst, &szF[0], cchMax, IDS_BADTRUSTBANTER2, &sz[0]); ::SetWindowText(WindowOf(IDC_BADTRUSTBANTER2), &szF[0]); cchBanter2 = lstrlen(&szF[0]); // // This control is read-only. Note that the text on the control // can be copied using the context menu in the control. // SendMessage(WindowOf(IDC_BADTRUSTBANTER2), EM_SETREADONLY, (WPARAM)TRUE, 0); } // Set the trailing banter UINT ids; switch (m_rrn.hrValid) { case HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND): case TRUST_E_NOSIGNATURE: ids = IDS_BADTRUSTBANTER31; break; case CERT_E_EXPIRED: case CERT_E_VALIDIYPERIODNESTING: ids = IDS_BADTRUSTBANTER32; break; case NTE_BAD_SIGNATURE: ids = IDS_BADTRUSTBANTER33; break; default: ids = IDS_BADTRUSTBANTER34; break; } ::LoadString(hinst, ids, &sz[0], cchMax); ::SetWindowText(WindowOf(IDC_BADTRUSTBANTER3), &sz[0]); } // Position the controls so that all are visible { UINT spacing = GetSystemMetrics(SM_CYFIXEDFRAME) * 2; RECT rc1, rc2, rc3; int h; POINT pt; // // Where on the screen is the client area of the dialog? // pt.x = 0; pt.y = 0; ClientToScreen(GetWindow(), &pt); // // Find first text box location // GetWindowRect(WindowOf(IDC_BADTRUSTBANTER1), &rc1); // // Adjust second text box size // SizeControlToFitText(WindowOf(IDC_BADTRUSTBANTER2)); // // Adjust second text box location // GetWindowRect(WindowOf(IDC_BADTRUSTBANTER2), &rc2); rc2.top = rc1.bottom + spacing; ::SetWindowPos(WindowOf(IDC_BADTRUSTBANTER2), NULL, rc2.left - pt.x, rc2.top - pt.y, 0, 0, SWP_NOZORDER | SWP_NOSIZE); GetWindowRect(WindowOf(IDC_BADTRUSTBANTER2), &rc2); // // Adjust third text box location // GetWindowRect(WindowOf(IDC_BADTRUSTBANTER3), &rc3); h = Height(rc3); rc3.top = rc2.bottom + spacing; rc3.bottom = rc3.top + h; ::SetWindowPos(WindowOf(IDC_BADTRUSTBANTER3), NULL, rc3.left - pt.x, rc3.top - pt.y, Width(rc3), Height(rc3), SWP_NOZORDER); // // Adjust the button locations // RECT rcOk, rcCancel, rcDetails; GetWindowRect(WindowOf(IDOK), &rcOk); GetWindowRect(WindowOf(IDCANCEL), &rcCancel); GetWindowRect(WindowOf(IDC_DETAILS), &rcDetails); rcOk.top = rc3.bottom + spacing; rcCancel.top = rcOk.top; rcDetails.top = rcOk.top; ::SetWindowPos(WindowOf(IDOK), NULL, rcOk.left-pt.x, rcOk.top-pt.y,0,0, SWP_NOZORDER|SWP_NOSIZE); ::SetWindowPos(WindowOf(IDCANCEL), NULL, rcCancel.left-pt.x, rcCancel.top-pt.y,0,0, SWP_NOZORDER|SWP_NOSIZE); ::SetWindowPos(WindowOf(IDC_DETAILS), NULL, rcDetails.left-pt.x, rcDetails.top-pt.y,0,0, SWP_NOZORDER|SWP_NOSIZE); GetWindowRect(WindowOf(IDOK), &rcOk); GetWindowRect(WindowOf(IDCANCEL), &rcCancel); GetWindowRect(WindowOf(IDC_DETAILS), &rcDetails); // // Adjust the overall dialog box size // RECT rcMe; ::GetWindowRect(GetWindow(), &rcMe); // screen coords rcMe.bottom = rcOk.bottom + spacing + GetSystemMetrics(SM_CYFIXEDFRAME); ::SetWindowPos(GetWindow(), NULL, 0,0,Width(rcMe),Height(rcMe), SWP_NOZORDER | SWP_NOMOVE); // // Center ourselves in the parent window // HWND hwndParent = ::GetParent(GetWindow()); if (hwndParent == NULL) hwndParent = ::GetDesktopWindow(); RECT rcParent; ::GetWindowRect(GetWindow(), &rcMe); // screen coords ::GetWindowRect(hwndParent, &rcParent); // screen coords POINT ptParent = Center(rcParent); POINT ptMe = Center(rcMe); pt.x = ptParent.x - ptMe.x; pt.y = ptParent.y - ptMe.y; ::SetWindowPos ( GetWindow(), NULL, pt.x, pt.y, 0, 0, SWP_NOZORDER | SWP_NOSIZE ); } // // Make sure we're on the screen // EnsureOnScreen(GetWindow()); // // Bring ourselves to the attention of the user // SetForegroundWindow(GetWindow()); }
LRESULT CALLBACK EditTagsDialog(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { static HANDLE hwndText; static int sizeX, sizeY; int len, newSizeX, newSizeY; char *str; RECT rect; MINMAXINFO *mmi; int err; switch (message) { case WM_INITDIALOG: /* message: initialize dialog box */ /* Initialize the dialog items */ Translate(hDlg, DLG_EditTags); hwndText = memo = GetDlgItem(hDlg, OPT_TagsText); SendMessage(hwndText, WM_SETFONT, (WPARAM)font[boardSize][EDITTAGS_FONT]->hf, MAKELPARAM(FALSE, 0)); SetDlgItemText(hDlg, OPT_TagsText, editTagsText); EnableWindow(GetDlgItem(hDlg, OPT_TagsCancel), canEditTags); EnableWindow(GetDlgItem(hDlg, OPT_EditTags), !canEditTags || bookUp); SendMessage(hwndText, EM_SETREADONLY, !canEditTags, 0); if (bookUp) { SetDlgItemText(hDlg, OPT_EditTags, _("&Play Move")); SetWindowText(hDlg, _("Edit Book")); SetFocus(hwndText); } else if (canEditTags) { SetWindowText(hDlg, _("Edit Tags")); SetFocus(hwndText); } else { SetWindowText(hDlg, _("Tags")); SetFocus(GetDlgItem(hDlg, IDOK)); } if (!editTagsDialog) { editTagsDialog = hDlg; GetClientRect(hDlg, &rect); sizeX = rect.right; sizeY = rect.bottom; SendDlgItemMessage( hDlg, OPT_TagsText, EM_SETEVENTMASK, 0, ENM_MOUSEEVENTS ); if (wpTags.x != CW_USEDEFAULT && wpTags.y != CW_USEDEFAULT && wpTags.width != CW_USEDEFAULT && wpTags.height != CW_USEDEFAULT) { WINDOWPLACEMENT wp; EnsureOnScreen(&wpTags.x, &wpTags.y, 0, 0); wp.length = sizeof(WINDOWPLACEMENT); wp.flags = 0; wp.showCmd = SW_SHOW; wp.ptMaxPosition.x = wp.ptMaxPosition.y = 0; wp.rcNormalPosition.left = wpTags.x; wp.rcNormalPosition.right = wpTags.x + wpTags.width; wp.rcNormalPosition.top = wpTags.y; wp.rcNormalPosition.bottom = wpTags.y + wpTags.height; SetWindowPlacement(hDlg, &wp); GetClientRect(hDlg, &rect); newSizeX = rect.right; newSizeY = rect.bottom; ResizeEditPlusButtons(hDlg, hwndText, sizeX, sizeY, newSizeX, newSizeY); sizeX = newSizeX; sizeY = newSizeY; } } return FALSE; case WM_COMMAND: switch (LOWORD(wParam)) { case IDOK: case OPT_TagsSave: if (canEditTags) { char *p, *q; /* Read changed options from the dialog box */ len = GetWindowTextLength(hwndText); str = (char *) malloc(len + 1); GetWindowText(hwndText, str, len + 1); p = q = str; while (*q) { if (*q == '\r') q++; else *p++ = *q++; } *p = NULLCHAR; err = 0; if(resPtr) *resPtr = strdup(str); else if(bookUp) SaveToBook(str), DisplayBook(currentMove); else err = ReplaceTags(str, &gameInfo); if (err) DisplayError(_("Error replacing tags."), err); free(str); } if(LOWORD(wParam) == IDOK) TagsPopDown(); return TRUE; case IDCANCEL: case OPT_TagsCancel: TagsPopDown(); return TRUE; case OPT_EditTags: if(bookUp) addToBookFlag = !addToBookFlag; else EditTagsEvent(); return TRUE; default: break; } break; case WM_NOTIFY: // [HGM] vari: cloned from whistory.c if( wParam == OPT_TagsText ) { MSGFILTER * lpMF = (MSGFILTER *) lParam; if( lpMF->msg == WM_RBUTTONDOWN ) { POINTL pt; LRESULT index; pt.x = LOWORD( lpMF->lParam ); pt.y = HIWORD( lpMF->lParam ); index = SendDlgItemMessage( hDlg, OPT_TagsText, EM_CHARFROMPOS, 0, (LPARAM) &pt ); hwndText = GetDlgItem(hDlg, OPT_TagsText); // cloned from above len = GetWindowTextLength(hwndText); str = (char *) malloc(len + 1); GetWindowText(hwndText, str, len + 1); if(bookUp) PlayBookMove(str, index); free(str); /* Zap the message for good: apparently, returning non-zero is not enough */ lpMF->msg = WM_USER; return TRUE; } } break; case WM_SIZE: newSizeX = LOWORD(lParam); newSizeY = HIWORD(lParam); ResizeEditPlusButtons(hDlg, hwndText, sizeX, sizeY, newSizeX, newSizeY); sizeX = newSizeX; sizeY = newSizeY; break; case WM_GETMINMAXINFO: /* Prevent resizing window too small */ mmi = (MINMAXINFO *) lParam; mmi->ptMinTrackSize.x = 100; mmi->ptMinTrackSize.y = 100; break; } return FALSE; }
void CDialogTrustDB::OnInitDialog() { // // Initialize our internals // if (Init() != S_OK) return; // // Set the state of our commercial checkbox per the current registry setting // ::SendMessage( WindowOf(IDC_TRUSTCOMMERCIAL), BM_SETCHECK, (m_pdb->AreCommercialPublishersTrusted()==S_OK) ? BST_CHECKED : BST_UNCHECKED, 0L); // // If we are a property sheet, then hide the OK & Cancel buttons and // make the banter wider // if (m_fPropertySheet) { RECT rcBanter, rcOk; GetWindowRect(WindowOf(IDC_BANTER), &rcBanter); // get in screen coords GetWindowRect(WindowOf(IDOK ), &rcOk); // get in screen coords ::SetWindowPos(WindowOf(IDC_BANTER), NULL, 0, 0, Width(rcBanter) + (rcOk.right - rcBanter.right), Height(rcBanter), SWP_NOMOVE | SWP_NOZORDER); ::ShowWindow(WindowOf(IDOK), SW_HIDE); ::ShowWindow(WindowOf(IDCANCEL), SW_HIDE); } else { // // We are the modal dialog variation. Center ourselves in our // parent window // RECT rcParent, rcMe; ::GetWindowRect(m_hWndParent, &rcParent); ::GetWindowRect(GetWindow(), &rcMe); POINT ptParent = Center(rcParent); POINT ptMe = Center(rcMe); POINT pt; pt.x = ptParent.x - ptMe.x + rcMe.left; pt.y = ptParent.y - ptMe.y + rcMe.top; ::SetWindowPos ( GetWindow(), NULL, pt.x, pt.y, 0, 0, SWP_NOZORDER | SWP_NOSIZE ); // // Make sure we're on the screen // EnsureOnScreen(GetWindow()); } // // Populate our list box // RefreshTrustList(); }