Question

MFC Dialog Application and TabControls

Asked by: npuleio

Hello everyone!!

I created a MFC Application based on Dialog forms. I put a Tab Control component from Toolbox, implemented an OnSize event so the tabcontrol fits the dialog when maximized and viceversa.
So I created four CDialog class templates where I put different controls, then I added four pages to the Tab Control with a page array where each page is template-based:

CDialog* m_dlg[4];
m_dlg[0] = new TEMPLATE_PAGE_1;
m_dlg[2] = new TEMPLATE_PAGE_2;

and so on...

and I created also a ShowTabDlg function to hide all templates and show the current when changing pages.

void MAINDLG::ShowTabDlg(int TabSel)
{
   for(int idx=0; idx < ARRAYSIZE(m_dlg); idx++)
       m_dlg[idx]->ShowWindow(SW_HIDE);

   CRect rc;
   pTabDlg->GetClientRect(rc);
   pTabDlg->AdjustRect(FALSE, rc);
   pTabDlg->ClientToScreen(rc);
   m_dlg[tabSel]->SetWindowPos(NULL, rc.left, rc.top, 0, 0, SWP_NOZORDER|SWP_NOSIZE|SWP_SHOWWINDOW|SWP_NOACTIVATE);
}

and a OnSize (related to WM_SIZE message and ON_WM_SIZE() on begin_message_map) always for each tabpage:

void TEMPLATE_PAGE_1::OnSize(UINT nType, int cx, int cy)
{
   CDialog::OnSize(nType, cx, cy);

   CWnd* pWnd = GetDlgItem(IDC_TABPAGE1);
   if (pWnd)
   {
      CRect rect;
      pWnd->GetWindowRect(rect);
      ScreenToClient(rect);
      rect.right = cx - rect.left;
      rect.bottom = cy - 10;
      pWnd->MoveWindow(rect);
   }
}

BUT I couldn't get those CDialog templates fit in each TabPage....it goes like in the bottom-right of the main window if main CDialog isn't maximized and when maximized it goes indeed at almost the top-left of the tabcontrol... what could I have missed?...Any suggest?...

Thanks in advance to all!
Ciao,
Luigi

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2009-09-15 at 08:08:39ID24733195
Tags

MFC Dialog Application

,

Tab Control

Topic

Windows MFC Programming

