我的程序是这样的:
void CCreateButtonView::OnRButtonDown(UINT nFlags, CPoint point) 
{    CWnd m_ax;
    LPCTSTR pszName = "MSDBGrid.DBGrid";
                     //控件的ProgID ,这里我用的是DBGrid32.ocx
    m_ax.CreateControl (pszName,NULL, WS_VISIBLE | WS_CHILD, 
CRect(100,100,200,200), this, AFX_IDW_PANE_FIRST);
    m_ax.ShowWindow(SW_SHOW);    CView::OnRButtonDown(nFlags, point);
}想要实现的功能是:在View中右键单击动态创建DBGrid.ocx控件的子窗体,通过调试发现没有问题,创建成功,但就是不能将创建的控件显示出来。
   最奇怪的是,如果我在m_ax.ShowWindow(SW_SHOW);之后加上一句              AfxMessageBox("hehe");创建的子窗体居然能显示出来了,请高手指点,这到底是怎么回事啊?应该怎么解决?多谢

解决方案 »

  1.   

    这样呢?
    m_ax.CreateControl (pszName,NULL, WS_VISIBLE ,CRect(100,100,200,200), this, AFX_IDW_PANE_FIRST);  WS_CHILD似乎不能被CreateControl 识别:Only a subset of the Windows dwStyle flags are supported for CreateControl: WS_VISIBLE   Creates a window that is initially visible. Required if you want the control to be visible immediately, like ordinary windows.
    WS_DISABLED   Creates a window that is initially disabled. A disabled window cannot receive input from the user. Can be set if the control has an Enabled property.
    WS_BORDER   Creates a window with a thin-line border. Can be set if control has a BorderStyle property.
    WS_GROUP   Specifies the first control of a group of controls. The user can change the keyboard focus from one control in the group to the next by using the direction keys. All controls defined with the WS_GROUP style after the first control belong to the same group. The next control with the WS_GROUP style ends the group and starts the next group.
    WS_TABSTOP   Specifies a control that can receive the keyboard focus when the user presses the TAB key. Pressing the TAB key changes the keyboard focus to the next control of the WS_TABSTOP style. 
      

  2.   

    多谢!但我试了一下,把WS_CHILD去掉,还是不好使,情况没有变化。thanks anyway~
      

  3.   

    把 m_ax 定义成 CCreateButtonView 的成员,不要定义成方法的局部变量
      

  4.   

    问题解决,确实是CWnd::~CWnd时调用DestroyWindow的问题,将CWnd m_ax;定义为全局变量就ok了,多谢大家!