如下函数
void CT4View::OnInitialUpdate()
{
         ...
         ...
fd=new FindData;               //fd是视图类成员,FindData是对话框类
fd->Create(IDD_DIALOG1);
fd->SetParent(this);
         ...
}
CT4View是我的视图类.本来觉得fd->setParent(this)执行后对话框的父窗口就是视图窗口了,可是在spy++中发现这个对话框的父窗口却是程序的主框架窗口,而视图窗口的第一个子窗口却是这个对话框。就是说 B 是 A 的子窗口但 A 却不是 B 的父窗口,好矛盾.使得GetParent()得到的结果不是想要的,发送消息给视图窗口也送不到.

解决方案 »

  1.   

    你这个对话框是否具有WS_CHILD样式?
      

  2.   

    要区分Parent和Owner,而GetParent()是不区分的。GetParent FunctionReturn ValueIf 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.ResNote that, despite its name, this function can return an owner window instead of a parent window. To obtain the parent window and not the owner, use GetAncestor with the GA_PARENT flag.
      

  3.   

    把对话框设置WS_CHILD后在SPY++中看到对话框是视图窗的子窗,视图窗也是对话框的父窗,本来以弄好了,可是视图类却再也对菜单消息和快捷键消息没了反应,使得连对话框都弹不出来,因为对话框是在按F3后显示的,本想用来做个查找对话框