Participating Experts
3
Points
125
Comments
27

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Linking in MFC Extension DLL's
    Environment Visual C++ 5.0, NT 4.0 I am having trouble getting two MFC extension DLL's to link together. I have an extension DLL that contains a view and various functions and classes for that view. If I link this to an MFC EXE, all is fine. However I want to link this to a...
  2. MFC
    We use ON_WM_PAINT() macro to invoke the handler OnPaint(),similarly we use OnDraw(CDC *pDC) which the MFC frame work calls , what is the basic difference between these to calls ?
  3. "Loose" the HWND of Cwnd in MFC ???
    Hi EXPERTS in MFC! I don't know for what reason (after m_cList1 handle it)the HWND of CWnd is 0? Please help me. Here is the code : void CSeeResultDlg::OnDblclkList1() { int LIndex; char FisName; char *Name; LPCTSTR myRez; //HWND hWnd; ...
  4. Menu Items are disabled. MFC?
    I am new to MFC. I just created a menu (by modifying MFC's default SDI menu). When I test-run the program, a bunch of my newly created menu items (selected seemingly arbitrarily) come out DISABLED. Does anyone know why? I searched the program's files for calls to EnableMenuIt...
  5. MFC Application
    I am developing an MFC based application using Visual studio .NET ( VC++) Applications are running fine!!! But the application is exiting when i press the "Enter" Button. Is there any way that i can remove this "feature"...??? I want only the application ...
  6. MFC Project
    sa you know i'm working on ctapiconnection sample in MSDN but i need help so ....................................... now i have now error in my code but all my code i had wrote was in (console application) and as you know i can't make a design with this kind of project ....

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: AndyAinscowPosted on 2009-09-15 at 10:01:59ID: 25336978

Why don't you use CPropertySheet and CPropertyPage instead of trying to do it yourself?

 

by: pgnatyukPosted on 2009-09-15 at 11:07:25ID: 25337556

You work with WM_SIZE message. Try to switch to WM_WINDOWPOSCHANGED. I do remember the same problem even in the app with the property pages.
Win32 API: http://msdn.microsoft.com/en-us/library/ms632652(VS.85).aspx

I attached a handler for this message.  

MFC CWnd::OnWindowPosChanged  http://msdn.microsoft.com/en-us/library/cs9c0kfx(VS.80).aspx

you can add ON_WM_WINDOWPOSCHANGED()

Here are few example:

http://www.codeguru.com/cpp/cpp/cpp_mfc/print.php/c4127

http://www.ucancode.net/Visual_C_Codes/MFC-Article-Keep-%20Window-Always-on-Top-WS_EX_TOPMOST-OnWindowPosChanged.htm

Anyway, it is much better to the property pages as AndyAinscow said.

I found an example

http://www.codeproject.com/KB/tabs/propview.aspx?fid=3570&df=90&mpp=25&noise=3&sort=Position&view=Quick

There is WM_WINDOWPOSCHANGING and it is about WTL. But it works exactly as you want.

void OnWindowPosChanged(HWND hwnd, const WINDOWPOS *pwp)
{
    if (pwp->flags & SWP_SHOWWINDOW) 
    {
       WindowWasShown();
    }
    if (pwp->flags & SWP_HIDEWINDOW) 
    {
       WindowWasHidden();
    }
    if (!(pwp->flags & SWP_NOMOVE)) 
    {
       WindowMovedTo(pwp->x, pwp->y);
    }
    if (!(pwp->flags & SWP_NOSIZE)) 
    {
       WindowResizedTo(pwp->cx, pwp->cy);
    }
}
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:

Select allOpen in new window

 

by: AndyAinscowPosted on 2009-09-15 at 11:15:19ID: 25337636

I must qualify and modify my comment - the 'all' was too much.  The Propertysheet/page combination doesn't natively support changing the size - you would still have to do that yourself.
It does however handle all the creation/cleanup, initial sizing to fit the pages and swapping pages as the tab selection is changed.

 

by: LaindowPosted on 2009-09-15 at 18:56:19ID: 25341177

Hi,
 I have CPropertySheet component and resizing all pages for that component in OnWindowPosChanged. Sample below.

#include "stdafx.h"
#include "DialogE50Base.h" 

// CDialogE50Base dialog 
IMPLEMENT_DYNAMIC(CDialogE50Base, CDialog) 
//---------------------------------------------------------------------------------------------------
	CDialogE50Base::CDialogE50Base(CWnd* pParent /*=NULL*/, CObjInfo* poInfo, UINT uiTemplate )
		: CDialog(uiTemplate, pParent)
//---------------------------------------------------------------------------------------------------
{
	m_pResult = NULL; 
	m_iBottomBlankSize = 40;
	m_iTopBlankSize = 10;
	m_iWideBlankSize = 10; 
	m_poInfo = 0;
	//Make own copy of Info object
	if( poInfo != NULL )
	{
		m_poInfo = new CObjInfo();
		*m_poInfo = *poInfo;
	}
	m_bIsInitialized = false;
	//Create PropertySheet object
	m_poPropSheet = new CPropertySheet("Main PropertySheet");
} 
/////////////////////////////////////////////////////////////////// 
//--------------------------------------------------------------------------------------------------
BOOL CDialogE50Base::OnInitDialog()
//--------------------------------------------------------------------------------------------------
{
	CDialog::OnInitDialog(); 
	//Initialize and show PropertySheet
	DWORD dwStyle = WS_VISIBLE | WS_CHILD;
	DWORD dwExStyle = WS_EX_LEFT|WS_EX_CONTROLPARENT;
	m_poPropSheet->Create( this, dwStyle, dwExStyle );//DoModal();//Create( this ); 
	//Set input focus to the current page
	m_poPropSheet->SetActiveWindow(); 

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
} 
//--------------------------------------------------------------------------------------------------
	void CDialogE50Base::OnWindowPosChanged(WINDOWPOS* lpwndpos)
//--------------------------------------------------------------------------------------------------
{
	CDialog::OnWindowPosChanged(lpwndpos); 
	if( m_bIsInitialized )
	{
		//Get client area size
		RECT oClientRect;
		this->GetClientRect( &oClientRect );
		//Wide
		oClientRect.right = oClientRect.right - oClientRect.left - m_iWideBlankSize * 2;
		//Hieght
		oClientRect.bottom = oClientRect.bottom - oClientRect.top - m_iBottomBlankSize - m_iTopBlankSize; 
		//Set PropertySheet position
		m_poPropSheet->SetWindowPos( &CWnd::wndBottom, m_iWideBlankSize, m_iTopBlankSize, 
			 oClientRect.right,	oClientRect.bottom, NULL ); 
		//Set PropertySheet subcontrol position
		CTabCtrl* poControl = m_poPropSheet->GetTabControl();
		poControl->SetWindowPos( &CWnd::wndBottom, 0, 0, 
			oClientRect.right - GUI_BORDER_SIZE * 2,	oClientRect.bottom - GUI_BORDER_SIZE * 2,
			SWP_NOMOVE|SWP_NOZORDER ); 
		//Set PropertySheet page positions
		//All another pages will be repositioned than user change tab 
		CPropertyPage* poPage = m_poPropSheet->GetActivePage();
		if( poPage != NULL && poPage->m_hWnd != NULL )
		{
			poPage->SetWindowPos( &CWnd::wndBottom, 0, 0, 
					oClientRect.right - GUI_BORDER_SIZE * 4, oClientRect.bottom - GUI_BORDER_SIZE * 4 - GUI_TAB_HEADER_SIZE,
					SWP_NOMOVE|SWP_NOZORDER  );
		}
	}
} 
///.h file/////////////////////////////////////////////////
// CDialogE50Base dialog 
class CDialogE50Base : public CDialog
{
	DECLARE_DYNAMIC(CDialogE50Base) 
public:
	CDialogE50Base(CWnd* pParent = NULL, CObjInfo* poInfo = NULL, UINT uiTemplate = IDD );   // standard constructor
	virtual ~CDialogE50Base(); 
	void	*m_pResult; 
// Dialog Data
	enum { IDD = IDD_DLG_ADD_SERVER }; 
protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support 
	//Main tabcontrol
	CPropertySheet*         m_poPropSheet;
	//Indicate does GUI initialized or not
	bool					m_bIsInitialized;
	//Additional Info object
	CObjInfo*				m_poInfo; 
	//Constants for the PropertySheet position
	int						m_iBottomBlankSize;
	int						m_iTopBlankSize;
	int						m_iWideBlankSize; 

	DECLARE_MESSAGE_MAP()
public:
	virtual BOOL OnInitDialog();
	afx_msg void OnWindowPosChanged(WINDOWPOS* lpwndpos);
};
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:

Select allOpen in new window

 

by: npuleioPosted on 2009-09-16 at 03:24:26ID: 25343828

Hello everyone,

first thanks for these answers...as it looks like using CPropertySheet sounds simpler BUT since I have to create pages with components and stuffs, this CPropertySheet DOESN'T have a resource where I can design components or adding another Tab Control in a page...

In fact I tried to add a class based on CPropertySheet but in fact it didn't added a resource template where to design what I want to show in that page. I tried even to add manually an IDD_FORMVIEW resource then adding an enum { IDD = IDD_FORMVIEW } in the CPropertySheet's class but it didn't worked.

Except if you have suggests about how I can design those CPropertySheets, I'd continue to use dialog modeless templates...

Thanks again
Luigi

 

by: LaindowPosted on 2009-09-16 at 04:01:16ID: 25344099

Hi,
 I am easy add new pages templates to the CPropertySheet.
 I make pages in resource editor and add them to CPropertySheet.
 But remember you need to add them before use function Create.

//---------------------------------------------------------------------------------------------------
	int CViewChannel::InitializeData( CObjInfo* poInfo )
//---------------------------------------------------------------------------------------------------
{
	int iResult = R_FAIL;
	try
	{
		//Call parent initialization
		CViewE50Base::InitializeData( poInfo );
 
		m_pobjChannel = (CE50Channel*)m_poInfo->m_pValue;
 
		//Create and initialize Info 
		//Page will take Channel object from it Info to operate with them
		CObjInfo poPageInfo;
		poPageInfo.m_iCode = DEF_SERV_NODE_CODE;
		//poPageInfo.m_iID = C_VIEW_Channel;
		poPageInfo.m_pValue = m_pobjChannel;
 
		//Create and add Channel Tab
		m_pobjPageChannel = new CPageChannel( &poPageInfo );
		m_poPropSheet->AddPage( m_pobjPageChannel );
		//Create and add Trace Tab
		poPageInfo.m_pValue = &m_pobjChannel->m_objTrace;
		m_pobjPageTrace = new CPageTrace( &poPageInfo );
		m_poPropSheet->AddPage( m_pobjPageTrace );
 
 
		//Initialize and show PropertySheet
		DWORD dwStyle = WS_VISIBLE | WS_CHILD;
		DWORD dwExStyle = WS_EX_LEFT|WS_EX_CONTROLPARENT;
		m_poPropSheet->Create( this, dwStyle, dwExStyle );//DoModal();//Create( this );
 
		//Make latest tab active
		m_poPropSheet->SetActivePage( m_pobjChannel->m_iPageIndex );
		m_piPosHolder = &m_pobjChannel->m_iPageIndex;
 
 
		//Set Channel status fields
		SetChannelStatusFields();
 
		//Set initialization flag
		m_bIsInitialized = true;
 
		iResult = R_OK;
	}
	catch(...)
	{
		iResult = R_EXCEPTION;
	}
	return iResult;
}
///////////////////////////////////////////////////////////
// PageChannel dialog
 
class CPageChannel : public CPage
{
	DECLARE_DYNAMIC(CPageChannel)
 
public:
	CPageChannel( CObjInfo* poInfo );
	virtual ~CPageChannel();
 
	//Apply changes to the object
	virtual int				SaveData();
	//Set data modification status
	virtual void			SetModificationsStatus( bool bNewStatus = true );
 
// Dialog Data
	enum { IDD = IDD_PAGE_CHANNEL };
 
protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
 
	//Pointer to the server object for internal use
	CE50Channel*				m_pobjChannel;	
	//Set data fields
	virtual int InitData();
 
	//Check data validation
	virtual bool	CheckData();
 
	DECLARE_MESSAGE_MAP()
public:
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:

Select allOpen in new window

 

by: LaindowPosted on 2009-09-16 at 04:03:43ID: 25344108

m_poPropSheet - that CPropertySheet

      //Main tabcontrol
      CPropertySheet*         m_poPropSheet;

// CViewE50Base form view
 
class CViewE50Base : public CFormView
{
	DECLARE_DYNCREATE(CViewE50Base)
 
protected:
public:
	CViewE50Base( UINT uiTemplate = IDD );           // protected constructor used by dynamic creation
	virtual ~CViewE50Base();
 
public:
	//This flag indicate does user changed data or not
	virtual bool			IsDataModified();
	//Function to update user interface dynamicly
	virtual int				UpdateData( CObjInfo* poInfo );
	//Base initialization for each view
	virtual int				InitializeData( CObjInfo* poInfo );
 
 
// Dialog Data
   //{{AFX_DATA(CMyView)
    enum { IDD = IDD_EMPTY_VIEW };
   //}}AFX_DATA
 
#ifdef _DEBUG
	virtual void AssertValid() const;
#ifndef _WIN32_WCE
	virtual void Dump(CDumpContext& dc) const;
#endif
#endif
 
protected:
 
	//Additional information object
	CObjInfo*				m_poInfo;
	//Indicate does GUI initialized or not
	bool					m_bIsInitialized;
	//Main tabcontrol
	CPropertySheet*         m_poPropSheet;
 
	//Constants for the PropertySheet position
	int						m_iBottomBlankSize;
	int						m_iTopBlankSize;
	int						m_iWideBlankSize;
 
	//Address for position holder if object support it
	int*					m_piPosHolder;
 
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
 
	DECLARE_MESSAGE_MAP()
public:
	afx_msg void OnWindowPosChanged(WINDOWPOS* lpwndpos);
	virtual void OnInitialUpdate();
protected:
	virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView);
};
                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:

Select allOpen in new window

 

by: AndyAinscowPosted on 2009-09-16 at 04:16:35ID: 25344177

In resource editor select 'add new' then expand the dialog selection to give you IDD_PROPPAGE_LARGE (or MEDIUM or SMALL).  Now add controls as you would a normal dialog.
Once done then save it then add a new class based on this dialog, select CPropertyPage as the base class.

 

by: npuleioPosted on 2009-09-16 at 05:24:54ID: 25344784

So since I'm creating a tabbed stuff I have first to add a tabcontrol component in the CDialog main window then calling Create assigning the CWnd* pParentWnd to the IDC_TAB1, so it should be a tabcontrol page derived from CPropertyPage, right?

 

by: AndyAinscowPosted on 2009-09-16 at 05:40:31ID: 25344917

Design the pages in the resource editor.
Create the new (CPropertyPage) classes with the wizard.
Add class based on CPropertySheet



in .h file for sheet

CMyPropertySheet:CpropertySheet
{
....
CMyPage1 m_page1;
CMyPage2 m_page2;
}

in constructor for the sheet
CMyPropertySheet::CMyPropertySheet(...) : CPropertySheet(...)
{
AddPage(m_page1);
AddPage(m_page2);
...
}

done.  No need to use keywords like new or functions like Create

 

by: LaindowPosted on 2009-09-16 at 05:51:16ID: 25345010

Hi,
 1 ) you create CDialog main window
 2) you create CPropertySheet component for this dialog
 3) you make your page class delivered from CPage
        class CPageChannel : public CPage
       {
         DECLARE_DYNAMIC(CPageChannel)

         public:
               CPageChannel( CObjInfo* poInfo );
               virtual ~CPageChannel();
         // Dialog Data
               enum { IDD = IDD_PAGE_CHANNEL };
  4) you create your page class object and add it to PropertySheet object

            //Create and add Channel Tab
            m_pobjPageChannel = new CPageChannel( &poPageInfo );
            m_poPropSheet->AddPage( m_pobjPageChannel );
  5) you call Create function for CPropertySheet to initialize that object
            //Initialize and show PropertySheet
            DWORD dwStyle = WS_VISIBLE | WS_CHILD;
            DWORD dwExStyle = WS_EX_LEFT|WS_EX_CONTROLPARENT;
            m_poPropSheet->Create( this, dwStyle, dwExStyle );//DoModal();//Create( this );
    Don't forget to set EX_CONTROLPARENT flag - MFC have a bug your application will go to deadloop without that flag.
  6) you set positions for PropertySheet object and all pages
 All sample code how to do it you can see above. I just little bit modify standard classes constructors to make them more useful for my project. All code above from real project.

 

