Click here to Skip to main content
15,895,799 members
Articles / Desktop Programming / MFC

CGroupLine

Rate me:
Please Sign up or sign in to vote.
4.84/5 (29 votes)
18 Nov 2008CPOL5 min read 81.7K   3.2K   68  
CStatic enhancement that adds a trailing horizontal line, and supports WinXP themes.
// GroupLineDlg.cpp : implementation file
//

#include "stdafx.h"
#include "GroupLineApp.h"
#include "GroupLineDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CGroupLineDlg dialog



CGroupLineDlg::CGroupLineDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CGroupLineDlg::IDD, pParent)
	, m_left_off(CGroupLine::eThemeOff)
	, m_right_off(CGroupLine::eThemeOff)
	, m_center_off(CGroupLine::eThemeOff)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CGroupLineDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Control(pDX, IDC_GROUP_LINE_LEFT, m_left);
	DDX_Control(pDX, IDC_GROUP_LINE_CENTER, m_center);
	DDX_Control(pDX, IDC_GROUP_LINE_RIGHT, m_right);
	DDX_Control(pDX, IDC_GROUP_LINE_LEFT_TAB, m_left_onTab);
	DDX_Control(pDX, IDC_GROUP_LINE_CENTER_TAB, m_center_onTab);
	DDX_Control(pDX, IDC_GROUP_LINE_RIGHT_TAB, m_right_onTab);
	DDX_Control(pDX, IDC_GROUP_LINE_LEFT_OFF, m_left_off);
	DDX_Control(pDX, IDC_GROUP_LINE_CENTER_OFF, m_center_off);
	DDX_Control(pDX, IDC_GROUP_LINE_RIGHT_OFF, m_right_off);
	DDX_Control(pDX, IDC_TAB, m_tab);
}

BEGIN_MESSAGE_MAP(CGroupLineDlg, CDialog)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDOK, OnBnClickedOk)
END_MESSAGE_MAP()


// CGroupLineDlg message handlers

BOOL CGroupLineDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// 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

	m_tab.InsertItem(0, _T("Tab 1"));
	m_tab.InsertItem(1, _T("Tab 2"));
	m_tab.InsertItem(2, _T("Tab 3"));
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// 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 CGroupLineDlg::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 CGroupLineDlg::OnQueryDragIcon()
{
	return static_cast<HCURSOR>(m_hIcon);
}

void CGroupLineDlg::OnBnClickedOk()
{
	// TODO: Add your control notification handler code here
	OnOK();
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
Canada Canada
www.IconsReview.com[^]
Huge list of stock icon collections (both free and commercial)

The picture is from September 2006, after picking up a rental car at the airport in Denver, Colorado. I'm smiling in the picture, because I have yet to come to the realization that I just wasted 400 bucks ( because you don't really need a car in downtown Denver - you can just walk everywhere).

Comments and Discussions