Click here to Skip to main content
12,633,856 members (27,181 online)
Click here to Skip to main content


82 bookmarked

Automatic Tab Bar for MDI Frameworks

, 3 Jan 2003 Public Domain
A dockable bar containing a tabbed list of open windows

#ifndef __AFXTEMPL_H__
#pragma message("Include <afxtempl.h> in your stdafx.h to avoid this message")
#include <afxtempl.h>

// Forward declaration

class CViewManager;
// 1. TODO: Please change the CMainFrame to your main frame
#define  CMyMainFrameClass CMainFrame
class CMyMainFrameClass;

// CDocumentList declaration

class CDocumentList : public CList <CDocument*, CDocument*>
	// Constuction
	CDocumentList();  // To automatically enumerates the documents in a given application
	// Destruction
	~CDocumentList(); // To empty and destroy the list when out of scope
	// Operations
	CDocument* GetNextDocument();  // Gets next document object
	// Prevent any copying and assignment of CDocumentList objects
	CDocumentList(const CDocumentList&);
	const CDocumentList& operator=(const CDocumentList&);
	// Implementation
	// Keep the current position in the document list
	POSITION m_CurPosInDocList;

// CWindowDlg dialog

class CWindowDlg : public CDialog
	// Construction
	CWindowDlg(CMDIFrameWnd* pMDIFrame, CWnd* pParentWnd);
	CWindowDlg(CMDIFrameWnd* pMDIFrame);   
	// Dialog Data
	CListBox	m_wndList;
	// Overrides
	// ClassWizard generated virtual function overrides
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	// Implementation
	void  MDIMessage(UINT uMsg, WPARAM flag);
	void  FillWindowList(void);
	void  SelActive(void);
	void  UpdateButtons(void);
	CMDIFrameWnd* m_pMDIFrame;
	// Generated message map functions
	virtual BOOL OnInitDialog();
	afx_msg void OnClose();
	afx_msg void OnSelChange();
	afx_msg void OnSave();
	afx_msg void OnActivate();
	afx_msg void OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct);
	afx_msg void OnUpdateUI(CCmdUI * pCmdUI);
	afx_msg void OnTileHorz();
	afx_msg void OnMinimize();
	afx_msg void OnTileVert();
	afx_msg void OnCascade();

// CMDIClient window

class CMDIClient : public CWnd
// Construction
	enum DispType 
// Attributes
	// Set background color
	void SetBkColor(COLORREF crBkValue);
	COLORREF GetBkColor() const;
	// Set Logo Text color
	void SetLogoColor(COLORREF crValue);
	COLORREF GetLogoColor() const;

	BOOL GetBkBitmapState() const;

	// Set the logo text font...
	void SetLogoFont(CFont* pLogoFont);
	void SetLogoFont(int nLogoWeight = FW_SEMIBOLD, BOOL bLogoItalic = FALSE,   
		BOOL bLogoUnderline = FALSE);

	CFont* GetLogoFont();
	// Load background bitmap from given file
	BOOL SetBitmap(LPCTSTR lpszFileName, UINT uFlags = LR_LOADMAP3DCOLORS);
	// Load background bitmap from resource.
	BOOL SetBitmap(UINT nBmpID, COLORMAP* pClrMap = NULL, int nCount = 0);
	// Load background bitmap from resource.
	BOOL SetDefBitmap(UINT nBmpID, COLORMAP* pClrMap = NULL, int nCount = 0);
	// Set desired display mode (tile, center, or stretch)
	void SetDispType(DispType enuDispType);
	DispType GetDispType() const;
	// Return the current image size.
	const CSize& GetImageSize() const;
	// Return the filename of the bitmap
	const CString& GetFileName() const;

	// For access to the private view manager member