by: LaindowPosted on 2009-09-16 at 05:55:33ID: 25345042

You can also use way how AndyAinscow said. That fine too just don't let you control dialog like my way does. If you need to add some buttons or other components that will be hard - you can't just put them in into main dialog in resource editor.

 

by: npuleioPosted on 2009-09-16 at 07:32:48ID: 25345991

Thinking by classes and resources I created first an IDD_PROPPAGE_LARGE, set no border, no title bar and Style = Child. Then I added a Page_Config MFC class based on CPropertyPage naming it as the same of the resource so the Dialog ID would be the ID of the resource created before.
Then in the CDialog main window I included the class, I declared in .h class CPropertySheet* m_poPropSheet; and I added in OnInitDialog event:

CPage_Config* pageConfig = new CPage_Config();
m_poPropSheet->AddPage(pageConfig);
DWORD dwStyle = WS_VISIBLE | WS_CHILD;
DWORD dwExStyle = WS_EX_LEFT|WS_EX_CONTROLPARENT;
m_poPropSheet->Create(this, dwStyle, dwExStyle);

so it should create a single page tabbed sheets but it doesn't work.... wouldn't that be because it's a MFC Application?...

 

by: npuleioPosted on 2009-09-17 at 02:33:20ID: 25354182

Hi Laindow,

