Click here to Skip to main content
15,894,405 members
Articles / Desktop Programming / WTL

Custom Tab Controls, Tabbed Frame and Tabbed MDI

Rate me:
Please Sign up or sign in to vote.
4.90/5 (144 votes)
13 Jul 200522 min read 1.6M   35.6K   395  
An extensible framework for creating customized tabs in ATL/WTL, with a VS.NET-like tab control implementation, tabbed frames, tabbed MDI, and more.
// ChildFrm.h : interface of the CChildFrame class
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_CHILDFRM_H__053AD664_0AE2_11D6_8BF1_00500477589F__INCLUDED_)
#define AFX_CHILDFRM_H__053AD664_0AE2_11D6_8BF1_00500477589F__INCLUDED_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

#define WM_POSTCREATE WM_USER + 1

class CChildFrame : public CTabbedMDIChildWindowImpl<CChildFrame>
{
public:
	DECLARE_FRAME_WND_CLASS(NULL, IDR_MDICHILD)

	CSimpleTabbedMDIDemoView m_view;

	virtual void OnFinalMessage(HWND /*hWnd*/)
	{
		delete this;
	}

	BEGIN_MSG_MAP(CChildFrame)
		MESSAGE_HANDLER(WM_CREATE, OnCreate)
		MESSAGE_HANDLER(WM_POSTCREATE, OnPostCreate)
		MESSAGE_HANDLER(WM_FORWARDMSG, OnForwardMsg)
		CHAIN_MSG_MAP(CTabbedMDIChildWindowImpl<CChildFrame>)
	END_MSG_MAP()

// Handler prototypes (uncomment arguments if needed):
//	LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
//	LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
//	LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)

	LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
	{
		m_hWndClient = m_view.Create(m_hWnd, rcDefault, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_HSCROLL | WS_VSCROLL | ES_AUTOHSCROLL | ES_AUTOVSCROLL | ES_MULTILINE | ES_NOHIDESEL, WS_EX_CLIENTEDGE);

		this->PostMessage(WM_POSTCREATE);

		bHandled = FALSE;
		return 1;
	}

	LRESULT OnPostCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
	{
		static int nCount=0;

		CString sToolTip;
		sToolTip.Format(_T("C:\\This is\\a test\\of the tooltip %d\\Document"), nCount++);
		this->SetTabToolTip(sToolTip);

		CMenuHandle menu = this->GetSystemMenu(FALSE);
		if(menu.IsMenu())
		{
			// To change the context menu when clicking on the tab corresponding
			//  to this window in the tabbed MDI, you can simply modify the 
			//  system menu for the window here.

			// Add menu items:
			//menu.AppendMenu(MF_SEPARATOR);
			//menu.AppendMenu((MF_ENABLED | MF_STRING), ID_VIEW_SOURCE, _T("View Source"));

			// Delete menu items:
			//menu.DeleteMenu(SC_SIZE, MF_BYCOMMAND);
			//menu.DeleteMenu(SC_MOVE, MF_BYCOMMAND);
			//menu.DeleteMenu(SC_MINIMIZE, MF_BYCOMMAND);
			//menu.DeleteMenu(SC_RESTORE, MF_BYCOMMAND);

			if(0 != menu.GetMenuString(SC_NEXTWINDOW, NULL, 0, MF_BYCOMMAND))
			{
				menu.DeleteMenu(SC_NEXTWINDOW, MF_BYCOMMAND);

				int nLastItemIndex = menu.GetMenuItemCount()-1;
				int nId = menu.GetMenuItemID(nLastItemIndex);
				if(SC_SEPARATOR == nId || 0 == nId)
				{
					menu.DeleteMenu(nLastItemIndex, MF_BYPOSITION);
				}
			}
		}

		return 0;
	}

	LRESULT OnForwardMsg(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/)
	{
		LPMSG pMsg = (LPMSG)lParam;

		if(CTabbedMDIChildWindowImpl<CChildFrame>::PreTranslateMessage(pMsg))
			return TRUE;

		return m_view.PreTranslateMessage(pMsg);
	}
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_CHILDFRM_H__053AD664_0AE2_11D6_8BF1_00500477589F__INCLUDED_)

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Architect
United States United States
Daniel Bowen used to work as a Software Engineer for Evans & Sutherland in Salt Lake City, Utah working on the modeling tools for high end flight simulators. He then worked for the startup company WiLife Inc. in Draper, Utah working on the software portion of an easy to use and affordable digital video surveillance system. WiLife Inc. is now part of Logitech Inc.

Comments and Discussions