标签:
对话框直接添加类,类向导添加时出现了问题。
因此便想通过添加C++类的方式间接实现添加对话框类。
第一步:添加C++类
#pragma once class CWordCountDlg { public: CWordCountDlg(void); ~CWordCountDlg(void); };
#include "StdAfx.h" #include "WordCountDlg.h" CWordCountDlg::CWordCountDlg(void) { } CWordCountDlg::~CWordCountDlg(void) { }
第二步: 扩展成MFC对话框类
#include "resource.h" //0 #pragma once class CWordCountDlg:public CDialog //1 基类 { DECLARE_DYNAMIC(CWordCountDlg) //2 public: // 对话框数据 enum { IDD = IDD_WORD_COUNT }; //3对话框关联ID public: CWordCountDlg(void); ~CWordCountDlg(void); protected: virtual void DoDataExchange(CDataExchange* pDX); //4 数据关联 DECLARE_MESSAGE_MAP() //5 消息映射 public: virtual BOOL OnInitDialog(); //6 初始化 };
#include "StdAfx.h" #include "WordCountDlg.h" IMPLEMENT_DYNAMIC(CWordCountDlg, CDialog) // 0 CWordCountDlg::CWordCountDlg(void): CDialog(CWordCountDlg::IDD, NULL) //1 { } CWordCountDlg::~CWordCountDlg(void) { } void CWordCountDlg::DoDataExchange(CDataExchange* pDX) //2 { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(CWordCountDlg, CDialog) //3 ON_BN_CLICKED(IDOK, &CWordCountDlg::OnBnClickedOk) END_MESSAGE_MAP() BOOL CWordCountDlg::OnInitDialog() //4 { CDialog::OnInitDialog(); return TRUE; // return TRUE unless you set the focus to a control // 异常: OCX 属性页应返回 FALSE }
标签:
原文地址:http://blog.csdn.net/shuilan0066/article/details/42147097