I sent you an email...let's see...

 

by: pgnatyukPosted on 2009-09-17 at 02:40:21ID: 25354213

The solution will be sent in the email too?
Guys, I think, you are doing soemthing wrong here.

 

by: npuleioPosted on 2009-09-17 at 02:48:15ID: 25354240

Nah, it's useful also to write solution here..just I sent email to let him see the code to indicate the right way to solve the problem since here it's looks it's going a bit messing with different suggests....

 

by: LaindowPosted on 2009-09-17 at 02:56:36ID: 25354291

I do it by email because all code present here at really - that don't work by another reasons - some errors in coding - sadly no way to show and fix whole solution here. It was error how windows event was assign on dialog.

 

by: npuleioPosted on 2009-09-17 at 03:27:26ID: 25354464

OK the little help of Laindow was to find what was wrong with the project example I'm doing to start and it was in fact not really related to suggests got here but I had to change CWinAppEx to CWinApp and to assign OnWindowPosChanged on ON_WM_WINDOWPOSCHANGED()....

 

by: pgnatyukPosted on 2009-09-17 at 03:40:05ID: 25354533

@npuleio: I don't know what to say. Everything looks so strange in this thread.
But the  most annoying is your grade B. I think, it will be great, if you will re-open the question and close it with A fully for Laindow.

 

