一个主窗口A,创建一个非模态的对话框B,B有WS_CHILD属性,并把B的父窗口指定为A;
B再创建一个非模态对话框C,C没有WS_CHILD属性,并把C的父窗口指定为B。我想在C中给B发消息,但是B中总是无响应,一步步跟踪发现C的GetParent函数返回的窗口句柄是A的句柄,在A中才能响应到消息,十分不解,求高手指点。对话框创建时指定的父窗口对象肯定是正确的A类中:
new B(this);
B->Create(IDD_B, this);B类中:
new C(this);
C->Create(IDD_C, this);消息映射也加的是正确的mfc  子窗口 父窗口 非模态

解决方案 »

  1.   

    没有WM_CHILD的属性造成。。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
      

  2.   


    请问这是哪里写的,vc6.0带的MSDN里的GetParent的说明没有这句话啊?Call this function to get a pointer to a child window’s parent window (if any). The GetParent function returns a pointer the immediate parent. In contrast, the GetParentOwner function returns a pointer to the most immediate parent or owner window that is not a child window (does not have the WS_CHILD style). If you have a child window within a child window GetParent and GetParentOwner return different results. 我看着意思应该是GetParentOwner返回第一个没有WS_CHILD style的父窗口句柄啊,而GetParent返回父窗口句柄,不管是否有WS_CHILD style
      

  3.   

    VS2008 MSDN 记得升级换代
      

  4.   

    WS_POPUP类型的窗口的所有者是在CreateWindow函数中通过设置hWndParent参数给定的,如果hWndParent不是子窗口,则该窗口就成为这个新的弹出式窗口的owner,否则,系统从hWndParent的父窗口向上找,直到找到第一个非子窗口,把它作为该弹出窗口的owner。当owner窗口销毁的时候,系统自动销毁这个弹出窗口。