ex13dlg.cpp
来自「一些VC++的经典实例」· C++ 代码 · 共 261 行
CPP
261 行
// ex13Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "ex13.h"
#include "ex13Dlg.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()
/////////////////////////////////////////////////////////////////////////////
// CEx13Dlg dialog
CEx13Dlg::CEx13Dlg(CWnd* pParent /*=NULL*/)
: CDialog(CEx13Dlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CEx13Dlg)
m_name = _T("");
m_describe = _T("");
m_interest1 = FALSE;
m_interest2 = FALSE;
m_interest3 = FALSE;
m_list = _T("");
m_data = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CEx13Dlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CEx13Dlg)
DDX_Control(pDX, IDC_COMBO1, m_ComboCtrl);
DDX_Text(pDX, IDC_NAME, m_name);
DDX_Text(pDX, IDC_DESCRIBE, m_describe);
DDX_Check(pDX, IDC_CHECK1, m_interest1);
DDX_Check(pDX, IDC_CHECK2, m_interest2);
DDX_Check(pDX, IDC_CHECK3, m_interest3);
DDX_LBString(pDX, IDC_LIST1, m_list);
DDX_Scroll(pDX, IDC_SLIDER1, m_pos);
DDX_Text(pDX, IDC_DATA, m_data);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CEx13Dlg, CDialog)
//{{AFX_MSG_MAP(CEx13Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_CBN_DROPDOWN(IDC_COMBO1, OnDropdownCombo1)
ON_BN_CLICKED(ID_UPDATE, OnUpdate)
ON_BN_CLICKED(IDC_SEX1, OnSex1)
ON_BN_CLICKED(IDC_SEX2, OnSex2)
ON_BN_CLICKED(ID_CLEAR, OnClear)
ON_WM_VSCROLL()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CEx13Dlg message handlers
BOOL CEx13Dlg::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
// 初始化List控件
CListBox * birthplace=(CListBox *)GetDlgItem(IDC_LIST1);
birthplace->InsertString(-1,"成都");
birthplace->InsertString(-1,"北京");
birthplace->InsertString(-1,"资中");
birthplace->InsertString(-1,"内江");
//初始化ScrollBar控件
m_pos = 0;
CSliderCtrl * ability=(CSliderCtrl *)GetDlgItem(IDC_SLIDER1);
ability->SetRange(0,100);
ability->SetPos(m_pos);
m_data.Format("%d",ability->GetPos());
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CEx13Dlg::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 CEx13Dlg::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 CEx13Dlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CEx13Dlg::OnDropdownCombo1()
{
// TODO: Add your control notification handler code here
m_ComboCtrl.ResetContent();
m_ComboCtrl.AddString("初中");
m_ComboCtrl.AddString("高中");
m_ComboCtrl.AddString("本科");
m_ComboCtrl.AddString("硕士");
m_ComboCtrl.AddString("博士");
}
void CEx13Dlg::OnUpdate()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
}
void CEx13Dlg::OnSex1()
{
// TODO: Add your control notification handler code here
m_sex=TRUE;
}
void CEx13Dlg::OnSex2()
{
// TODO: Add your control notification handler code here
m_sex=FALSE;
}
void CEx13Dlg::OnClear()
{
// TODO: Add your control notification handler code here
m_describe.Empty();
m_name.Empty();
m_interest1=FALSE;
m_interest2=FALSE;
m_interest3=FALSE;
m_ComboCtrl.ResetContent();
m_list.Empty();
UpdateData(FALSE);
}
void CEx13Dlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
{
// TODO: Add your message handler code here and/or call default
CSliderCtrl * pSlide=(CSliderCtrl *)pScrollBar;
UpdateData(TRUE);
m_data.Format("%d",pSlide->GetPos());
UpdateData(FALSE);
CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?