// MultiCtrlDemoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MultiCtrlDemo.h"
#include "MultiCtrlDemoDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMultiCtrlDemoDlg dialog
CMultiCtrlDemoDlg::CMultiCtrlDemoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMultiCtrlDemoDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CMultiCtrlDemoDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMultiCtrlDemoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMultiCtrlDemoDlg)
DDX_Control(pDX, IDC_BTN_READONLY, m_btnReadOnly);
DDX_Control(pDX, IDC_BTN_HIDDEN, m_btnHidden);
DDX_Control(pDX, IDC_BTN_LABEL_AUTO, m_btnAutoFitLabel);
DDX_Control(pDX, IDC_FLD, m_ctrl);
DDX_Control(pDX, IDC_COMBO_TYPE, m_comboType);
DDX_Control(pDX, IDC_BTN_NORMAL, m_btnNormal);
DDX_Control(pDX, IDC_EDIT_VALUE, m_editValue);
DDX_Control(pDX, IDC_EDIT_TOOLTIP, m_editTooltip);
DDX_Control(pDX, IDC_EDIT_LABEL, m_editLabel);
DDX_Control(pDX, IDC_BTN_NO_LABEL, m_btnNoLabel);
DDX_Control(pDX, IDC_BTN_BROWSE_BTN, m_btnBrowseBtn);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMultiCtrlDemoDlg, CDialog)
//{{AFX_MSG_MAP(CMultiCtrlDemoDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_CBN_SELENDOK(IDC_COMBO_TYPE, OnSelendokComboType)
ON_BN_CLICKED(IDC_FLD, OnFld)
ON_BN_CLICKED(IDC_BTN_SET_VALUE, OnBtnSetValue)
ON_BN_CLICKED(IDC_BTN_SET_TOOLTIP, OnBtnSetTooltip)
ON_BN_CLICKED(IDC_BTN_SET_LABEL, OnBtnSetLabel)
ON_BN_CLICKED(IDC_BTN_READONLY, OnBtnReadonly)
ON_BN_CLICKED(IDC_BTN_NORMAL, OnBtnNormal)
ON_BN_CLICKED(IDC_BTN_NO_LABEL, OnBtnNoLabel)
ON_BN_CLICKED(IDC_BTN_HIDDEN, OnBtnHidden)
ON_BN_CLICKED(IDC_BTN_DISABLED, OnBtnDisabled)
ON_BN_CLICKED(IDC_BTN_BROWSE_BTN, OnBtnBrowseBtn)
ON_BN_CLICKED(IDC_BTN_LABEL_AUTO, OnBtnLabelAuto)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMultiCtrlDemoDlg message handlers
const char szLabel[] = "My label";
const char szValue[] = "My value text";
const char szTooltip[] = "This is a multi control";
#define AddComboItem(combo, text, data) \
{ int n = combo.AddString(text); combo.SetItemData(n, data); }
// control type strings
#define CTS_NONE "(None)"
#define CTS_STATIC "Static"
#define CTS_STATICBTN "Static Button"
#define CTS_EDIT "Edit"
#define CTS_UPDOWNEDIT "Up/down"
#define CTS_DROPLIST "Droplist"
#define CTS_COMBO "Combo"
#define CTS_CHECKBOX "Checkbox"
#define CTS_DATETIME "Date/Time"
#define CTS_RICHEDIT "Rich Edit"
BOOL CMultiCtrlDemoDlg::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
AddComboItem(m_comboType, CTS_NONE, MCT_NONE);
AddComboItem(m_comboType, CTS_STATIC, MCT_STATIC);
AddComboItem(m_comboType, CTS_STATICBTN, MCT_STATICBTN);
AddComboItem(m_comboType, CTS_EDIT, MCT_EDIT);
AddComboItem(m_comboType, CTS_UPDOWNEDIT, MCT_UPDOWNEDIT);
AddComboItem(m_comboType, CTS_DROPLIST, MCT_DROPLIST);
AddComboItem(m_comboType, CTS_COMBO, MCT_COMBO);
AddComboItem(m_comboType, CTS_CHECKBOX, MCT_CHECKBOX);
AddComboItem(m_comboType, CTS_DATETIME, MCT_DATETIME);
AddComboItem(m_comboType, CTS_RICHEDIT, MCT_RICHEDIT);
m_comboType.SetCurSel(m_comboType.FindStringExact(-1, CTS_EDIT));
m_btnNormal.SetCheck(TRUE);
m_ctrl.SetType(MCT_EDIT);
m_ctrl.SetLabelText(szLabel);
m_btnAutoFitLabel.SetCheck(TRUE);
m_ctrl.SetLabelWidth(MCSLW_AUTO);
m_editLabel.SetWindowText(szLabel);
m_ctrl.SetValueText(szValue);
m_editValue.SetWindowText(szValue);
m_ctrl.SetHelpString(szTooltip);
m_editTooltip.SetWindowText(szTooltip);
return TRUE; // return TRUE unless you set the focus to a control
}
void CMultiCtrlDemoDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.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 CMultiCtrlDemoDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (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 to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CMultiCtrlDemoDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMultiCtrlDemoDlg::OnSelendokComboType()
{
// change the control type
int n = m_comboType.GetCurSel();
if (n == -1)
return;
m_ctrl.SetType((MULTICTRLTYPE)m_comboType.GetItemData(n));
}
void CMultiCtrlDemoDlg::OnFld()
{
AfxMessageBox("You clicked on the control");
}
void CMultiCtrlDemoDlg::OnBtnSetValue()
{
CString sValue;
m_editValue.GetWindowText(sValue);
m_ctrl.SetValueText(sValue);
}
void CMultiCtrlDemoDlg::OnBtnSetTooltip()
{
CString sTooltip;
m_editTooltip.GetWindowText(sTooltip);
m_ctrl.SetHelpString(sTooltip);
}
void CMultiCtrlDemoDlg::OnBtnSetLabel()
{
CString sLabel;
m_editLabel.GetWindowText(sLabel);
m_ctrl.SetLabelText(sLabel);
if (m_btnAutoFitLabel.GetCheck())
m_ctrl.SetLabelWidth(MCSLW_AUTO);
}
void CMultiCtrlDemoDlg::OnBtnReadonly()
{
int nAttrib = m_ctrl.GetAttributes();
m_ctrl.SetAttributes((nAttrib | MCA_READONLY) & ~MCA_DISABLED);
}
void CMultiCtrlDemoDlg::OnBtnNormal()
{
int nAttrib = m_ctrl.GetAttributes();
m_ctrl.SetAttributes(nAttrib & ~(MCA_READONLY | MCA_DISABLED));
}
void CMultiCtrlDemoDlg::OnBtnNoLabel()
{
int nAttrib = m_ctrl.GetAttributes();
if (m_btnNoLabel.GetCheck())
m_ctrl.SetAttributes(nAttrib | MCA_NOLABEL);
else
m_ctrl.SetAttributes(nAttrib & ~MCA_NOLABEL);
}
void CMultiCtrlDemoDlg::OnBtnHidden()
{
int nAttrib = m_ctrl.GetAttributes();
if (m_btnHidden.GetCheck())
m_ctrl.SetAttributes(nAttrib | MCA_HIDDEN);
else
m_ctrl.SetAttributes(nAttrib & ~MCA_HIDDEN);
}
void CMultiCtrlDemoDlg::OnBtnDisabled()
{
int nAttrib = m_ctrl.GetAttributes();
m_ctrl.SetAttributes((nAttrib | MCA_DISABLED) & ~MCA_READONLY);
}
void CMultiCtrlDemoDlg::OnBtnBrowseBtn()
{
int nAttrib = m_ctrl.GetAttributes();
if (m_btnBrowseBtn.GetCheck())
m_ctrl.SetAttributes(nAttrib | MCA_BROWSEBTN);
else
m_ctrl.SetAttributes(nAttrib & ~MCA_BROWSEBTN);
}
void CMultiCtrlDemoDlg::OnBtnLabelAuto()
{
if (m_btnAutoFitLabel.GetCheck())
m_ctrl.SetLabelWidth(MCSLW_AUTO);
else
m_ctrl.SetLabelWidth();
}