新建两个对DIALOGBAR对话框和相关连的类,第二个对话框类做为第一个对话框的成员。把第一个对话框的style设置成child用来框覆盖掉视图窗口,代码如下:
void CChildView::OnSize(UINT nType, int cx, int cy)
{
CWnd::OnSize(nType, cx, cy);
if(pViewDlg == NULL)
{
pViewDlg =  new CViewDlg;
pViewDlg->Create(IDD_DIALOGBAR,this);
}
CRect clientRect;
GetClientRect(clientRect);

pViewDlg->SetWindowPos((CWnd *)HWND_TOP,0,0,clientRect.Width(),clientRect.Height(),SWP_SHOWWINDOW);
}
第二个对话框做为第一个对话框的成员并把style属性设成Popup,border属性设成dialog frame。在第一个对话框的OnInitDialog函数创建非模态对话框2
BOOL CViewDlg::OnInitDialog()
{
CDialog::OnInitDialog();
if(pPopDlg == NULL)
{
pPopDlg = new CPopDlg;
pPopDlg->Create(IDD_DIALOGBAR1,this);
} return TRUE;  // return TRUE unless you set the focus to a control

}
这时有第二个对话框的OnInitDialog获取第一个对话框中的成员数据是无效数据。代码如下
BOOL CPopDlg::OnInitDialog()
{
CDialog::OnInitDialog();
int ver,vol;
ver = ((CViewDlg *)GetParent())->GetVer();
vol = ((CViewDlg *)GetParent())->GetVol();
return TRUE;  
}
其中变量ver和vol都是无效的。但是如果把第二个对话框的style属性设成child后,ver,vol的值就是正确的值了。谁知道是什么原因不?

解决方案 »

  1.   

    真心受不了CSDN没人回答还要给分。
      

  2.   

    style属性设成popup,相当于两个DIALOG?
      

  3.   

    如果是Popup风格,你那里的GetParent得到不是View类的CWnd指针,而应该是主框架类即CMainFrame类的指针。
      

  4.   

    HWND GetParent(HWND);If the window is a child window, the return value is a handle to the parent window. If the window is a top-level window, the return value is a handle to the owner window. If the window is a top-level unowned window or if the function fails, the return value is NULL. To get extended error information, call GetLastError. For example, this would determine, when the function returns NULL, if the function failed or the window was a top-level window.
      

  5.   

    这里写错了,不是“View",而是”CViewDlg“
      

  6.   

    因为第二个对话框设置了Popup属性,所以你不能用GetParent()而应该用GetOwer().