by: npuleioPosted on 2009-09-17 at 05:16:01ID: 25355140

Oh sorry I was closing too fast the solution...in fact I wanted to give A to both you because you, pygnatyuk, started to suggest that ON_WM_WINDOWPOSCHANGED() and Laindow explained the tasks to reach the result and helped a bit about that CWinAppEx that has to be CWinApp, so it's thanks to both of you and I think is good to share with both you points...

 

by: npuleioPosted on 2009-09-17 at 05:27:09ID: 25355212

At least here it's the code I have as a result.... I had before CWinAppEx then went to CWinApp plus had to assign ON_WM_WINDOWPOSCHANGED() to messagemap... in this code example there are two simple CPropertyPage's classes

// MFC_Analyzer_GUI.h : main header file for the PROJECT_NAME application
//
 
#pragma once
 
#ifndef __AFXWIN_H__
        #error "include 'stdafx.h' before including this file for PCH"
#endif
 
#include "resource.h"           // main symbols
 
 
// CMFC_Analyzer_GUIApp:
// See MFC_Analyzer_GUI.cpp for the implementation of this class
//
 
class CMFC_Analyzer_GUIApp : public CWinApp
{
public:
        CMFC_Analyzer_GUIApp();
 
// Overrides
        public:
        virtual BOOL InitInstance();
 
// Implementation
 
