实验七-MFC-控件编程实验
实验七 MFC 控件编程实验
一、实验目的
(1) 熟悉Visual C++ 6.0 开发环境; (2) 掌握MFC 环境下标准控件的使用方法;
(3) 熟练掌握在Visual C++ 6.0 开发环境调试程序的方法。
二、实验内容
创建如图所示的应用程序,在“形状”列表框中选择要绘制的图形,在“笔颜 色”下拉列表框中选择画笔的颜色,在“刷子颜色”下拉列表框中选择画刷的颜色,
在“线型”组框中选择画笔的线型,在“填充类型”中选择画刷填充类型,单击“绘图”按钮
在“绘图设置”编辑框中显示选择的绘图设置选项,单击“退出”按钮退 出程序。
三、程序代码
// testDlg.cpp : implementation file //
#include \#include \#include \
#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()
/////////////////////////////////////////////////////////////////
////////////
// CTestDlg dialog
CTestDlg::CTestDlg(CWnd* pParent /*=NULL*/) : CDialog(CTestDlg::IDD, pParent) { //{{AFX_DATA_INIT(CTestDlg) m_pen = -1; m_brush = -1; m_Output = _T(\ //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); }
void CTestDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CTestDlg) DDX_Control(pDX, IDC_LIST1, m_list); DDX_Control(pDX, IDC_COMBO2, m_cb2); DDX_Control(pDX, IDC_COMBO1, m_cb1); DDX_Radio(pDX, IDC_RADIO1, m_pen); DDX_Radio(pDX, IDC_RADIO5, m_brush); DDX_Text(pDX, IDC_OUTPUT, m_Output); //}}AFX_DATA_MAP }
BEGIN_MESSAGE_MAP(CTestDlg, CDialog) //{{AFX_MSG_MAP(CTestDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_EN_CHANGE(IDC_OUTPUT, OnChangeOutput) ON_BN_CLICKED(IDC_BUTTON1, OnButton1) ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1) ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1) ON_CBN_SELCHANGE(IDC_COMBO2, OnSelchangeCombo2) ON_CBN_EDITCHANGE(IDC_COMBO2, OnSelchangeCombo2) //}}AFX_MSG_MAP END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////
////////////
// CTestDlg message handlers
BOOL CTestDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add \ // 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_list.AddString(\
m_list.AddString(\ m_list.AddString(\ m_list.AddString(\ m_cb1.AddString(\ m_cb1.AddString(\ m_cb1.AddString(\ return TRUE; // return TRUE unless you set the focus to a control }
void CTestDlg::OnSysCommand(UINT nID, LPARAM lParam)