// CtrlMessageBarDemoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CtrlMessageBarDemo.h"
#include "CtrlMessageBarDemoDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
// CCtrlMessageBarDemoDlg dialog
CCtrlMessageBarDemoDlg::CCtrlMessageBarDemoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCtrlMessageBarDemoDlg::IDD, pParent)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CCtrlMessageBarDemoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_TREE1, m_tree);
DDX_Control(pDX, IDC_LISTBOX, m_listbox);
DDX_Control(pDX, IDC_LIST1, m_list);
DDX_Control(pDX, IDC_EDIT1, m_edit);
DDX_Control(pDX, IDC_BUTTON1, m_btn);
}
BEGIN_MESSAGE_MAP(CCtrlMessageBarDemoDlg, CDialog)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_RESET, OnReset)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// CCtrlMessageBarDemoDlg message handlers
BOOL CCtrlMessageBarDemoDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// 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
// TODO: Add extra initialization here
m_iml.Create(IDB_ICONS_SML, 16, 0, RGB(255, 0, 255));
m_imlLarge.Create(IDB_ICONS, 32, 0, RGB(255, 0, 255));
m_imlMessage.Create(IDB_MSG_ICONS, 16, 0, RGB(255, 0, 255));
m_list.SetImageList(&m_imlLarge, LVSIL_NORMAL);
m_list.SetImageList(&m_iml, LVSIL_SMALL);
m_tree.SetImageList(&m_iml, TVSIL_NORMAL);
m_list.InsertColumn(0, _T("Hello"), LVCFMT_LEFT, 200);
HTREEITEM hItemRoot = m_tree.InsertItem(_T("Root item"), 0, 0);
for (int n = 0; n < 20; n++)
{
CString sItem;
sItem.Format(_T("Item %d"), n+1);
m_list.InsertItem(n, sItem, 0);
m_tree.InsertItem(sItem, 1, 1, hItemRoot);
m_listbox.AddString(sItem);
}
m_tree.Expand(hItemRoot, TVE_EXPAND);
AddInitialMessageBars();
return TRUE; // return TRUE unless you set the focus to a control
}
void CCtrlMessageBarDemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CDialog dlg(IDD_ABOUTBOX);
dlg.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// 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 CCtrlMessageBarDemoDlg::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 CCtrlMessageBarDemoDlg::OnQueryDragIcon()
{
return static_cast<HCURSOR>(m_hIcon);
}
void CCtrlMessageBarDemoDlg::AddInitialMessageBars()
{
bar.Detach();
VERIFY(bar.Attach(this));
bar.SetResize();
bar.SetImageList(&m_imlMessage);
bar.SetText(_T("This is a dialog message"), 3);
barEdit.Detach();
VERIFY(barEdit.Attach(m_edit));
barEdit.SetImageList(&m_imlMessage);
barEdit.Show(FALSE);
m_edit.SetWindowText(_T("Click in here to \r\nadd a message bar"));
barEdit.SetShowMenuCallback(CCMBEdit::CMB_ShowMenuCallback);
barList.Detach();
VERIFY(barList.Attach(m_list));
barList.SetImageList(&m_imlMessage);
barList.SetText(_T("This is a message bar in a list, which lights up on mouse-over"), 3);
barList.SetHighlightOnMouseOver(TRUE);
barTree.Detach();
VERIFY(barTree.Attach(m_tree));
barTree.SetImageList(&m_imlMessage);
barTree.SetText(_T("This is a wrapped message bar in a tree control, which is a non-default colour"), 1);
barTree.SetWrapText(TRUE);
barTree.SetColours(RGB(255, 192, 192), RGB(0, 0, 255));
barListBox.Detach();
VERIFY(barListBox.Attach(m_listbox));
barListBox.SetImageList(&m_imlMessage);
barListBox.SetText(_T("This is a message bar in a list, which is not wrapped, and is too long, so shows in a tool-tip"), 2);
barBtn.Detach();
VERIFY(barBtn.Attach(m_btn));
barBtn.SetResize();
barBtn.SetText(_T("Button message bar"));
}
void CCtrlMessageBarDemoDlg::OnReset()
{
AddInitialMessageBars();
}