        DECLARE_MESSAGE_MAP()
};
 
extern CMFC_Analyzer_GUIApp theApp;
 
// MFC_Analyzer_GUI.cpp : Defines the class behaviors for the application.
//
 
#include "stdafx.h"
#include "MFC_Analyzer_GUI.h"
#include "MFC_Analyzer_GUIDlg.h"
 
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
 
 
// CMFC_Analyzer_GUIApp
 
BEGIN_MESSAGE_MAP(CMFC_Analyzer_GUIApp, CWinApp)
        ON_COMMAND(ID_HELP, &CWinApp::OnHelp)
END_MESSAGE_MAP()
 
 
// CMFC_Analyzer_GUIApp construction
 
CMFC_Analyzer_GUIApp::CMFC_Analyzer_GUIApp()
{
        // TODO: add construction code here,
        // Place all significant initialization in InitInstance
}
 
 
// The one and only CMFC_Analyzer_GUIApp object
 
CMFC_Analyzer_GUIApp theApp;
 
 
// CMFC_Analyzer_GUIApp initialization
 
BOOL CMFC_Analyzer_GUIApp::InitInstance()
{
        AfxOleInit();
        // InitCommonControlsEx() is required on Windows XP if an application
        // manifest specifies use of ComCtl32.dll version 6 or later to enable
        // visual styles.  Otherwise, any window creation will fail.
        INITCOMMONCONTROLSEX InitCtrls;
        InitCtrls.dwSize = sizeof(InitCtrls);
        // Set this to include all the common control classes you want to use
        // in your application.
        InitCtrls.dwICC = ICC_WIN95_CLASSES;
        InitCommonControlsEx(&InitCtrls);
 
        CWinApp::InitInstance();
 
        AfxEnableControlContainer();
 
        // Standard initialization
        // If you are not using these features and wish to reduce the size
        // of your final executable, you should remove from the following
        // the specific initialization routines you do not need
        // Change the registry key under which our settings are stored
        // TODO: You should modify this string to be something appropriate
        // such as the name of your company or organization
        SetRegistryKey(_T("Local AppWizard-Generated Applications"));
 
        CMFC_Analyzer_GUIDlg dlg;
        m_pMainWnd = &dlg;
        INT_PTR nResponse = dlg.DoModal();
        if (nResponse == IDOK)
        {
                // TODO: Place code here to handle when the dialog is
                //  dismissed with OK
        }
        else if (nResponse == IDCANCEL)
        {
                // TODO: Place code here to handle when the dialog is
                //  dismissed with Cancel
        }
 
        // Since the dialog has been closed, return FALSE so that we exit the
        //  application, rather than start the application's message pump.
        return FALSE;
}
 
 
 
// MFC_Analyzer_GUIDlg.cpp : implementation file
//
 
#include "stdafx.h"
#include "MFC_Analyzer_GUI.h"
#include "MFC_Analyzer_GUIDlg.h"
 
#include "Page_Config.h"
#include "Page_Profile.h"
 
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
 
 
// CAboutDlg dialog used for App About
 
class CAboutDlg : public CDialog
{
public:
        CAboutDlg();
 
// Dialog Data
        enum { IDD = IDD_ABOUTBOX };
 
        protected:
        virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
 
// Implementation
protected:
        DECLARE_MESSAGE_MAP()
};
 
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
}
 
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
        CDialog::DoDataExchange(pDX);
}
 
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
END_MESSAGE_MAP()
 
 
// CMFC_Analyzer_GUIDlg dialog
 
 
 
 
CMFC_Analyzer_GUIDlg::CMFC_Analyzer_GUIDlg(CWnd* pParent /*=NULL*/)
        : CDialog(CMFC_Analyzer_GUIDlg::IDD, pParent)
{
        m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
        m_bIsInitialized = FALSE;
}
 
void CMFC_Analyzer_GUIDlg::DoDataExchange(CDataExchange* pDX)
{
        CDialog::DoDataExchange(pDX);
}
 
