CCreateContext context;
context.m_pNewViewClass=RUNTIME_CLASS( CMotionGalilView );  //类型是 CRuntimeClass*
context.m_pCurrentDoc=new CMotionScanPrjDoc();//CFrameWnd* ChildF;ChildF=new CFrameWnd();
context.m_pCurrentFrame = ChildF;ChildF->Create(NULL,"",WS_OVERLAPPEDWINDOW| WS_POPUPWINDOW,
rectDefault ,this,NULL,NULL,&context);通过这种方式创建的子窗体怎么接受到父窗体的自定义消息?试了各种方式,除了这种方式创建的窗体,别的方式就能响应父窗体分发的消息。我是在父窗体中通过SendMessageToDescendants 想子窗体传递的消息。MFCVC++

解决方案 »

  1.   

    只能显示指定接收消息的窗体句柄。创建窗体没有指定WS_CHILD或WS_CHILDWINDOW,系统会自动将指定的父窗体作为创建窗体的所有者窗体,而创建者窗体的父窗体为空,即桌面。在MSDN Library 2005/2008中索引一下GetAncestor函数吧,在线的MSDN居然相关页面已不存在了。
      

  2.   

    GetAncestor Function--------------------------------------------------------------------------------The GetAncestor function retrieves the handle to the ancestor of the specified window. SyntaxHWND GetAncestor(          HWND hwnd,
        UINT gaFlags
    );
    Parametershwnd
    [in] Handle to the window whose ancestor is to be retrieved. If this parameter is the desktop window, the function returns NULL. 
    gaFlags
    [in] Specifies the ancestor to be retrieved. This parameter can be one of the following values. 
    GA_PARENT
    Retrieves the parent window. This does not include the owner, as it does with the GetParent function. 
    GA_ROOT
    Retrieves the root window by walking the chain of parent windows.
    GA_ROOTOWNER
    Retrieves the owned root window by walking the chain of parent and owner windows returned by GetParent. 
    Return ValueThe return value is the handle to the ancestor window.
      

  3.   


    指明了WS_CHILD属性后,同样不响应消息,当然按照MSDN上的说明去掉了 WS_POPUPWINDOW 属性。
    而且我在子窗体中通过GetParent->PostMessage 父窗体的PreTranslateMessage 能接收到
      

  4.   


    指明了WS_CHILD属性后,同样不响应消息,当然按照MSDN上的说明去掉了 WS_POPUPWINDOW 属性。
    而且我在子窗体中通过GetParent->PostMessage 父窗体的PreTranslateMessage 能接收到 
      

  5.   


    在子窗体中GetParent()->PostMessage();