0

我有一个CFormView- 派生类,它有一个我试图调用的按钮ShowWindow。但是,此调用失败,因为m_hWnd变量为空。为什么 m_hWnd 为空?该对话框child在属性窗口中设置了样式,并且我将父级CFrameWnd与表单视图相关联。此视图旨在实现无模式。

创建视图的代码:

void CMainFrame::SwitchEditView(CRuntimeClass * pViewClass)
{
    context.m_pNewViewClass=pViewClass;
    context.m_pCurrentDoc=pDoc;
    context.m_pNewDocTemplate=NULL;
    context.m_pLastView=NULL;
    context.m_pCurrentFrame=this;

    m_subSplitter.CreateView(0,1,pViewClass,CSize(0,0), &context); // create new view and add it to the splitter window
}

我的 CFormView 派生类的构造函数:

CDFAManEditViewProject::CDFAManEditViewProject()
: CFormView(CDFAManEditViewProject::IDD)
{
    // c_btnEdit is a CButton MFC control
    c_btnEdit.ShowWindow(SW_SHOW); // this call fails on ASSERT(::IsWindow(m_hWnd) )
}
4

1 回答 1

0

您正在尝试从视图构造函数访问编辑控件。但是在构造函数运行时还没有创建视图窗口。这就是为什么您还没有 m_hWnd 和编辑控件的原因。

将控件的初始化移动到视图的 OnInitialUpdate 中。

于 2013-08-07T19:20:26.173 回答