BEGIN_MESSAGE_MAP(CMFC_Analyzer_GUIDlg, CDialog)
        ON_WM_SYSCOMMAND()
        ON_WM_PAINT()
        ON_WM_QUERYDRAGICON()
        //}}AFX_MSG_MAP
        ON_WM_SIZE()
        ON_WM_WINDOWPOSCHANGED()
END_MESSAGE_MAP()
 
 
// CMFC_Analyzer_GUIDlg message handlers
 
BOOL CMFC_Analyzer_GUIDlg::OnInitDialog()
{
        CDialog::OnInitDialog();
 
        // Add "About..." menu item to system menu.
 
        // IDM_ABOUTBOX must be in the system command range.
        ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
        ASSERT(IDM_ABOUTBOX < 0xF000);
 
        CMenu* pSysMenu = GetSystemMenu(FALSE);
        if (pSysMenu != NULL)
        {
                BOOL bNameValid;
                CString strAboutMenu;
                bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
                ASSERT(bNameValid);
                if (!strAboutMenu.IsEmpty())
                {
                        pSysMenu->AppendMenu(MF_SEPARATOR);
                        pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
                }
        }
 
        // Set the icon for this dialog.  The framework does this automatically
        //  when the application's main window is not a dialog
        SetIcon(m_hIcon, TRUE);                 // Set big icon
        SetIcon(m_hIcon, FALSE);                // Set small icon
 
        // TODO: Add extra initialization here
        CPage_Config* pageConfig = new CPage_Config();
        CPage_Profile* pageProfile = new CPage_Profile();
        m_poPropSheet = new CPropertySheet();
        m_poPropSheet->AddPage(pageConfig);
        m_poPropSheet->AddPage(pageProfile);
        DWORD dwStyle = WS_VISIBLE | WS_CHILD;       
        DWORD dwExStyle = WS_EX_LEFT|WS_EX_CONTROLPARENT;
        m_poPropSheet->Create(this, dwStyle, dwExStyle);
 
        poControl = m_poPropSheet->GetTabControl();
 
        SetPageLabel(0, L"Configuration");
        SetPageLabel(1, L"Profiling");
       
        m_poPropSheet->SetActivePage(0);
 
        m_bIsInitialized = TRUE;
 
        return TRUE;  // return TRUE  unless you set the focus to a control
}
 
void CMFC_Analyzer_GUIDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
        if ((nID & 0xFFF0) == IDM_ABOUTBOX)
        {
                CAboutDlg dlgAbout;
                dlgAbout.DoModal();
        }
        else
        {
                CDialog::OnSysCommand(nID, lParam);
        }
}
 
// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.
 
void CMFC_Analyzer_GUIDlg::OnPaint()
{
        if (IsIconic())
        {
                CPaintDC dc(this); // device context for painting
 
                SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
 
                // Center icon in client rectangle
                int cxIcon = GetSystemMetrics(SM_CXICON);
                int cyIcon = GetSystemMetrics(SM_CYICON);
                CRect rect;
                GetClientRect(&rect);
                int x = (rect.Width() - cxIcon + 1) / 2;
                int y = (rect.Height() - cyIcon + 1) / 2;
 
                // Draw the icon
                dc.DrawIcon(x, y, m_hIcon);
        }
        else
        {
                CDialog::OnPaint();
        }
}
 
// The system calls this function to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMFC_Analyzer_GUIDlg::OnQueryDragIcon()
{
        return static_cast<HCURSOR>(m_hIcon);
}
 
 
void CMFC_Analyzer_GUIDlg::OnSize(UINT nType, int cx, int cy)
{
        CDialog::OnSize(nType, cx, cy);
 
        // TODO: Add your message handler code here
}
 
void CMFC_Analyzer_GUIDlg::SetPageLabel(UINT index, LPTSTR text)
{
        TC_ITEM tcItem;
        tcItem.mask = TCIF_TEXT;
        tcItem.pszText = text; 
        poControl->SetItem(index, &tcItem);
}
 