//	void SetViewManager(CViewManager* pViewManager)  { m_pViewManager = pViewManager; }
	CViewManager* GetViewManager() const  { return m_pViewManager; }
	CString       m_strWindows;
	HMENU	      m_hMenuWindow;
	CMyMainFrameClass*   m_pMDIFrame;
	// Full Screen mode support
	CRect         m_rcMainFrame;
	BOOL          m_bMaxChild;
	CToolBar*     m_pwndFullScrnToolBar;
	void FullScreenOff();
	void FullScreenOn();
	CSize         m_sizeClient;
	CViewManager* m_pViewManager;
	BOOL          m_bFullScreen;        // TRUE for "On" mode, FALSE for "Off"
	BOOL          m_bFirstTime;
	BOOL          m_bBkBitmap;
	void HideControlBars(void);
	void ShowControlBars(void);

	struct FSControlBars
		BOOL         bWasVisible;
		CControlBar* pControlBar;

	CArray<FSControlBars, FSControlBars&>* m_pwndControlBars;

// Operations
	void ManageWindows(CMDIFrameWnd* pMDIFrame);
	void ManageWindows(CMDIFrameWnd* pMDIFrame, CWnd* pParentWnd);
    BOOL SubclassMDIClient(CMDIFrameWnd* pMDIFrameWnd, 
		CViewManager* pViewManager = NULL, UINT uID = ID_VIEW_VIEWTAB);
	BOOL IsFullScreen() { return m_bFullScreen; }
	// Overrides
	// ClassWizard generated virtual function overrides
	virtual BOOL PreTranslateMessage(MSG* pMsg);
// Implementation
	void Defaults(BOOL bBkBitmap = TRUE, BOOL bDelBkBitmap = TRUE);
	void RestoreMainFrameState(UINT nCmdShow);
	void SaveMainFrameState();
	virtual ~CMDIClient();
    COLORREF m_crBkColor;          // Background color
    COLORREF m_crLogoColor;        // Right logo text color
    CBitmap  m_bkBitmap;           // background bitmap
    CBitmap  m_bkDefBitmap;        // Default background bitmap
    CBrush   m_bkBrush;            // Brush used for background painting
    CString  m_strFileName;        // Filename of any bitmap loaded from a file
    CSize    m_sizImage;           // Bitmap image size
    CSize    m_sizDefImage;        // Default Bitmap image size
    DispType m_enuDispType;        // Current display type
    CFont    m_fontLogo;           // Font for drawing the logo text
// Generated message map functions
	void PaintLogo(CDC* pDC);

	afx_msg LRESULT OnRefreshMenu(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnSetMenu(WPARAM wParam, LPARAM lParam);
	afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
	afx_msg void OnWindowManage();
	afx_msg void OnWindowNext();
	afx_msg void OnWindowPrevious();
	afx_msg void OnWindowSaveAll();
	afx_msg void OnWindowCloseAll();
	afx_msg void OnWindowClose();
	afx_msg void OnViewFullscreen();
	afx_msg void OnUpdateViewFullscreen(CCmdUI* pCmdUI);
	afx_msg void OnTabView();
	afx_msg void OnUpdateTabView(CCmdUI* pCmdUI);
	afx_msg void OnUpdateWindowManage(CCmdUI* pCmdUI);
	afx_msg void OnPaint();
	afx_msg void OnDestroy();
	afx_msg LRESULT OnMDICreate(WPARAM wParam, LPARAM lParam);
	afx_msg LRESULT OnMDIDestroy(WPARAM wParam, LPARAM lParam);	


// CMDIClient inlines

inline COLORREF CMDIClient::GetBkColor() const
	return m_crBkColor;

inline COLORREF CMDIClient::GetLogoColor() const
	return m_crLogoColor;

inline CMDIClient::DispType CMDIClient::GetDispType() const
	return m_enuDispType;

inline const CString& CMDIClient::GetFileName() const
	return m_strFileName;

inline const CSize& CMDIClient::GetImageSize() const
	return m_sizImage;

inline CFont* CMDIClient::GetLogoFont()
	return &m_fontLogo;

inline BOOL CMDIClient::GetBkBitmapState() const
	return m_bBkBitmap;


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.


This article, along with any associated source code and files, is licensed under A Public Domain dedication


About the Author

Paul Selormey
Japan Japan
Systems Engineer

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161208.2 | Last Updated 4 Jan 2003
Article Copyright 2000 by Paul Selormey
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid