void CPWFiltersDlg::UpdateDialogMaxWidth() { bool bSave = m_FLCHeader.GetStopChangeFlag(); m_FLCHeader.SetStopChangeFlag(true); int itotalwidth = 0; for (int i = 0; i < FLC_NUM_COLUMNS - 1; i++) { m_FilterLC.SetColumnWidth(i, LVSCW_AUTOSIZE); int iw1 = m_FilterLC.GetColumnWidth(i); m_FilterLC.SetColumnWidth(i, LVSCW_AUTOSIZE_USEHEADER); int iw2 = m_FilterLC.GetColumnWidth(i); m_FilterLC.SetColumnWidth(i, std::max(iw1, iw2)); itotalwidth += std::max(iw1, iw2); } m_FilterLC.SetColumnWidth(FLC_NUM_COLUMNS - 1, LVSCW_AUTOSIZE_USEHEADER); itotalwidth += m_FilterLC.GetColumnWidth(FLC_NUM_COLUMNS - 1); m_FLCHeader.SetStopChangeFlag(bSave); int iMaxWidth = itotalwidth + 32; int iMaxHeight = 1024; SetMaxHeightWidth(iMaxHeight, iMaxWidth); }
BOOL CViewReport::OnInitDialog() { std::vector<UINT> vibottombtns; vibottombtns.push_back(IDOK); vibottombtns.push_back(IDC_REPORT2CLIPBOARD); vibottombtns.push_back(IDCANCEL); AddMainCtrlID(IDC_EDITREPORT); AddBtnsCtrlIDs(vibottombtns, 2); UINT statustext[1] = {IDS_BLANK}; SetStatusBar(&statustext[0], 1, false); CPWResizeDialog::OnInitDialog(); if (GetParent() == NULL) GetDlgItem(IDC_REPORT2CLIPBOARD)->EnableWindow(FALSE); // Get new edit string (as per MS doc.) HLOCAL h = ::LocalAlloc(LHND, m_dwDatasize + sizeof(wchar_t)); if (h == NULL) { pws_os::Trace(L"ViewReport: Unable to allocate memory. Can't do this properly!\n"); m_editreport.SetWindowText(m_pString.c_str()); return FALSE; } m_bMemoryAllocOK = true; LPCWSTR lpszText = (LPCWSTR)::LocalLock(h); memcpy((void *)lpszText, m_pString.c_str(), m_dwDatasize); // Now work out maximum size of dialog CClientDC dc(GetDlgItem(IDC_EDITREPORT)); //get the size of the text CRect textRect(0, 0, 32767, 32767); CFont *pOldFont = dc.SelectObject(m_editreport.GetFont()); // Get Height dc.DrawText(lpszText, (int)m_pString.length(), &textRect, DT_CALCRECT | DT_NOCLIP); // Get width of longest line - ignores tabs - but no issue as edit control has // horizontal scroll bars wchar_t pSeps[] = L"\r\n"; int iMaxWidth(-1); // Capture individual lines: wchar_t *next_token; wchar_t *token = wcstok_s((LPWSTR)lpszText, pSeps, &next_token); while(token) { CSize sz = dc.GetTextExtent(token, (int)wcslen(token)); if (sz.cx > iMaxWidth) iMaxWidth = sz.cx; token = wcstok_s(NULL, pSeps, &next_token); } dc.SelectObject(pOldFont); //get the size of the edit control and the dialog CRect editRect, dlgRect; m_editreport.GetClientRect(&editRect); GetClientRect(&dlgRect); // Get height and width of characters TEXTMETRIC tm; dc.GetTextMetrics(&tm); // Set size based on current size (add spare in case) int iAdditionalHeight(0), iAdditionalWidth(0); if (iMaxWidth > editRect.Width()) iAdditionalWidth = (iMaxWidth - editRect.Width()) + 2 * tm.tmMaxCharWidth; if (textRect.Height() > editRect.Height()) iAdditionalHeight = (textRect.Height() - editRect.Height()) + 2 * tm.tmHeight; // Set it SetMaxHeightWidth(dlgRect.Height() + iAdditionalHeight, dlgRect.Width() + iAdditionalWidth); // Refresh data as _wcstok trashes it! memcpy((void *)lpszText, m_pString.c_str(), m_dwDatasize); ::LocalUnlock(h); // Free original handle ::LocalFree(m_editreport.GetHandle()); // Set ours m_editreport.SetHandle(h); return FALSE; }
BOOL CPWFiltersDlg::OnInitDialog() { std::vector<UINT> vibottombtns; UINT main_bns[] = {IDC_APPLY, IDOK, IDCANCEL, ID_HELP}; UINT other_bns[] = {IDOK, IDCANCEL, ID_HELP}; if (m_iType == DFTYPE_MAIN && m_bAllowSet) vibottombtns.assign(main_bns, main_bns + _countof(main_bns)); else vibottombtns.assign(other_bns, other_bns + _countof(other_bns)); AddMainCtrlID(IDC_FILTERLC); AddBtnsCtrlIDs(vibottombtns); UINT statustext[1] = {IDS_BLANK}; SetStatusBar(&statustext[0], 1); CPWResizeDialog::OnInitDialog(); SetWindowText(m_cstitle); m_hAccel = ::LoadAccelerators(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_FILTERACCELERATOR)); DWORD dwExStyle = m_FilterLC.GetExtendedStyle(); dwExStyle |= LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_SUBITEMIMAGES; m_FilterLC.SetExtendedStyle(dwExStyle); m_FilterLC.Init(this, m_pfilters, m_iType, m_bCanHaveAttachments, m_psMediaTypes); if (m_filtername.IsEmpty() || m_pfilters->fname.empty()) m_filtername.LoadString(IDS_FILTER_NAME); else m_filtername = m_pfilters->fname.c_str(); CHeaderCtrl* pHCtrl; pHCtrl = m_FilterLC.GetHeaderCtrl(); ASSERT(pHCtrl != NULL); pHCtrl->SetDlgCtrlID(IDC_FILTERLC_HEADER); m_FLCHeader.SubclassWindow(pHCtrl->GetSafeHwnd()); m_FLCHeader.SetStopChangeFlag(true); CRect rect; // Move over History & Policy dialogs so as not to obscure main filter dialog if (m_iType != DFTYPE_MAIN) { GetParent()->GetWindowRect(&rect); SetWindowPos(NULL, rect.left + rect.Width() / 3, rect.top + rect.Width() / 3, 0, 0, SWP_NOSIZE | SWP_NOZORDER); } // Main window has Apply (if not called via Manage), OK, Cancel buttons // History/Policy/Attachment have OK, Cancel, Help buttons // but only one dialog definition in resource file for both in // order to ensure that the dialogs look exactly the same and also // easier to maintain if (m_iType != DFTYPE_MAIN) { GetDlgItem(IDC_FILTERNAME)->EnableWindow(FALSE); } if (!m_bAllowSet) { // Change buttons if called via ManageFilters or // is a History/Policy dialog GetDlgItem(IDC_APPLY)->EnableWindow(FALSE); GetDlgItem(IDC_APPLY)->ShowWindow(SW_HIDE); } int itotalwidth = 0; for (int i = 0; i < FLC_NUM_COLUMNS; i++) { itotalwidth += m_FilterLC.GetColumnWidth(i); } int iMaxWidth = itotalwidth + 16; int iMaxHeight = 1024; SetMaxHeightWidth(iMaxHeight, iMaxWidth); // Update dialog window text UpdateStatusText(); UpdateData(FALSE); if (m_iType == DFTYPE_MAIN) GetDlgItem(IDC_APPLY)->EnableWindow(m_pfilters->num_Mactive == 0 ? FALSE : TRUE); return TRUE; // return TRUE unless you set the focus to a control }
BOOL CCompareResultsDlg::OnInitDialog() { std::vector<UINT> vibottombtns; vibottombtns.push_back(IDOK); AddMainCtrlID(IDC_RESULTLIST); AddBtnsCtrlIDs(vibottombtns); UINT statustext[1] = {IDS_STATCOMPANY}; SetStatusBar(&statustext[0], 1); CPWResizeDialog::OnInitDialog(); m_menuManager.Install(this); m_menuManager.SetImageList(&GetMainDlg()->m_MainToolBar); m_menuManager.SetMapping(&GetMainDlg()->m_MainToolBar); m_LCResults.GetHeaderCtrl()->SetDlgCtrlID(IDC_RESULTLISTHDR); DWORD dwExtendedStyle = m_LCResults.GetExtendedStyle(); dwExtendedStyle |= (LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT); m_LCResults.SetExtendedStyle(dwExtendedStyle); CString cs_header; int i; for (i = 0; i < sizeof(FixedCols) / sizeof(FixedCols[0]); i++) { cs_header.LoadString(FixedCols[i]); m_LCResults.InsertColumn(i, cs_header); } for (i = 0; i < sizeof(OptCols) / sizeof(OptCols[0]); i++) { if (m_bsFields.test(OptCols[i].ft)) { cs_header.LoadString(OptCols[i].ids); // Add on the end int icol = m_LCResults.InsertColumn(LAST, cs_header, LVCFMT_CENTER); ASSERT(icol != -1); } } m_nCols = m_LCResults.GetHeaderCtrl()->GetItemCount(); m_numOnlyInCurrent = m_OnlyInCurrent.size(); m_numOnlyInComp = m_OnlyInComp.size(); m_numConflicts = m_Conflicts.size(); m_numIdentical = m_Identical.size(); m_LCResults.SetItemCount((int)(m_numOnlyInCurrent + m_numOnlyInComp + m_numConflicts + m_numIdentical)); // Sort the entries first by group, title, user (not case sensitive) if (m_numOnlyInCurrent > 0) std::sort(m_OnlyInCurrent.begin(), m_OnlyInCurrent.end(), GTUCompare2); if (m_numOnlyInComp > 0) std::sort(m_OnlyInComp.begin(), m_OnlyInComp.end(), GTUCompare2); if (m_numConflicts > 0) std::sort(m_Conflicts.begin(), m_Conflicts.end(), GTUCompare2); if (m_numIdentical > 0) std::sort(m_Identical.begin(), m_Identical.end(), GTUCompare2); AddCompareEntries(false); m_LCResults.SetRedraw(FALSE); for (i = 0; i < m_nCols - 1; i++) { m_LCResults.SetColumnWidth(i, LVSCW_AUTOSIZE_USEHEADER); int header_width = m_LCResults.GetColumnWidth(i); m_LCResults.SetColumnWidth(i, LVSCW_AUTOSIZE); int data_width = m_LCResults.GetColumnWidth(i); if (header_width > data_width) m_LCResults.SetColumnWidth(i, LVSCW_AUTOSIZE_USEHEADER); } m_LCResults.SetColumnWidth(m_nCols - 1, LVSCW_AUTOSIZE_USEHEADER); m_LCResults.SetRedraw(TRUE); m_LCResults.Invalidate(); int itotalwidth = 0; for (i = 0; i < m_nCols; i++) { itotalwidth += m_LCResults.GetColumnWidth(i); } int iMaxWidth = itotalwidth + 16; int iMaxHeight = 1024; SetMaxHeightWidth(iMaxHeight, iMaxWidth); GetDlgItem(IDC_COMPAREORIGINALDB)->SetWindowText(m_scFilename1); GetDlgItem(IDC_COMPARECOMPARISONDB)->SetWindowText(m_scFilename2); WriteReportData(); UpdateStatusBar(); return FALSE; }