void CMFC_Analyzer_GUIDlg::OnWindowPosChanged(WINDOWPOS* lpwndpos)
{
        CDialog::OnWindowPosChanged(lpwndpos);
 
        if( m_bIsInitialized ) 
        {              
                //Get client area size         
                RECT oClientRect;              
                this->GetClientRect( &oClientRect );           
                //Wide         
                oClientRect.right = oClientRect.right - oClientRect.left - 15;         
                //Hieght               
                //Additional -10 - to make range more better don't forget that TOP + BOTTOM space
                oClientRect.bottom = oClientRect.bottom - oClientRect.top - 10 - 10;            
                //Set PropertySheet position           
                m_poPropSheet->SetWindowPos( &CWnd::wndBottom, 10, 10,                   
                                                                        oClientRect.right,     oClientRect.bottom, NULL );             
                //Set PropertySheet subcontrol position        
                CTabCtrl* poControl = m_poPropSheet->GetTabControl();          
                poControl->SetWindowPos( &CWnd::wndBottom, 0, 0,
                                                                oClientRect.right - 10, oClientRect.bottom - 10,              
                                                                SWP_NOMOVE|SWP_NOZORDER );             
                //Set PropertySheet page positions             
                //All another pages will be repositioned than user change tab           
                CPropertyPage* poPage = m_poPropSheet->GetActivePage();        
                if( poPage != NULL && poPage->m_hWnd != NULL )         
                {
                        //Here you need calculate space between dialog and sheet border + between page and sheet border - so it double space and 20 instead 10
                        //in my sourcecode I multiple on 4 here not on 2
                        //+ for vertical size you need to remember about tabs line with tabs name - sheet reserver it so page lost 25 pixels - sheet header 25 pixels
                        //- better get it dynamicly but I think that not a problem to gardcode it
                        poPage->SetWindowPos( &CWnd::wndBottom, 0, 0,                                   
                                                                  oClientRect.right - 20, oClientRect.bottom - 20 - 25,
                                                                  SWP_NOMOVE|SWP_NOZORDER  );          
                }      
        }
}
 
 
// MFC_Analyzer_GUIDlg.h : header file
//
 
#pragma once
 
 
// CMFC_Analyzer_GUIDlg dialog
class CMFC_Analyzer_GUIDlg : public CDialog
{
// Construction
public:
        CMFC_Analyzer_GUIDlg(CWnd* pParent = NULL);     // standard constructor
 
// Dialog Data
        enum { IDD = IDD_MFC_ANALYZER_GUI_DIALOG };
 
        protected:
        virtual void DoDataExchange(CDataExchange* pDX);        // DDX/DDV support
 
 
// Implementation
protected:
        HICON m_hIcon;
        CPropertySheet* m_poPropSheet;
        CTabCtrl* poControl;
        bool m_bIsInitialized;
 
        // Generated message map functions
        virtual BOOL OnInitDialog();
        afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
        afx_msg void OnPaint();
        afx_msg HCURSOR OnQueryDragIcon();
        DECLARE_MESSAGE_MAP()
public:
        afx_msg void OnSize(UINT nType, int cx, int cy);
        afx_msg void SetPageLabel(UINT index, LPTSTR text);
        afx_msg void OnWindowPosChanged(WINDOWPOS* lpwndpos);
};
 

                                              
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
235:
236:
237:
238:
239:
240:
241:
242:
243:
244:
245:
246:
247:
248:
249:
250:
251:
252:
253:
254:
255:
256:
257:
258:
259:
260:
261:
262:
263:
264:
265:
266:
267:
268:
269:
270:
271:
272:
273:
274:
275:
276:
277:
278:
279:
280:
281:
282:
283:
284:
285:
286:
287:
288:
289:
290:
291:
292:
293:
294:
295:
296:
297:
298:
299:
300:
301:
302:
303:
304:
305:
306:
307:
308:
309:
310:
311:
312:
313:
314:
315:
316:
317:
318:
319:
320:
321:
322:
323:
324:
325:
326:
327:
328:
329:
330:
331:
332:
333:
334:
335:
336:
337:
338:
339:
340:
341:
342:
343:
344:
345:
346:
347:
348:
349:
350:
351:
352:
353:
354:
355:
356:
357:
358:
359:
360:
361:
362:
363:
364:
365:
366:
367:
368:
369:
370:
371:
372:
373:
374:
375:
376:
377:
378:
379:
380:
381:
382:
383:

Select allOpen in new window

 

by: npuleioPosted on 2009-09-17 at 05:31:13ID: 25355244

Yes, I agree Vee_Mod, so I pasted the main code that was involved in this issue.... it is ok?...

And, Vee_Mod, as you can see both of them helped, first suggesting that ON_WM_WINDOWPOSCHANGED() and then the other explaining the steps to reach this result, is it reasonable to award points to both them?...

 

by: LaindowPosted on 2009-09-17 at 05:33:24ID: 25355262

I don't have any problems with points and agree to split them.

 

by: npuleioPosted on 2009-09-17 at 05:51:06ID: 31628970

As already explained

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...