void CXTPSkinObjectTab::OnMouseMove(UINT /*nFlags*/, CPoint point) { int nHotItem = -1; CTabCtrl* pTabCtrl = (CTabCtrl*)this; for (int iItem = 0; iItem < pTabCtrl->GetItemCount(); ++iItem) { CRect rcItem; pTabCtrl->GetItemRect(iItem, &rcItem); if (rcItem.PtInRect(point)) { nHotItem = iItem; break; } } if (nHotItem != m_nHotItem) { m_nHotItem = nHotItem; InvalidateRect(GetHeaderRect(), FALSE); if (m_nHotItem != -1) { TRACKMOUSEEVENT tme = {sizeof(TRACKMOUSEEVENT), TME_LEAVE, m_hWnd, HOVER_DEFAULT}; _TrackMouseEvent(&tme); } } }
//--------------------------------------------------------------- // Purpose: //--------------------------------------------------------------- BOOL CEntityDialog::OnInitDialog() { if( !CDialogEx::OnInitDialog() ) return FALSE; //Create copy of editable entity m_oldEntity = GetActiveDocument()->GetSelectedEntity(0); m_newEntity = m_oldEntity->Clone(); Assert( m_oldEntity && m_newEntity ); GetActiveDocument()->GetEntityList()->ReplaceEntity( m_oldEntity, m_newEntity ); GetActiveDocument()->SelectSingleEntity( m_newEntity ); m_dialogClassInfo.SetEditEntity(m_newEntity); //Get Tab Control CTabCtrl *pTabCtrl = (CTabCtrl*)GetDlgItem(IDC_TAB1); //Create Tab Content dialog and adjust m_dialogClassInfo.Create(IDD_ENTITY_CLASS_INFO, pTabCtrl); TCITEM tcItem; tcItem.mask = TCIF_TEXT | TCIF_PARAM; tcItem.pszText = _T("Class Info"); tcItem.lParam = (LPARAM)&m_dialogClassInfo; pTabCtrl->InsertItem(0, &tcItem); RECT wndrect; GetClientRect(&wndrect); wndrect.top -= 15; wndrect.bottom -= 30; pTabCtrl->AdjustRect( FALSE, &wndrect ); pTabCtrl->MoveWindow( &wndrect ); CRect rect; pTabCtrl->GetItemRect(0, &rect); m_dialogClassInfo.SetWindowPos(NULL, rect.left, rect.bottom + 1, wndrect.right-wndrect.left-10, wndrect.bottom-wndrect.top-30, /*SWP_NOSIZE |*/ SWP_NOZORDER ); m_dialogClassInfo.ShowWindow(SW_SHOW); return TRUE; }
BOOL CPageLog::OnInitDialog() { CDialogEx::OnInitDialog(); // TODO: 在此添加额外的初始化 // 获取当前路径 CString strPath; GetModuleFileName(NULL,strPath.GetBuffer(MAX_PATH),MAX_PATH); strPath.ReleaseBuffer(); m_strAppPath = strPath.Left(strPath.ReverseFind(_T('\\'))); // 获取窗口原始大小 GetClientRect(&m_rect); CRect rectClient; this->GetOwner()->GetClientRect(&rectClient); CTabCtrl *pTab = (CTabCtrl *)this->GetOwner(); CRect rcHead; pTab->GetItemRect(0,&rcHead); rectClient.top += rcHead.Height() + 2; rectClient.left += 2; rectClient.right -= 2; rectClient.bottom -= 2; MoveWindow(rectClient); m_hEvent = ::CreateEvent(NULL,FALSE,TRUE,NULL); return TRUE; // return TRUE unless you set the focus to a control // 异常: OCX 属性页应返回 FALSE }
void CXTPSkinObjectTab::DrawTab(CDC* pDC, int iItem) { CXTPClientRect rc(this); CTabCtrl* pTabCtrl = (CTabCtrl*)this; // Get the current tab selection. int iCurSel = pTabCtrl->GetCurSel(); // Get the tab item size. CRect rcItem; pTabCtrl->GetItemRect(iItem, &rcItem); if (!CRect().IntersectRect(rcItem, rc)) return; CRect rcItemFocus(rcItem); // Draw the tab item. BOOL bSelected = (iItem == iCurSel); FillTabFace(pDC, rcItem, iItem, pTabCtrl->GetItemCount(), bSelected); DrawTabIcon(pDC, rcItem, iItem); DrawTabText(pDC, rcItem, iItem, iItem, bSelected); // draw the focus rect if (bSelected && ::GetFocus() == m_hWnd && (SendMessage(WM_QUERYUISTATE) & UISF_HIDEFOCUS) == 0) { rcItemFocus.DeflateRect(GetMetrics()->m_cxEdge / 2, GetMetrics()->m_cyEdge / 2); pDC->DrawFocusRect(&rcItemFocus); } }
CRect CXTPSkinObjectTab::GetHeaderRect() { CRect rcHeader; GetClientRect(&rcHeader); CTabCtrl* pTabCtrl = (CTabCtrl*)this; // get the selected tab item rect. CRect rcItem; pTabCtrl->GetItemRect(pTabCtrl->GetCurSel(), &rcItem); DWORD dwStyle = GetStyle(); if (IsRight(dwStyle)) { rcHeader.left = rcItem.left; } else if (IsLeft(dwStyle)) { rcHeader.right = rcItem.right; } else if (IsBottom(dwStyle)) { rcHeader.top = rcItem.top; } else { rcHeader.bottom = (rcHeader.top + rcItem.Height()) * pTabCtrl->GetRowCount() + GetMetrics()->m_cyEdge; } return rcHeader; }
BOOL CPageDataReport::OnInitDialog() { CDialogEx::OnInitDialog(); // TODO: 在此添加额外的初始化 ASSERT(m_pMySlotData); m_StartTimeCtrl.SetFormat(_T("yyyy-MM-dd HH:mm:ss")); m_EndTimeCtrl.SetFormat(_T("yyyy-MM-dd HH:mm:ss")); CTime timeBegin = CTime::GetCurrentTime(); CTime timeEnd(3000,12,31,23,59,59); m_StartTimeCtrl.SetTime(&timeBegin); m_EndTimeCtrl.SetTime(&timeEnd); //获取对话框原始大小 GetClientRect(&m_rect); CRect rectClient; this->GetOwner()->GetClientRect(&rectClient); CTabCtrl *pTab = (CTabCtrl *)this->GetOwner(); CRect rcHead; pTab->GetItemRect(0,&rcHead); rectClient.top += rcHead.Height() + 2; rectClient.left += 2; rectClient.right -= 2; rectClient.bottom -= 2; MoveWindow(rectClient); InitialListCtrl(); // 设置字体颜色 static CFont font; font.CreatePointFont(120,_T("Arial")); GetDlgItem(IDC_TEXT_REPORT_TOTAL)->SetFont(&font); GetDlgItem(IDC_TEXT_REPORT_PASS)->SetFont(&font); GetDlgItem(IDC_TEXT_REPORT_FAIL)->SetFont(&font); GetDlgItem(IDC_TEXT_REPORT_YIELD)->SetFont(&font); return TRUE; // return TRUE unless you set the focus to a control // 异常: OCX 属性页应返回 FALSE }
BOOL CPageData::OnInitDialog() { CDialogEx::OnInitDialog(); // TODO: 在此添加额外的初始化 CRect rectClient; this->GetOwner()->GetClientRect(&rectClient); CTabCtrl *pTab = (CTabCtrl *)this->GetOwner(); CRect rcHead; pTab->GetItemRect(0,&rcHead); rectClient.top += rcHead.Height() + 2; rectClient.left += 2; rectClient.right -= 2; rectClient.bottom -= 2; MoveWindow(rectClient); InitialListCtrl(); return TRUE; // return TRUE unless you set the focus to a control // 异常: OCX 属性页应返回 FALSE }
void CXTPColorDialog::CalculateRects() { CRect rcBtnOK; CRect rcBtnCancel; CRect rcTabCtrl; CRect rcItem; // get the tab control size. CTabCtrl* pTabCtrl = GetTabControl(); pTabCtrl->GetWindowRect(&rcTabCtrl); ScreenToClient(&rcTabCtrl); // get the size of the first tab item. pTabCtrl->GetItemRect(0, &rcItem); // get the OK button size. CButton* pBtnOK = (CButton*)GetDlgItem(IDOK); pBtnOK->GetWindowRect(&rcBtnOK); ScreenToClient(&rcBtnOK); // get the Cancel button size. CButton* pBtnCancel = (CButton*)GetDlgItem(IDCANCEL); pBtnCancel->GetWindowRect(&rcBtnCancel); ScreenToClient(&rcBtnCancel); rcBtnCancel.OffsetRect(-15, 0); // resize the tab control rcTabCtrl.right = rcBtnCancel.left - 5; rcTabCtrl.bottom = rcBtnCancel.top - 15; pTabCtrl->MoveWindow(&rcTabCtrl); // reposition the OK button. rcBtnOK = rcBtnCancel; rcBtnOK.top = rcTabCtrl.top + rcItem.Height() + 1; rcBtnOK.bottom = rcBtnOK.top + rcBtnCancel.Height(); pBtnOK->MoveWindow(&rcBtnOK); // reposition the Cancel button. rcBtnCancel = rcBtnOK; rcBtnCancel.top = rcBtnOK.bottom + 5; rcBtnCancel.bottom = rcBtnCancel.top + rcBtnOK.Height(); pBtnCancel->MoveWindow(&rcBtnCancel); // reposition the hex display if (::IsWindow(m_wndHexEdit.m_hWnd)) { CRect rcWnd; rcWnd = rcBtnCancel; rcWnd.top = rcBtnCancel.bottom + 5; rcWnd.bottom = rcWnd.top + 18; m_wndHexEdit.MoveWindow(&rcWnd); } // reposition the eye dropper. if (::IsWindow(m_wndEyeDropper.m_hWnd)) { CRect rcWnd; m_wndEyeDropper.GetWindowRect(&rcWnd); CSize size = rcWnd.Size(); rcWnd.right = rcBtnOK.right; rcWnd.left = rcBtnOK.right - size.cx; rcWnd.bottom = rcTabCtrl.bottom; rcWnd.top = rcTabCtrl.bottom - size.cy; m_wndEyeDropper.MoveWindow(&rcWnd); } // resize the property sheet. CXTPWindowRect rcWindow(this); ClientToScreen(&rcTabCtrl); rcWindow.bottom = rcTabCtrl.bottom + 10; rcWindow.right -= 15; MoveWindow(&rcWindow); }
BOOL CTreePropSheet::OnInitDialog() { if (m_bTreeViewMode) { // be sure, there are no stacked tabs, because otherwise the // page caption will be to large in tree view mode EnableStackedTabs(FALSE); // Initialize image list. if (m_DefaultImages.GetSafeHandle()) { IMAGEINFO ii; m_DefaultImages.GetImageInfo(0, &ii); if (ii.hbmImage) DeleteObject(ii.hbmImage); if (ii.hbmMask) DeleteObject(ii.hbmMask); m_Images.Create(ii.rcImage.right-ii.rcImage.left, ii.rcImage.bottom-ii.rcImage.top, ILC_COLOR32|ILC_MASK, 0, 1); } else m_Images.Create(16, 16, ILC_COLOR32|ILC_MASK, 0, 1); } // perform default implementation BOOL bResult = CPropertySheet::OnInitDialog(); if (!m_bTreeViewMode) // stop here, if we would like to use tabs return bResult; // Get tab control... CTabCtrl *pTab = GetTabControl(); if (!IsWindow(pTab->GetSafeHwnd())) { ASSERT(FALSE); return bResult; } // ... and hide it pTab->ShowWindow(SW_HIDE); pTab->EnableWindow(FALSE); // Place another (empty) tab ctrl, to get a frame instead CRect rectFrame; pTab->GetWindowRect(rectFrame); ScreenToClient(rectFrame); m_pFrame = CreatePageFrame(); if (!m_pFrame) { ASSERT(FALSE); AfxThrowMemoryException(); } m_pFrame->Create(WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS, rectFrame, this, 0xFFFF); m_pFrame->ShowCaption(m_bPageCaption); // Lets make place for the tree ctrl const int nTreeWidth = m_nPageTreeWidth; const int nTreeSpace = 5; CRect rectSheet; GetWindowRect(rectSheet); rectSheet.right+= nTreeWidth; SetWindowPos(NULL, -1, -1, rectSheet.Width(), rectSheet.Height(), SWP_NOZORDER|SWP_NOMOVE); CenterWindow(); MoveChildWindows(nTreeWidth, 0); // Lets calculate the rectangle for the tree ctrl CRect rectTree(rectFrame); rectTree.right = rectTree.left + nTreeWidth - nTreeSpace; // calculate caption height CTabCtrl wndTabCtrl; wndTabCtrl.Create(WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS, rectFrame, this, 0x1234); wndTabCtrl.InsertItem(0, _T("")); CRect rectFrameCaption; wndTabCtrl.GetItemRect(0, rectFrameCaption); wndTabCtrl.DestroyWindow(); m_pFrame->SetCaptionHeight(rectFrameCaption.Height()); // if no caption should be displayed, make the window smaller in // height if (!m_bPageCaption) { // make frame smaller m_pFrame->GetWnd()->GetWindowRect(rectFrame); ScreenToClient(rectFrame); rectFrame.top+= rectFrameCaption.Height(); m_pFrame->GetWnd()->MoveWindow(rectFrame); // move all child windows up MoveChildWindows(0, -rectFrameCaption.Height()); // modify rectangle for the tree ctrl rectTree.bottom-= rectFrameCaption.Height(); // make us smaller CRect rect; GetWindowRect(rect); rect.top+= rectFrameCaption.Height()/2; rect.bottom-= rectFrameCaption.Height()-rectFrameCaption.Height()/2; if (GetParent()) GetParent()->ScreenToClient(rect); MoveWindow(rect); } // finally create tht tree control const DWORD dwTreeStyle = TVS_SHOWSELALWAYS|TVS_TRACKSELECT|TVS_HASLINES|TVS_LINESATROOT|TVS_HASBUTTONS; m_pwndPageTree = CreatePageTreeObject(); if (!m_pwndPageTree) { ASSERT(FALSE); AfxThrowMemoryException(); } ((CWnd*)m_pwndPageTree)->CreateEx( WS_EX_CLIENTEDGE|WS_EX_NOPARENTNOTIFY, _T("SysTreeView32"), _T("PageTree"), WS_TABSTOP|WS_CHILD|WS_VISIBLE|dwTreeStyle, rectTree, this, s_unPageTreeId); //// MFC7-support here (Thanks to Rainer Wollgarten) //#if _MFC_VER >= 0x0700 //{ // m_pwndPageTree->CreateEx( // WS_EX_CLIENTEDGE|WS_EX_NOPARENTNOTIFY, // WS_TABSTOP|WS_CHILD|WS_VISIBLE|dwTreeStyle, // rectTree, this, s_unPageTreeId); //} //#else //{ // m_pwndPageTree->CreateEx( // WS_EX_CLIENTEDGE|WS_EX_NOPARENTNOTIFY, // _T("SysTreeView32"), _T("PageTree"), // WS_TABSTOP|WS_CHILD|WS_VISIBLE|dwTreeStyle, // rectTree, this, s_unPageTreeId); //} //#endif if (m_bTreeImages) { m_pwndPageTree->SetImageList(&m_Images, TVSIL_NORMAL); m_pwndPageTree->SetImageList(&m_Images, TVSIL_STATE); } // Fill the tree ctrl RefillPageTree(); // Select item for the current page if (pTab->GetCurSel() > -1) SelectPageTreeItem(pTab->GetCurSel()); // Expand all tree items HTREEITEM hCurrent = m_pwndPageTree->GetNextItem(NULL, TVGN_FIRSTVISIBLE); while (hCurrent != NULL) { m_pwndPageTree->Expand(hCurrent, TVE_EXPAND); hCurrent = m_pwndPageTree->GetNextItem(hCurrent, TVGN_NEXT); } return bResult; }
BOOL CPageImageProcess::OnInitDialog() { CDialogEx::OnInitDialog(); // TODO: 在此添加额外的初始化 GetClientRect(&m_rect); CRect rectClient; this->GetOwner()->GetClientRect(&rectClient); CTabCtrl *pTab = (CTabCtrl *)this->GetOwner(); CRect rcHead; pTab->GetItemRect(0,&rcHead); rectClient.top += rcHead.Height() + 2; rectClient.left += 2; rectClient.right -= 2; rectClient.bottom -= 2; MoveWindow(rectClient); // Button m_BtnUndo.SubclassDlgItem(ID_EDIT_UNDO,this); m_BtnUndo.SetTooltipText(_T("撤销")); m_BtnFitWindow.SubclassDlgItem(IDC_BTN_FIT_WINDOW,this); m_BtnFitWindow.SetTooltipText(_T("适屏")); m_BtnZoomIn.SubclassDlgItem(IDC_BTN_ZOOM_IN,this); m_BtnZoomIn.SetTooltipText(_T("放大")); m_BtnZoom11.SubclassDlgItem(IDC_BTN_ZOOM_11,this); m_BtnZoom11.SetTooltipText(_T("实际大小")); m_BtnZoomOut.SubclassDlgItem(IDC_BTN_ZOOM_OUT,this); m_BtnZoomOut.SetTooltipText(_T("缩小")); m_BtnRotateLeft.SubclassDlgItem(IDC_BTN_ROTATE_LEFT,this); m_BtnRotateLeft.SetTooltipText(_T("左转90度")); m_BtnRotateRight.SubclassDlgItem(IDC_BTN_ROTATE_RIGHT,this); m_BtnRotateRight.SetTooltipText(_T("右转90度")); m_BtnRotate.SubclassDlgItem(IDC_BTN_ROTATE,this); m_BtnRotate.SetTooltipText(_T("任意角度旋转")); m_BtnMirror.SubclassDlgItem(IDC_BTN_MIRROR,this); m_BtnMirror.SetTooltipText(_T("左右镜像")); m_BtnFlip.SubclassDlgItem(IDC_BTN_FLIP,this); m_BtnFlip.SetTooltipText(_T("上下翻转")); // m_BtnMove.SubclassDlgItem(IDC_BTN_MOVE,this); m_BtnMove.SetTooltipText(_T("移动")); m_BtnMove.SetCheckBox(); m_BtnSelect.SubclassDlgItem(IDC_BTN_SELECT,this); m_BtnSelect.SetTooltipText(_T("选择")); m_BtnSelect.SetCheckBox(); m_BtnZoom.SubclassDlgItem(IDC_BTN_ZOOM,this); m_BtnZoom.SetTooltipText(_T("缩放")); m_BtnZoom.SetCheckBox(); m_BtnLine.SubclassDlgItem(IDC_BTN_LINE,this); m_BtnLine.SetTooltipText(_T("画直线")); m_BtnLine.SetCheckBox(); m_BtnRect.SubclassDlgItem(IDC_BTN_RECT,this); m_BtnRect.SetTooltipText(_T("画矩形")); m_BtnRect.SetCheckBox(); m_BtnEllipse.SubclassDlgItem(IDC_BTN_ELLIPSE,this); m_BtnEllipse.SetTooltipText(_T("画椭圆")); m_BtnEllipse.SetCheckBox(); m_BtnDist.SubclassDlgItem(IDC_BTN_DIST,this); m_BtnDist.SetTooltipText(_T("测距")); m_BtnDist.SetCheckBox(); m_BtnDegree.SubclassDlgItem(IDC_BTN_DEGREE,this); m_BtnDegree.SetTooltipText(_T("量角")); m_BtnDegree.SetCheckBox(); m_BtnText.SubclassDlgItem(IDC_BTN_TEXT,this); m_BtnText.SetTooltipText(_T("文字")); m_BtnText.SetCheckBox(); // m_BtnNegative.SubclassDlgItem(IDC_BTN_NEGATIVE,this); m_BtnNegative.SetTooltipText(_T("负片")); m_BtnThreshold.SubclassDlgItem(IDC_BTN_THRESHOLD,this); m_BtnThreshold.SetTooltipText(_T("阈值")); m_BtnMean.SubclassDlgItem(IDC_BTN_MEAN,this); m_BtnMean.SetTooltipText(_T("均值滤波")); m_BtnMedian.SubclassDlgItem(IDC_BTN_MEDIAN,this); m_BtnMedian.SetTooltipText(_T("中值滤波")); m_BtnGauss.SubclassDlgItem(IDC_BTN_GAUSS,this); m_BtnGauss.SetTooltipText(_T("高斯滤波")); m_BtnEnhance.SubclassDlgItem(IDC_BTN_ENHANCE,this); m_BtnEnhance.SetTooltipText(_T("增强")); m_SliderGamma.SetRange(0,89); m_SliderGamma.SetTicFreq(10); double angle = atan(m_dbEditGamma); m_SliderGamma.SetPos((int)DEGREE(angle)); m_Gamma.SetGamma(m_dbEditGamma); return TRUE; // return TRUE unless you set the focus to a control // 异常: OCX 属性页应返回 FALSE }
BOOL CTreePropSheet::OnInitDialog() { if (m_bTreeViewMode) { // be sure, there are no stacked tabs, because otherwise the // page caption will be to large in tree view mode EnableStackedTabs(FALSE); // Initialize image list. if (m_DefaultImages.GetSafeHandle()) { IMAGEINFO ii; m_DefaultImages.GetImageInfo(0, &ii); m_Images.Create(ii.rcImage.right - ii.rcImage.left, ii.rcImage.bottom - ii.rcImage.top, ILC_COLOR32 | ILC_MASK, 0, 1); } else m_Images.Create(16, 16, ILC_COLOR32 | ILC_MASK, 0, 1); } // perform default implementation BOOL bResult = CPropertySheet::OnInitDialog(); if (!m_bTreeViewMode) // stop here, if we would like to use tabs return bResult; // Get tab control... CTabCtrl* pTab = GetTabControl(); if (!IsWindow(pTab->GetSafeHwnd())) { ASSERT(FALSE); return bResult; } HighColorTab::UpdateImageList(*this); // ... and hide it pTab->ShowWindow(SW_HIDE); pTab->EnableWindow(FALSE); // Place another (empty) tab ctrl, to get a frame instead CRect rectFrame; pTab->GetWindowRect(rectFrame); ScreenToClient(rectFrame); m_pFrame = CreatePageFrame(); if (!m_pFrame) { ASSERT(FALSE); AfxThrowMemoryException(); } m_pFrame->Create(WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS, rectFrame, this, 0xFFFF); m_pFrame->ShowCaption(m_bPageCaption); // Lets make place for the tree ctrl const int nTreeWidth = m_nPageTreeWidth; const int nTreeSpace = 5; CRect rectSheet; GetWindowRect(rectSheet); rectSheet.right += nTreeWidth; SetWindowPos(NULL, 0, 0, rectSheet.Width(), rectSheet.Height(), SWP_NOZORDER | SWP_NOMOVE); CenterWindow(); MoveChildWindows(nTreeWidth, 0); // Lets calculate the rectangle for the tree ctrl CRect rectTree(rectFrame); rectTree.right = rectTree.left + nTreeWidth - nTreeSpace; // calculate caption height CTabCtrl wndTabCtrl; wndTabCtrl.Create(WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS, rectFrame, this, 0x1234); wndTabCtrl.InsertItem(0, _T("")); CRect rectFrameCaption; wndTabCtrl.GetItemRect(0, rectFrameCaption); wndTabCtrl.DestroyWindow(); m_pFrame->SetCaptionHeight(rectFrameCaption.Height()); // if no caption should be displayed, make the window smaller in // height if (!m_bPageCaption) { // make frame smaller m_pFrame->GetWnd()->GetWindowRect(rectFrame); ScreenToClient(rectFrame); rectFrame.top+= rectFrameCaption.Height(); m_pFrame->GetWnd()->MoveWindow(rectFrame); // move all child windows up MoveChildWindows(0, -rectFrameCaption.Height()); // modify rectangle for the tree ctrl rectTree.bottom-= rectFrameCaption.Height(); // make us smaller CRect rect; GetWindowRect(rect); rect.top+= rectFrameCaption.Height()/2; rect.bottom-= rectFrameCaption.Height()-rectFrameCaption.Height()/2; if (GetParent()) GetParent()->ScreenToClient(rect); MoveWindow(rect); // Need to center window again to reflect the missing caption bar (noticeable on 640x480 resolutions) CenterWindow(); } // finally create the tree control //const DWORD dwTreeStyle = TVS_SHOWSELALWAYS/*|TVS_TRACKSELECT*/|TVS_HASLINES/*|TVS_LINESATROOT*/|TVS_HASBUTTONS; // As long as we don't use sub pages we apply the 'TVS_FULLROWSELECT' style for a little more user convinience. const DWORD dwTreeStyle = TVS_SHOWSELALWAYS | TVS_FULLROWSELECT | TVS_NOHSCROLL; m_pwndPageTree = CreatePageTreeObject(); if (!m_pwndPageTree) { ASSERT(FALSE); AfxThrowMemoryException(); } // MFC7-support here (Thanks to Rainer Wollgarten) #if _MFC_VER >= 0x0700 { // Using 'CTreeCtrl::CreateEx' (and it's indeed a good idea to call this one), results in // flawed window styles (border is missing) when running under WinXP themed.. ??? //m_pwndPageTree->CreateEx( // WS_EX_CLIENTEDGE|WS_EX_NOPARENTNOTIFY, // WS_TABSTOP|WS_CHILD|WS_VISIBLE|dwTreeStyle, // rectTree, this, s_unPageTreeId); // Feel free to explain to me why we need to call CWnd::CreateEx to get the proper window style // for the tree view control when running under WinXP. Look at CTreeCtrl::CreateEx and CWnd::CreateEx to // see the (minor) difference. However, this could create problems in future MFC versions.. m_pwndPageTree->CWnd::CreateEx( WS_EX_CLIENTEDGE|WS_EX_NOPARENTNOTIFY, WC_TREEVIEW, _T("PageTree"), WS_TABSTOP|WS_CHILD|WS_VISIBLE|dwTreeStyle, rectTree, this, s_unPageTreeId); } #else { m_pwndPageTree->CreateEx( WS_EX_CLIENTEDGE|WS_EX_NOPARENTNOTIFY, _T("SysTreeView32"), _T("PageTree"), WS_TABSTOP|WS_CHILD|WS_VISIBLE|dwTreeStyle, rectTree, this, s_unPageTreeId); } #endif // This treeview control was created dynamically, thus it does not derive the font // settings from the parent dialog. Need to set the font explicitly so that it fits // to the font which is used for the property pages. m_pwndPageTree->SendMessage(WM_SETFONT, (WPARAM)AfxGetMainWnd()->GetFont()->m_hObject, TRUE); m_pwndPageTree->SetItemHeight(m_pwndPageTree->GetItemHeight() + 6); if (m_bTreeImages) { m_pwndPageTree->SetImageList(&m_Images, TVSIL_NORMAL); m_pwndPageTree->SetImageList(&m_Images, TVSIL_STATE); } // Fill the tree ctrl RefillPageTree(); // Select item for the current page if (pTab->GetCurSel() > -1) SelectPageTreeItem(pTab->GetCurSel()); return bResult; }
//**************************************************************************************** BOOL CBCGPropertySheet::OnInitDialog() { BOOL bResult = CPropertySheet::OnInitDialog(); BOOL bReposButtons = FALSE; const int nVertMargin = 5; const int nHorzMargin = 5; CWnd* pWndNavigator = InitNavigationControl (); CRect rectClient; GetClientRect (rectClient); if (m_wndTab.GetSafeHwnd () != NULL) { CTabCtrl* pTab = GetTabControl (); ASSERT_VALID (pTab); CRect rectTab; pTab->GetWindowRect (rectTab); ScreenToClient (rectTab); rectTab.InflateRect (2, 0); if (pTab->GetItemCount () > 0) { CRect rectTabsNew; m_wndTab.GetTabsRect (rectTabsNew); CRect rectTabsOld; pTab->GetItemRect (0, rectTabsOld); const int nOldHeight = rectTabsOld.Height (); const int nNewHeight = rectTabsNew.Height (); if (nNewHeight > nOldHeight) { rectClient.bottom += nNewHeight - nOldHeight + nVertMargin; rectTab.bottom += nNewHeight - nOldHeight; SetWindowPos (NULL, -1, -1, rectClient.Width (), rectClient.Height (), SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE); } } m_wndTab.MoveWindow (rectTab); pTab->ModifyStyle (WS_TABSTOP, 0); pTab->ShowWindow (SW_HIDE); if (pTab->GetItemCount () > 0) { m_wndTab.SetActiveTab (0); } bReposButtons = TRUE; } else if (pWndNavigator != NULL) { CTabCtrl* pTab = GetTabControl (); ASSERT_VALID (pTab); pTab->ModifyStyle (WS_TABSTOP, 0); CRect rectTabItem; pTab->GetItemRect (0, rectTabItem); pTab->MapWindowPoints (this, &rectTabItem); const int nTabsHeight = rectTabItem.Height () + nVertMargin; SetWindowPos (NULL, -1, -1, rectClient.Width () + m_nBarWidth, rectClient.Height () - nTabsHeight + 4 * nVertMargin, SWP_NOZORDER | SWP_NOMOVE | SWP_NOACTIVATE); GetClientRect (rectClient); pTab->MoveWindow (m_nBarWidth, -nTabsHeight, rectClient.right, rectClient.bottom - 2 * nVertMargin); CRect rectTab; pTab->GetWindowRect (rectTab); ScreenToClient (rectTab); CRect rectNavigator = rectClient; rectNavigator.right = rectNavigator.left + m_nBarWidth; rectNavigator.bottom = rectTab.bottom; rectNavigator.DeflateRect (1, 1); pWndNavigator->SetWindowPos (&wndTop, rectNavigator.left, rectNavigator.top, rectNavigator.Width (), rectNavigator.Height (), SWP_NOACTIVATE); SetActivePage (GetActivePage ()); bReposButtons = TRUE; } if (bReposButtons) { int ids[] = { IDOK, IDCANCEL, ID_APPLY_NOW, IDHELP }; int nTotalButtonsWidth = 0; for (int iStep = 0; iStep < 2; iStep++) { for (int i = 0; i < sizeof (ids) / sizeof (ids [0]); i++) { CWnd* pButton = GetDlgItem (ids[i]); if (pButton != NULL) { if (ids [i] == IDHELP && (m_psh.dwFlags & PSH_HASHELP) == 0) { continue; } if (ids [i] == ID_APPLY_NOW && (m_psh.dwFlags & PSH_NOAPPLYNOW)) { continue; } CRect rectButton; pButton->GetWindowRect (rectButton); ScreenToClient (rectButton); if (iStep == 0) { // Align buttons at the bottom pButton->SetWindowPos (&wndTop, rectButton.left, rectClient.bottom - rectButton.Height () - nVertMargin, -1, -1, SWP_NOSIZE | SWP_NOACTIVATE); nTotalButtonsWidth = rectButton.right; } else { // Right align the buttons pButton->SetWindowPos (&wndTop, rectButton.left + rectClient.right - nTotalButtonsWidth - nHorzMargin, rectButton.top, -1, -1, SWP_NOSIZE | SWP_NOACTIVATE); } } } } } return bResult; }
BOOL CTreePropSheetBase::OnInitDialog() { if (m_bTreeViewMode && !IsWizardMode() ) { // Fix suggested by Przemek Miszczuk // http://www.codeproject.com/property/TreePropSheetEx.asp?msg=1024928#xx1024928xx TreePropSheet::CIncrementScope RefillingPageTreeContentGuard(m_nRefillingPageTreeContent ); // be sure, there are no stacked tabs, because otherwise the // page caption will be to large in tree view mode EnableStackedTabs(FALSE); // Initialize image list. if (m_DefaultImages.GetSafeHandle()) { IMAGEINFO ii; m_DefaultImages.GetImageInfo(0, &ii); if (ii.hbmImage) DeleteObject(ii.hbmImage); if (ii.hbmMask) DeleteObject(ii.hbmMask); m_Images.Create(ii.rcImage.right-ii.rcImage.left, ii.rcImage.bottom-ii.rcImage.top, ILC_COLOR32|ILC_MASK, 0, 1); } else m_Images.Create(16, 16, ILC_COLOR32|ILC_MASK, 0, 1); } // perform default implementation BOOL bResult = CPropertySheet::OnInitDialog(); // If in wizard mode, stop here. if( IsWizardMode() ) return bResult; // Get tab control... CTabCtrl *pTab = GetTabControl(); if (!IsWindow(pTab->GetSafeHwnd())) { ASSERT(FALSE); return bResult; } // HighColorTab::UpdateImageList to change the internal image list to 24 bits colors) HighColorTab::UpdateImageList( *this ); // If not in tree mode, stop here. if (!m_bTreeViewMode) // stop here, if we would like to use tabs return bResult; // ... and hide it pTab->ShowWindow(SW_HIDE); pTab->EnableWindow(FALSE); // Place another (empty) tab ctrl, to get a frame instead CRect rectFrame; pTab->GetWindowRect(rectFrame); ScreenToClient(rectFrame); m_pFrame = CreatePageFrame(); if (!m_pFrame) { ASSERT(FALSE); AfxThrowMemoryException(); } m_pFrame->Create(WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS, rectFrame, this, 0xFFFF); m_pFrame->ShowCaption(m_bPageCaption); // Lets make place for the tree ctrl const int nTreeWidth = m_nPageTreeWidth; CRect rectSheet; GetWindowRect(rectSheet); rectSheet.right+= nTreeWidth; SetWindowPos(NULL, -1, -1, rectSheet.Width(), rectSheet.Height(), SWP_NOZORDER|SWP_NOMOVE); CenterWindow(); MoveChildWindows(nTreeWidth, 0); // Lets calculate the rectangle for the tree ctrl CRect rectTree(rectFrame); rectTree.right = rectTree.left + nTreeWidth - m_nSeparatorWidth; // calculate caption height CTabCtrl wndTabCtrl; wndTabCtrl.Create(WS_CHILD|WS_VISIBLE|WS_CLIPSIBLINGS, rectFrame, this, 0x1234); wndTabCtrl.InsertItem(0, _T("")); CRect rectFrameCaption; wndTabCtrl.GetItemRect(0, rectFrameCaption); wndTabCtrl.DestroyWindow(); m_pFrame->SetCaptionHeight(rectFrameCaption.Height()); // if no caption should be displayed, make the window smaller in // height if (!m_bPageCaption) { // make frame smaller m_pFrame->GetWnd()->GetWindowRect(rectFrame); ScreenToClient(rectFrame); rectFrame.top+= rectFrameCaption.Height(); m_pFrame->GetWnd()->MoveWindow(rectFrame); // move all child windows up MoveChildWindows(0, -rectFrameCaption.Height()); // modify rectangle for the tree ctrl rectTree.bottom-= rectFrameCaption.Height(); // make us smaller CRect rect; GetWindowRect(rect); rect.top+= rectFrameCaption.Height()/2; rect.bottom-= rectFrameCaption.Height()-rectFrameCaption.Height()/2; if (GetParent()) GetParent()->ScreenToClient(rect); MoveWindow(rect); CenterWindow(); } // finally create the tree control const DWORD dwTreeStyle = TVS_SHOWSELALWAYS|TVS_TRACKSELECT|TVS_HASLINES|TVS_LINESATROOT|TVS_HASBUTTONS; m_pwndPageTree = CreatePageTreeObject(); if (!m_pwndPageTree) { ASSERT(FALSE); AfxThrowMemoryException(); } // MFC7-support here (Thanks to Rainer Wollgarten) // YT: Cast tree control to CWnd and calls CWnd::CreateEx in all cases (VC 6 and7). ((CWnd*)m_pwndPageTree)->CreateEx( WS_EX_CLIENTEDGE|WS_EX_NOPARENTNOTIFY, _T("SysTreeView32"), _T("PageTree"), WS_TABSTOP|WS_CHILD|WS_VISIBLE|dwTreeStyle, rectTree, this, s_unPageTreeId); if (m_bTreeImages) { m_pwndPageTree->SetImageList(&m_Images, TVSIL_NORMAL); m_pwndPageTree->SetImageList(&m_Images, TVSIL_STATE); } // TreePropSheetEx: Fix refresh problem. // Fill the tree ctrl { TreePropSheet::CWindowRedrawScope WindowRedrawScope( m_pwndPageTree, true ); // Populate the tree control. RefillPageTree(); // Expand the tree if necessary. if( IsAutoExpandTree() ) { ExpandTreeItem( m_pwndPageTree, m_pwndPageTree->GetRootItem(), TVE_EXPAND ); } // Select item for the current page if (pTab->GetCurSel() > -1) SelectPageTreeItem(pTab->GetCurSel()); } return bResult; }