INT_PTR KBIntDialog::OnInitDialog() { //TODO: fix the tab order const char * name = ssh_userauth_kbdint_getname(m_session); if (!name) name = ""; ::SetDlgItemTextA(m_hwnd, IDC_STATIC_NAMEFIELD, name); if (m_nrPrompt > 1) { //for each prompt, clone prompt and input fields HWND hPrompt1 = ::GetDlgItem(m_hwnd, IDC_EDIT_PROMPT1); HWND hAnswer1 = ::GetDlgItem(m_hwnd, IDC_EDIT_ANSWER1); HWND hMarker = ::GetDlgItem(m_hwnd, IDC_STATIC_MARKER); RECT promptRect; RECT answerRect; RECT markerRect; ::GetWindowRect(hPrompt1, &promptRect); ScreenRectToClient(m_hwnd, &promptRect); ::GetWindowRect(hAnswer1, &answerRect); ScreenRectToClient(m_hwnd, &answerRect); ::GetWindowRect(hMarker, &markerRect); ScreenRectToClient(m_hwnd, &markerRect); int deltaY = markerRect.top - promptRect.top; //int deltaX = 0; //unused int curPromptID = IDC_EDIT_PROMPT1; int curAnswerID = IDC_EDIT_ANSWER1; for(int i = 1; i < m_nrPrompt; i++) { curPromptID = curPromptID+2; curAnswerID = curAnswerID+2; promptRect.top += deltaY; promptRect.bottom += deltaY; answerRect.top += deltaY; answerRect.bottom += deltaY; ::CreateWindowEx(0, WC_EDIT, TEXT(""), WS_CHILD | WS_VSCROLL | ES_AUTOHSCROLL | ES_MULTILINE | ES_READONLY | WS_VISIBLE, promptRect.left, promptRect.top, promptRect.right-promptRect.left, promptRect.bottom-promptRect.top, m_hwnd, (HMENU)curPromptID, m_hInstance, NULL); ::CreateWindowEx(WS_EX_CLIENTEDGE, WC_EDIT, TEXT(""), WS_CHILD | WS_BORDER | ES_AUTOHSCROLL | WS_VISIBLE, answerRect.left, answerRect.top, answerRect.right-answerRect.left, answerRect.bottom-answerRect.top, m_hwnd, (HMENU)curPromptID, m_hInstance, NULL); } int totalDeltaY = deltaY * (m_nrPrompt-1); HWND hBtnOK = ::GetDlgItem(m_hwnd, IDOK); HWND hBtnCancel = ::GetDlgItem(m_hwnd, IDCANCEL); RECT btnRect; ::GetWindowRect(hBtnOK, &btnRect); ScreenRectToClient(m_hwnd, &btnRect); ::MoveWindow(hBtnOK, btnRect.left, btnRect.top+totalDeltaY, btnRect.right-btnRect.left, btnRect.bottom-btnRect.top, TRUE); ::GetWindowRect(hBtnCancel, &btnRect); ScreenRectToClient(m_hwnd, &btnRect); ::MoveWindow(hBtnCancel, btnRect.left, btnRect.top+totalDeltaY, btnRect.right-btnRect.left, btnRect.bottom-btnRect.top, TRUE); RECT winRect; ::GetWindowRect(m_hwnd, &winRect); Resize(winRect.right-winRect.left, winRect.bottom-winRect.top+totalDeltaY); } for(int i = 0; i < m_nrPrompt; i++) { char echo = 0; const char * prompt = ssh_userauth_kbdint_getprompt(m_session, i, &echo); ::SetDlgItemTextA(m_hwnd, IDC_EDIT_PROMPT1+(i*2), prompt); if (!echo) { HWND hCurAnswer = ::GetDlgItem(m_hwnd, IDC_EDIT_ANSWER1+(i*2)); //LONG_PTR style = ::GetWindowLongPtr(hCurAnswer, GWL_STYLE); //::SetWindowLongPtr(hCurAnswer, GWL_STYLE, style|ES_PASSWORD); ::SendMessage(hCurAnswer, EM_SETPASSWORDCHAR, (WPARAM)'*', 0); } } Dialog::OnInitDialog(); ::SetFocus(::GetDlgItem(m_hwnd, IDC_EDIT_ANSWER1)); return FALSE; }
void DrawLegendLabel (PLEGEND pLegend, HDC hDC, HWND hWnd) { // DrawLegendLabel int i ; int xPos ; RECT rect ; RECT rectLB ; INT LocalThreeDPad = ThreeDPad - 1 ; // SetBkColor (hDC, crLightGray) ; SetBkColor (hDC, ColorBtnFace) ; SelectFont (hDC, pLegend->hFontLabels) ; GetClientRect (hWnd, &rect) ; // Fill (hDC, crLightGray, &rect) ; ExtTextOut (hDC, rect.left, rect.top, ETO_OPAQUE, &(rect), NULL, 0, NULL ) ; GetWindowRect (pLegend->hWndItems, &rectLB) ; ScreenRectToClient (hWnd, &rectLB) ; ThreeDConcave1 (hDC, rectLB.left - LocalThreeDPad, rectLB.top - LocalThreeDPad, rectLB.right + LocalThreeDPad, rectLB.bottom + LocalThreeDPad) ; for (i = 0 ; i < iLegendNumCols ; i++) { // for rect.left = pLegend->aCols[i].xPos ; rect.top = yBorderHeight ; rect.right = rect.left + pLegend->aCols[i].xWidth - LegendHorzMargin () ; rect.bottom = pLegend->yLabelHeight ; switch (pLegend->aCols[i].iOrientation) { // switch case LEFTORIENTATION: SetTextAlign (hDC, TA_LEFT) ; xPos = rect.left ; break ; case CENTERORIENTATION: SetTextAlign (hDC, TA_CENTER) ; xPos = (rect.left + rect.right) / 2 ; break ; case RIGHTORIENTATION: SetTextAlign (hDC, TA_RIGHT) ; xPos = rect.right ; break ; default: xPos = rect.left ; break ; } // switch ExtTextOut (hDC, xPos, rect.top, ETO_OPAQUE, &rect, pLegend->aCols[i].szLabel, lstrlen (pLegend->aCols[i].szLabel), NULL) ; } // for } // DrawLegendLabel
void wxMessageDialog::ReplaceStaticWithEdit() { // check if the message box fits the display int nDisplay = wxDisplay::GetFromWindow(this); if ( nDisplay == wxNOT_FOUND ) nDisplay = 0; const wxRect rectDisplay = wxDisplay(nDisplay).GetClientArea(); if ( rectDisplay.Contains(GetRect()) ) { // nothing to do return; } // find the static control to replace: normally there are two of them, the // icon and the text itself so search for all of them and ignore the icon // ones HWND hwndStatic = ::FindWindowEx(GetHwnd(), NULL, wxT("STATIC"), NULL); if ( ::GetWindowLong(hwndStatic, GWL_STYLE) & SS_ICON ) hwndStatic = ::FindWindowEx(GetHwnd(), hwndStatic, wxT("STATIC"), NULL); if ( !hwndStatic ) { wxLogDebug("Failed to find the static text control in message box."); return; } // set the right font for GetCharHeight() call below wxWindowBase::SetFont(GetMessageFont()); // put the new edit control at the same place RECT rc = wxGetWindowRect(hwndStatic); ScreenRectToClient(GetHwnd(), rc); // but make it less tall so that the message box fits on the screen: we try // to make the message box take no more than 7/8 of the screen to leave // some space above and below it const int hText = (7*rectDisplay.height)/8 - ( 2*::GetSystemMetrics(SM_CYFIXEDFRAME) + ::GetSystemMetrics(SM_CYCAPTION) + 5*GetCharHeight() // buttons + margins ); const int dh = (rc.bottom - rc.top) - hText; // vertical space we save rc.bottom -= dh; // and it also must be wider as it needs a vertical scrollbar (in order // to preserve the word wrap, otherwise the number of lines would change // and we want the control to look as similar as possible to the original) // // NB: you would have thought that 2*SM_CXEDGE would be enough but it // isn't, somehow, and the text control breaks lines differently from // the static one so fudge by adding some extra space const int dw = ::GetSystemMetrics(SM_CXVSCROLL) + 4*::GetSystemMetrics(SM_CXEDGE); rc.right += dw; // chop of the trailing new line(s) from the message box text, they are // ignored by the static control but result in extra lines and hence extra // scrollbar position in the edit one wxString text(wxGetWindowText(hwndStatic)); for ( wxString::reverse_iterator i = text.rbegin(); i != text.rend(); ++i ) { if ( *i != '\n' ) { // found last non-newline char, remove everything after it and stop text.erase(i.base() + 1, text.end()); break; } } // do create the new control HWND hwndEdit = ::CreateWindow ( wxT("EDIT"), wxTextBuffer::Translate(text).wx_str(), WS_CHILD | WS_VSCROLL | WS_VISIBLE | ES_MULTILINE | ES_READONLY | ES_AUTOVSCROLL, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, GetHwnd(), NULL, wxGetInstance(), NULL ); if ( !hwndEdit ) { wxLogDebug("Creation of replacement edit control failed in message box"); return; } // copy the font from the original control LRESULT hfont = ::SendMessage(hwndStatic, WM_GETFONT, 0, 0); ::SendMessage(hwndEdit, WM_SETFONT, hfont, 0); // and get rid of it ::DestroyWindow(hwndStatic); // shrink and centre the message box vertically and widen it box to account // for the extra scrollbar RECT rcBox = wxGetWindowRect(GetHwnd()); const int hMsgBox = rcBox.bottom - rcBox.top - dh; rcBox.top = (rectDisplay.height - hMsgBox)/2; rcBox.bottom = rcBox.top + hMsgBox + (rectDisplay.height - hMsgBox)%2; rcBox.left -= dw/2; rcBox.right += dw - dw/2; SetWindowRect(GetHwnd(), rcBox); // and adjust all the buttons positions for ( unsigned n = 0; n < WXSIZEOF(ms_buttons); n++ ) { const HWND hwndBtn = ::GetDlgItem(GetHwnd(), ms_buttons[n].id); if ( !hwndBtn ) continue; // it's ok, not all buttons are always present RECT rc = wxGetWindowRect(hwndBtn); rc.top -= dh; rc.bottom -= dh; rc.left += dw/2; rc.right += dw/2; MoveWindowToScreenRect(hwndBtn, rc); } }