westine
asked on
Adding tabs to the MainFrame in an MDI application.
I have an MDI application and would like to add tabs to the MainFrame (the CMDIFrameWnd derived class) so that the child windows are added to the tab control without losing the other MDI functionality (cascade, tile, etc). This would create a "workbook" feel in the MDI application. The tabs would act just like selcting a child window from the "Window" menu. I've tried changing the window class to "SysTabControl32" in the CREATESTRUCT but have had no luck. Has anyone tried this or have any ideas? I've been told that there are some software packages available that can extend MFC in this manner, unfortunately my funds are very limited. Thanks for any help.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What I would do is to create a FormView that has no contorls on it and add a ResizePropertySheet as a member that get created in the OnInit override. Then also overide the ONSize to resize it to fill the form. This keep the Doc-view architecture.
following is the code for a resize Property Sheet. You may not need all of it as it also modify style etc to make it have resize boder which you will not require.
// ResizePropertySheet.cpp : implementation file
//
#include "stdafx.h"
#include "ResizePropertySheet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define TOP_OFFSET (30)
#define LEFT_OFFSET (10)
#define BOTTOM_OFFSET (8)
#define RIGHT_OFFSET (8)
////////////////////////// ////////// ////////// ////////// ////////// ////////// /
// CResizePropertySheet
IMPLEMENT_DYNAMIC(CResizeP ropertyShe et, CPropertySheet)
CResizePropertySheet::CRes izePropert ySheet(UIN T nIDCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(nIDCaptio n, pParentWnd, iSelectPage)
{
}
CResizePropertySheet::CRes izePropert ySheet(LPC TSTR pszCaption, CWnd* pParentWnd, UINT iSelectPage)
:CPropertySheet(pszCaptio n, pParentWnd, iSelectPage)
{
}
CResizePropertySheet::~CRe sizeProper tySheet()
{
}
BEGIN_MESSAGE_MAP(CResizeP ropertyShe et, CPropertySheet)
//{{AFX_MSG_MAP(CResizePr opertyShee t)
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
////////////////////////// ////////// ////////// ////////// ////////// ////////// /
// CResizePropertySheet message handlers
void CResizePropertySheet::PreS ubclassWin dow()
{
ModifyStyle ( 0, WS_SIZEBOX);
CPropertySheet::PreSubcla ssWindow() ;
}
void CResizePropertySheet::OnSi ze(UINT nType, int cx, int cy)
{
CPropertySheet::OnSize(nT ype, cx, cy);
CRect WinRect;
CRect TabWinRect;
CTabCtrl *pTabCtrl;
CPropertyPage *pPage;
unsigned int a,ct;
GetWindowRect( &WinRect );
pTabCtrl = GetTabControl();
if(NULL != pTabCtrl)
{
WinRect.top += TOP_OFFSET;
WinRect.left += LEFT_OFFSET;
WinRect.right -= RIGHT_OFFSET;
WinRect.bottom -= BOTTOM_OFFSET;
ScreenToClient( &WinRect );
pTabCtrl->MoveWindow( &WinRect );
pTabCtrl->AdjustRect( FALSE, &WinRect );
ct = m_pages.GetSize();
for(a = 0; a < ct; a++)
{
pPage = (CPropertyPage*)m_pages[a] ;
if( NULL != pPage->m_hWnd )
{
pPage->MoveWindow( &WinRect );
//pPage->SendMessage( WM_SIZE, SIZE_RESTORED, MAKELONG( WinRect.Width(), WinRect.Height() ) );
}
}
}
}
void CResizePropertySheet::Hide AllButtons ()
{
unsigned int idButtons[] = {IDOK,IDCANCEL,ID_APPLY_NO W,ID_WIZBA CK,ID_WIZN EXT,ID_WIZ FINISH};
CWnd *pWnd;
unsigned int a,ct;
ct = sizeof(idButtons) / sizeof(idButtons[0]);
for(a = 0; a < ct ; a++)
{
pWnd = GetDlgItem( idButtons[a] ) ;
if( NULL != pWnd )
{
pWnd->ShowWindow( FALSE );
}
}
}
BOOL CResizePropertySheet::OnIn itDialog()
{
BOOL bResult = CPropertySheet::OnInitDial og();
CTabCtrl *pTabCtrl;
CRect WinRect;
HideAllButtons();
GetWindowRect( &WinRect );
pTabCtrl = GetTabControl();
if( NULL != pTabCtrl )
{
WinRect.top += TOP_OFFSET;
WinRect.left += LEFT_OFFSET;
WinRect.right -= RIGHT_OFFSET;
WinRect.bottom -= BOTTOM_OFFSET;
ScreenToClient( &WinRect );
pTabCtrl->MoveWindow( &WinRect );
}
return bResult;
}
following is the code for a resize Property Sheet. You may not need all of it as it also modify style etc to make it have resize boder which you will not require.
// ResizePropertySheet.cpp : implementation file
//
#include "stdafx.h"
#include "ResizePropertySheet.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define TOP_OFFSET (30)
#define LEFT_OFFSET (10)
#define BOTTOM_OFFSET (8)
#define RIGHT_OFFSET (8)
//////////////////////////
// CResizePropertySheet
IMPLEMENT_DYNAMIC(CResizeP
CResizePropertySheet::CRes
:CPropertySheet(nIDCaptio
{
}
CResizePropertySheet::CRes
:CPropertySheet(pszCaptio
{
}
CResizePropertySheet::~CRe
{
}
BEGIN_MESSAGE_MAP(CResizeP
//{{AFX_MSG_MAP(CResizePr
ON_WM_SIZE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
//////////////////////////
// CResizePropertySheet message handlers
void CResizePropertySheet::PreS
{
ModifyStyle ( 0, WS_SIZEBOX);
CPropertySheet::PreSubcla
}
void CResizePropertySheet::OnSi
{
CPropertySheet::OnSize(nT
CRect WinRect;
CRect TabWinRect;
CTabCtrl *pTabCtrl;
CPropertyPage *pPage;
unsigned int a,ct;
GetWindowRect( &WinRect );
pTabCtrl = GetTabControl();
if(NULL != pTabCtrl)
{
WinRect.top += TOP_OFFSET;
WinRect.left += LEFT_OFFSET;
WinRect.right -= RIGHT_OFFSET;
WinRect.bottom -= BOTTOM_OFFSET;
ScreenToClient( &WinRect );
pTabCtrl->MoveWindow( &WinRect );
pTabCtrl->AdjustRect( FALSE, &WinRect );
ct = m_pages.GetSize();
for(a = 0; a < ct; a++)
{
pPage = (CPropertyPage*)m_pages[a]
if( NULL != pPage->m_hWnd )
{
pPage->MoveWindow( &WinRect );
//pPage->SendMessage( WM_SIZE, SIZE_RESTORED, MAKELONG( WinRect.Width(), WinRect.Height() ) );
}
}
}
}
void CResizePropertySheet::Hide
{
unsigned int idButtons[] = {IDOK,IDCANCEL,ID_APPLY_NO
CWnd *pWnd;
unsigned int a,ct;
ct = sizeof(idButtons) / sizeof(idButtons[0]);
for(a = 0; a < ct ; a++)
{
pWnd = GetDlgItem( idButtons[a] ) ;
if( NULL != pWnd )
{
pWnd->ShowWindow( FALSE );
}
}
}
BOOL CResizePropertySheet::OnIn
{
BOOL bResult = CPropertySheet::OnInitDial
CTabCtrl *pTabCtrl;
CRect WinRect;
HideAllButtons();
GetWindowRect( &WinRect );
pTabCtrl = GetTabControl();
if( NULL != pTabCtrl )
{
WinRect.top += TOP_OFFSET;
WinRect.left += LEFT_OFFSET;
WinRect.right -= RIGHT_OFFSET;
WinRect.bottom -= BOTTOM_OFFSET;
ScreenToClient( &WinRect );
pTabCtrl->MoveWindow( &WinRect );
}
return bResult;
}
ASKER
Thanks Andy! I'll give this a shot and see if it does the trick.
ASKER
Thanks Andy...
ASKER