📄 combodlg.cpp
字号:
// ComboDlg.cpp : implementation file
//
#include "stdafx.h"
//#include "ExmpCombo.h"
#include "ExmpTabCtl.h" // 修改为应用程序类头文件
#include "ComboDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CComboDlg dialog
CComboDlg::CComboDlg(CWnd* pParent /*=NULL*/)
: CDialog(CComboDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CComboDlg)
m_strCtrlName = _T("");
//}}AFX_DATA_INIT
}
void CComboDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CComboDlg)
DDX_Control(pDX, IDC_COMBOCTRLNAME, m_ComboBx);
DDX_CBString(pDX, IDC_COMBOCTRLNAME, m_strCtrlName);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CComboDlg, CDialog)
//{{AFX_MSG_MAP(CComboDlg)
ON_CBN_SELCHANGE(IDC_COMBOCTRLNAME, OnSelchangeComboctrlname)
ON_BN_CLICKED(IDC_BUTNAPPLY, OnButnApply)
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CComboDlg message handlers
void CComboDlg::OnSelchangeComboctrlname()
{
// TODO: Add your control notification handler code here
if(pWndCtrl!=NULL)
{
delete pWndCtrl; // 删除上一次生成的控件对象
pWndCtrl=NULL;
}
int nChoice=m_ComboBx.GetCurSel(); // 获得当前选项的索引
switch(nChoice) // 根据选项生成不同类型的控件对象
{
case 0:
pWndCtrl=new CStatic;
((CStatic*)pWndCtrl)->Create(_T("Static Text"),WS_VISIBLE,CRect(180,40,300,70),this,1);
break;
case 1:
pWndCtrl=new CEdit;
((CEdit*)pWndCtrl)->Create(WS_VISIBLE|WS_BORDER,CRect(180,40,300,70),this,2);
break;
case 2:
pWndCtrl=new CButton;
((CButton*)pWndCtrl)->Create(_T("Group Box"),WS_VISIBLE|BS_GROUPBOX,CRect(180,40,300,100),this,3);
break;
case 3:
pWndCtrl=new CButton;
((CButton*)pWndCtrl)->Create(_T("Button"),WS_VISIBLE|WS_DISABLED|BS_PUSHBUTTON,CRect(180,40,300,70),this,4);
break;
case 4:
pWndCtrl=new CButton;
((CButton*)pWndCtrl)->Create(_T("Check Box"),WS_VISIBLE|BS_CHECKBOX,CRect(180,40,300,70),this,5);
break;
case 5:
pWndCtrl=new CButton;
((CButton*)pWndCtrl)->Create(_T("Radio Button"),WS_VISIBLE|BS_RADIOBUTTON,CRect(180,40,300,70),this,6);
break;
case 6:
pWndCtrl=new CComboBox;
((CComboBox*)pWndCtrl)->Create(WS_VISIBLE|CBS_DROPDOWN,CRect(180,40,300,100),this,7);
break;
case 7:
pWndCtrl=new CListBox;
((CListBox*)pWndCtrl)->Create(WS_VISIBLE|WS_BORDER,CRect(180,40,300,100),this,8);
break;
case 8:
pWndCtrl=new CScrollBar;
((CScrollBar*)pWndCtrl)->Create(WS_VISIBLE|SBS_VERT,CRect(250,40,280,100),this,9);
break;
default: // 没有选择列表项
pWndCtrl=new CStatic;
((CStatic*)pWndCtrl)->Create(_T("No any Control"),WS_VISIBLE,CRect(180,40,300,70),this,1);
break;
}
}
void CComboDlg::OnButnApply()
{
// TODO: Add your control notification handler code here
if(pWndCtrl!=NULL)
{
delete pWndCtrl; // 删除上一次生成的控件对象
pWndCtrl=NULL;
}
UpdateData();
pWndCtrl=new CStatic;
((CStatic*) pWndCtrl)->Create(_T("Static Text :\n"+m_strCtrlName),
WS_VISIBLE,CRect(180,40,300,80),this,10); // 创建静态文本控件
}
BOOL CComboDlg::OnInitDialog() // 初始化对话框时调用
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
pWndCtrl=NULL; // 初始化控件对象指针
return TRUE;
}
void CComboDlg::OnDestroy() // 关闭对话框时调用
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
if(pWndCtrl!=NULL) delete pWndCtrl; // 删除最后生成的控件对象
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -