📄 buttondemodlg.cpp
字号:
// ButtonDemoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ButtonDemo.h"
#include "ButtonDemoDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CButtonDemoDlg dialog
CButtonDemoDlg::CButtonDemoDlg(CWnd* pParent /*=NULL*/)
: CDialog(CButtonDemoDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CButtonDemoDlg)
m_checkvalue1 = FALSE;//多选按钮选项1未被选中
m_checkvalue2 = FALSE;//多选按钮选项2未被选中
m_checkvalue3 = FALSE;//多选按钮选项3未被选中
m_radio = 0;//第一单项按钮选中
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CButtonDemoDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CButtonDemoDlg)
DDX_Control(pDX, IDC_CHECK3, m_check3);
DDX_Control(pDX, IDC_CHECK2, m_check2);
DDX_Control(pDX, IDC_CHECK1, m_check1);
DDX_Check(pDX, IDC_CHECK1, m_checkvalue1);
DDX_Check(pDX, IDC_CHECK2, m_checkvalue2);
DDX_Check(pDX, IDC_CHECK3, m_checkvalue3);
DDX_Radio(pDX, IDC_RADIO1, m_radio);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CButtonDemoDlg, CDialog)
//{{AFX_MSG_MAP(CButtonDemoDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
ON_BN_CLICKED(IDC_OK, OnOk)
ON_BN_CLICKED(IDC_RESET, OnReset)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CButtonDemoDlg message handlers
BOOL CButtonDemoDlg::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
/* CButton *p_MyBut = new CButton();
CRect rect(10,10,30,20);
p_MyBut->Create("动态创建",WS_CHILD|WS_VISIBLE,rect,this,IDS_MYBUTTON);
p_MyBut->SetWindowPos(0,10,10,30,20,SWP_SHOWWINDOW);
p_MyBut->ShowWindow(SW_SHOW);*/
return TRUE; // return TRUE unless you set the focus to a control
}
void CButtonDemoDlg::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 CButtonDemoDlg::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 CButtonDemoDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CButtonDemoDlg::OnRadio1()
{
// TODO: Add your control notification handler code here
m_radio=0;
m_check1.SetWindowText("数据库设计");//设置第一个多选项标题
m_check2.SetWindowText("网站开发");//设置第二个多选项标题
m_check3.SetWindowText("语言编程");//设置第三个多选项标题
}
void CButtonDemoDlg::OnRadio2()
{
// TODO: Add your control notification handler code here
m_radio=1;
m_check1.SetWindowText("电路设计");//设置第一个多选项标题
m_check2.SetWindowText("光电子技术");//设置第二个多选项标题
m_check3.SetWindowText("无线通信");//设置第三个多选项标题
}
void CButtonDemoDlg::OnRadio3()
{
// TODO: Add your control notification handler code here
m_radio=2;
m_check1.SetWindowText("商务英语");//设置第一个多选项标题
m_check2.SetWindowText("德语法语");//设置第二个多选项标题
m_check3.SetWindowText("其他小语种");//设置第三个多选项标题
}
void CButtonDemoDlg::OnOk()
{
// TODO: Add your control notification handler code here
UpdateData(true);//获取用户的输入
if((!m_checkvalue1)&&(!m_checkvalue2)&&(!m_checkvalue3))//复选框为空
{
AfxMessageBox("必须选择精通科目!");
return;//退出响应
}
GetDlgItem(IDCANCEL)->ShowWindow(SW_SHOW);//显示“退出窗口”按钮
GetDlgItem(IDC_RESET)->EnableWindow(true);//“重置”按钮生效
CString str,str1; //字符串
switch(m_radio)
{
case 0: //第一个单选项被选中
GetDlgItem(IDC_RADIO1)->GetWindowText(str1);//获取单选项标题
str="专业方向:"+str1+" 精通科目:";
break;
case 1: //第二个单选项被选中
GetDlgItem(IDC_RADIO2)->GetWindowText(str1);//获取单选项标题
str="专业方向:"+str1+" 精通科目:";
break;
case 2: //第三个单选项被选中
GetDlgItem(IDC_RADIO3)->GetWindowText(str1);//获取单选项标题
str="专业方向:"+str1+" 精通科目:";
break;
}
if(m_checkvalue1)//第一个多选项被选中
{
m_check1.GetWindowText(str1);//获取多选项标题
str=str+str1;
}
if(m_checkvalue2)//第二个多选项被选中
{
m_check2.GetWindowText(str1);//获取多选项标题
str=str+str1;
}
if(m_checkvalue3)//第三个多选项被选中
{
m_check3.GetWindowText(str1);//获取多选项标题
str=str+str1;
}
AfxMessageBox(str);//显示提示框
}
void CButtonDemoDlg::OnReset()
{
// TODO: Add your control notification handler code here
m_radio=0;//选中单选项1
m_checkvalue1=m_checkvalue2=m_checkvalue3=false;//复选项都未被选中
UpdateData(false);//更新对话框
GetDlgItem(IDC_RESET)->EnableWindow(false);//“重置”按钮无效
GetDlgItem(IDCANCEL)->ShowWindow(SW_HIDE);//隐藏“退出窗口”按钮
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -