Click here to Skip to main content
15,881,588 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.5K   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.
// TestDialog.cpp : implementation of the CTestDialog class
//
/////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "resource.h"

#include "TestDialog.h"

LRESULT CTestDialog::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
	HICON hIcon = (HICON)::LoadImage(_pModule->GetResourceInstance(), MAKEINTRESOURCE(IDI_FOLDER_OPEN), IMAGE_ICON, 16,16, LR_SHARED);
	this->SetIcon(hIcon, ICON_SMALL);

	this->InitializeControls();
	this->InitializeValues();

	resizeClass::DlgResize_Init(false, true, WS_CLIPCHILDREN);

	return TRUE;
}

void CTestDialog::InitializeControls(void)
{
	m_edit = this->GetDlgItem(IDC_EDIT_COMMAND);
	m_button = this->GetDlgItem(IDC_BTN_EXECUTE);
	m_list.SubclassWindow(this->GetDlgItem(IDC_LIST));

	DWORD nExtended = m_list.GetExtendedListViewStyle()|
				LVS_EX_FULLROWSELECT|LVS_EX_INFOTIP|LVS_EX_HEADERDRAGDROP|//LVS_EX_LABELTIP|
				LVS_EX_SUBITEMIMAGES|LVS_EX_UNDERLINEHOT|LVS_EX_FLATSB|LVS_EX_GRIDLINES;
	m_list.SetExtendedListViewStyle(nExtended);

	LVCOLUMN lvColumn = {0};

	lvColumn.mask = (LVCF_FMT|LVCF_TEXT);
	lvColumn.fmt = LVCFMT_LEFT;

	lvColumn.pszText = _T("Name");
	m_list.InsertColumn(0, &lvColumn);

	lvColumn.pszText = _T("Value");
	m_list.InsertColumn(1, &lvColumn);

	CRect rcDialog;
	this->GetClientRect(&rcDialog);

	m_list.SetColumnWidth(0, rcDialog.Width()/2);
	m_list.SetColumnWidth(1, rcDialog.Width()/2);
}

LRESULT CTestDialog::OnClose(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
	if(::IsWindow(m_hWnd))
	{
		::DestroyWindow(m_hWnd);
	}

	// NOTE: For some reason, DefWindowProc doesn't call DestroyWindow
	//  when handling WM_CLOSE for modeless dialogs, so we'll do it ourself
	bHandled = TRUE;
	return 0;
}

LRESULT CTestDialog::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
	m_list.UnsubclassWindow();

	// Let anyone else (including DefWindowProc) see the message
	bHandled = FALSE;
	return 0;
}

LRESULT CTestDialog::OnExecute(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
#if _ATL_VER > 0x0700
	CString text;
	m_edit.GetWindowText(text);
	if(text.GetLength() > 0)
	{
		this->MessageBox(text, _T("Execute"), MB_OK);
	}
#else
	CComBSTR text;
	m_edit.GetWindowText(&text);
	if(text.Length() > 0)
	{
		::MessageBoxW(m_hWnd, text, L"Execute", MB_OK);
	}
#endif
	return 0;
}

void CTestDialog::InitializeValues(void)
{
	m_edit.SetWindowText(_T("Test"));
	m_button.SetFocus();

	int itemIndex = 0;
	itemIndex = m_list.GetItemCount();
	itemIndex = m_list.InsertItem(itemIndex, _T("Hello"));
	m_list.SetItemText(itemIndex, 1, _T("There"));
}

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