Click here to Skip to main content
15,897,187 members
Articles / Desktop Programming / MFC

Outlookbar-style menu interface

Rate me:
Please Sign up or sign in to vote.
4.84/5 (57 votes)
22 Jul 20035 min read 203K   9.5K   132  
A control bar outlook-style that integrates with the standard menu command's framework.
/********************************************************************

This dialog will be inserted as a child into the outbar control.
It uses Marc Richarme 's Easysize classes to keep the controls in the proper
position during resizing (very nice work Mark!, easy to use and works just great)

The test dialogs contails a list box, a button, a static label and an edit box.
With button you can add the text in the edit into the list box.
The dialog will be transparent, showing the background of the outbar control.

See CMainFrame::OnCreate() for how to insert this into the control itself.

*********************************************************************/

#include "stdafx.h"
#include "Outbar2_demo.h"
#include "DlgTest1.h"


// CDlgTest1 dialog

//EASYSIZE(control,left,top,right,bottom,options)
BEGIN_EASYSIZE_MAP(CDlgTest1)
	EASYSIZE(IDC_EDIT1,ES_BORDER,ES_BORDER,ES_BORDER,ES_KEEPSIZE,0)
	EASYSIZE(IDC_BUTTON1,ES_KEEPSIZE,ES_BORDER,ES_BORDER,ES_KEEPSIZE,0)
	EASYSIZE(IDC_LIST1,ES_BORDER,ES_BORDER,ES_BORDER,ES_BORDER,0)
END_EASYSIZE_MAP


IMPLEMENT_DYNAMIC(CDlgTest1, CDialog)
CDlgTest1::CDlgTest1(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgTest1::IDD, pParent)
{
}

CDlgTest1::~CDlgTest1()
{
}

void CDlgTest1::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_EDIT1, csFind);
	DDX_Control(pDX, IDC_LIST1, wndList);
}


BEGIN_MESSAGE_MAP(CDlgTest1, CDialog)
	ON_BN_CLICKED(IDOK, OnBnClickedOk)
	ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
	ON_WM_SIZE()
	ON_WM_ERASEBKGND()
	ON_WM_CTLCOLOR()
	ON_BN_CLICKED(IDC_BUTTON1, OnBnClickedButton1)
END_MESSAGE_MAP()



// CDlgTest1 message handlers

// Those 2 needs to be overridden to avoid the child window go poof on enter/esc key

void CDlgTest1::OnBnClickedOk()
{
	
}

void CDlgTest1::OnBnClickedCancel()
{
}

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

	INIT_EASYSIZE; // this is for the auto-resizing of controls

	wndList.InsertColumn(0,"Topic",LVCFMT_LEFT,80);
	wndList.InsertColumn(1,"Title",LVCFMT_LEFT,280);
	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgTest1::OnSize(UINT nType, int cx, int cy)
{
	CDialog::OnSize(nType, cx, cy);
	
	UPDATE_EASYSIZE; // this is for the auto-resizing of controls
	
	Invalidate(); // at least on win2k seems that glitches may happen during resize, so let's invalidate
}

BOOL CDlgTest1::OnEraseBkgnd(CDC* pDC)
{
	// let's have the control background show through

	return TRUE;
}

HBRUSH CDlgTest1::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
	// also let's have the static labels with an invisible background and
	// proper color for the text

	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	if (nCtlColor == CTLCOLOR_STATIC)
	{
		pDC->SetBkMode(TRANSPARENT);
		pDC->SetTextColor(GetSysColor(COLOR_WINDOW));
		return (HBRUSH) GetStockObject(NULL_BRUSH);
	}
	return hbr;
}

void CDlgTest1::OnBnClickedButton1()
{
	// and at end let's have the controls do something 

	UpdateData();
	int idx = wndList.InsertItem(wndList.GetItemCount(), "*");
	wndList.SetItemText(idx,1,csFind);
	GetDlgItem(IDC_EDIT1)->SetFocus();
}

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
Web Developer
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions