请问: MFC 中,CWnd* m_pMainWnd 成员的疑问?

时间:2022-02-22 21:23:22
我有以下代码:


// .h 文件

#include "resource.h"                 // 资源文件


class MySound : public CWinApp         // 应用程序类
{
public:
virtual BOOL InitInstance(); // 初始化
};



class MyMainWindow : public CDialog       // 以对话框为主窗口
{
public:
MyMainWindow( CWnd* pDlog = NULL );

enum{ IDD = IDD_MYSOUNDLG };       // 对话框主窗口的 ID
};





// .cpp 文件

#include "afxwin.h"
#include "MySound.h"




MySound myApp; // 定义应用程序对象






/////////////////////////////////////////////////////////////

BOOL
MySound::InitInstance() // 初始化应用程序
{
CWinApp::InitInstance();


m_pMainWnd = new MyMainWindow;

m_pMainWnd->DoModal();


return FALSE;


}


MyMainWindow::MyMainWindow( CWnd* pParent ) : CDialog( MyMainWindow::IDD, pParent )
{
}


debug 时,提示:

'DoModal' : is not a member of 'CWnd'


按我的理解,m_pMainWnd 是 CWnd*;而 CDialog 是 CWnd 的派生类。
那么,我用 m_pMainWnd 指向 CDialog 的派生类对像应该没问题吧?

m_pMainWnd->DoModal();   这行为什么出错呢?

3 个解决方案

#1


不行。父类(CWnd)没有实现'DoModal' 方法。

#2


谢谢楼上!

#3


看来高人指点,我就接点分了,

#1


不行。父类(CWnd)没有实现'DoModal' 方法。

#2


谢谢楼上!

#3


看来高人指点,我就接点分了,