CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2002
    Posts
    8

    Question CPropertySheet with vertical pages

    Hello,

    How can I properly create and use a CPropertySheet object with vertically arranged pages?

    Here I've uploaded a demo project with source code included. It's just a simple SDI application which has main view class CVerticalPropSheetView (derived from CView) containing property sheet CPropSheetDemo (derived from CPropertySheet) with 3 property pages:

    http://forum.codenet.ru/attachment.p...1&d=1173007311
    http://www.rsdn.ru:80/File/35531/VerticalPropSheet.rar

    I tried to follow the advice from one of topics at CodeGuru forum (http://www.codeguru.com/forum/archiv.../t-331500.html) however, I've discovered the following issues related to resizing of the property sheet's window in CVerticalPropSheetView::OnSize():

    1) When changing size of CPropSheetDemo window so that its width is less than its height, the tabs of the bottom property pages are not properly drawn. It looks like only rectangle part of property sheet (width x width) is being drawn properly.

    2) When changing height of CPropertySheet window so that it can't display all tabs, the spin control is displayed. However, it doesn't work (I can't choose tab using spin control).

    Does anyone know how to resolve these issues? All above appears only when property pages are arranged vertically - e.g. until I comment the following lines of code in CPropSheetDemo::OnInitDialog():


    // create the new font for property pages' titles
    CreateNewFont(&m_Font,14,_T("Microsoft Sans Serif"));

    // make our property sheet vertical-oriented
    CWnd* pctrlTab=GetDlgItem(AFX_IDC_TAB_CONTROL);
    if (pctrlTab!=NULL) {
    pctrlTab->ModifyStyle(TCS_FOCUSONBUTTONDOWN,TCS_VERTICAL,0);
    pctrlTab->SetFont(&m_Font);
    }


    Many thanks in advance!

    dp
    See you.

  2. #2
    Join Date
    Jun 2002
    Posts
    8

    Re: CPropertySheet with vertical pages

    Does anybody know how to resolve this issue? Still can't find an answer.
    See you.

  3. #3
    John E is offline Elite Member Power Poster
    Join Date
    Apr 2001
    Location
    Manchester, England
    Posts
    4,867

    Re: CPropertySheet with vertical pages

    I don't know if this article might help you. It's a Windows Tab Control that supports tabs in any orientation. Apparently it only works for Windows XP - and even then, only with XP Themes enabled.

    Have you thought about what should happen if your property sheet needed more tabs than would fit in a single row? Horizontal property pages cater for this automatically but vertical tabs are possibly going to be more trouble than they're worth.
    "A problem well stated is a problem half solved.” - Charles F. Kettering

  4. #4
    Join Date
    Jun 2002
    Posts
    8

    Resolved Re: CPropertySheet with vertical pages

    John,

    Thank you for pointing out this interesting article. I've flicked through it and find it is rather useful. Although, I have no idea how to use custom Tab Control with the MFC CPropertySheet class (?).

    After getting no answer to my question, I decided to look at the MFC source code for CPropertySheet. Hell, I should have beed done this before posting my question. It's pretty straightforward and I've discovered that the problem is apparently related to the mutual incompatibility between the flags TCS_VERTICAL and TCS_SINGLELINE (scrolling property pages). So, I've just removed EnableStackedTabs(FALSE) in the constructor of my class CPropSheetDemo derived from CPropertySheet and modified OnSize() handler to get it working the way I want:

    Code:
    void CPropSheetDemo::OnSize(UINT nType, int cx, int cy) 
    {
    	CPropertySheet::OnSize(nType, cx, cy);
    	
    	// TODO: Add your message handler code here
    
    	// let's resize this property sheet and all embedded property pages
    	if ((nType!=SIZE_MINIMIZED) && (cx!=0) && (cy!=0)) {
    		CRect rect,rect2;
    		CTabCtrl* pTab;
    		CPropertyPage* pPage;
    		// change size of CTabCtrl
    		if (pTab=GetTabControl()) {
    			int iWidthHeight;
    			GetClientRect(&rect);
    			// calculate and set maximal width or height of the tab's bookmarks
    			if (GetWindowLong(pTab->m_hWnd,GWL_STYLE) & TCS_VERTICAL)
    				iWidthHeight=rect.Height()/PROPSHEET_DEMO_PAGES_COUNT;
    			else
    				iWidthHeight=rect.Width()/PROPSHEET_DEMO_PAGES_COUNT;
    			if (iWidthHeight>2) iWidthHeight-=2;
    			pTab->SetMinTabWidth(iWidthHeight);
    
    			// change tab control size
    			pTab->MoveWindow(&rect,TRUE);
    
    			// change size of Property Page
    			if (pPage=GetActivePage()) {
    				// top coordinate will probably stay the same
    				rect.left=0;
    				rect.top=0;
    				int n=pTab->GetItemCount();
    				// top-left coordinates will probably stay the same
    				if (GetWindowLong(pTab->m_hWnd,GWL_STYLE) & TCS_VERTICAL) {
    					for (int i=0;i<n;i++) {
    						pTab->GetItemRect(i,&rect2);
    						if (rect.left<rect2.right) rect.left=rect2.right;
    					}
    				// get the new top coordinate if tab is horizontally oriented
    				} else {
    					for (int i=0;i<n;i++) {
    						pTab->GetItemRect(i,&rect2);
    						if (rect.top<rect2.bottom) rect.top=rect2.bottom;
    					}
    				}
    				// get new right-bottom coordinates
    				pTab->GetClientRect(&rect2);
    				rect.right=rect2.right;
    				rect.bottom=rect2.bottom;
    				if (rect.right>2) rect.right-=2;
    				if (rect.bottom>2) rect.bottom-=2;
    				if (rect.left+2<rect.right) rect.left+=2;
    				if (rect.top+2<rect.bottom) rect.top+=2;
    				// change the size of tab control
    				pPage->MoveWindow(&rect,FALSE);
    			}
    		}
    	}
    }
    See you.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured