WS_POPUP 改为 WS_CHILD
Create以后 ModifyStyle(WS_CHILD, WS_POPUP, ……); SetParent(NULL) 试试看

解决方案 »

  1.   

    不能使用WS_POPUP,这个风格给模态对话框用的
      

  2.   

    基本控件可以使用WS_POPUP,前提是必须使用CreateEx来创建(这个可以在afxwin.h找到原话)
      

  3.   

    嗯 我查MSDN也是这么说的,Release版本能编译通过,而且我查看底层代码,发现CreateEx之后调用的是CWnd::Create()函数,而CWnd有CreateEx()函数,为什么不调用后者呢。
      

  4.   

    实践出真知。将WS_POPUP改成WS_CHILD肯定没问题。
    但是Create中加WS_POPUP就会有问题
    // can't use for desktop or pop-up windows (use CreateEx instead)
    ASSERT(pParentWnd != NULL);
    ASSERT((dwStyle & WS_POPUP) == 0);
    这是Create中的代码我怎么看到的是Create最后调用的CreateEx呢?BOOL CWnd::Create(LPCTSTR lpszClassName,
    LPCTSTR lpszWindowName, DWORD dwStyle,
    const RECT& rect,
    CWnd* pParentWnd, UINT nID,
    CCreateContext* pContext)
    {
    // can't use for desktop or pop-up windows (use CreateEx instead)
    ASSERT(pParentWnd != NULL);
    ASSERT((dwStyle & WS_POPUP) == 0); return CreateEx(0, lpszClassName, lpszWindowName,
    dwStyle | WS_CHILD,
    rect.left, rect.top,
    rect.right - rect.left, rect.bottom - rect.top,
    pParentWnd->GetSafeHwnd(), (HMENU)(UINT_PTR)nID, (LPVOID)pContext);
    }
      

  5.   

    CTreeCtrl::CreateEx 
    virtual BOOL CreateEx(
       DWORD dwExStyle,
       DWORD dwStyle,
       const RECT& rect,
       CWnd* pParentWnd,
       UINT nID
    );
    CTreeCtrl类重载了CreateEx函数
      

  6.   

    6楼说的不错,是我的叙述错了,debug下关键是遇到了 ASSERT((dwStyle & WS_POPUP)==0);导致的问题,我思前想后发现 既然他最终调用的是CWnd::CreateEx()函数,我就用强制类型转换试试,结果发现我的想法是正确的。问题已经解决。把其中一句改成 ((CWnd&)m_Tree).CreateEx(0, WC_TREEVIEW, NULL, dwStyle, rect, GetParent(), 0, NULL); 就可以了
      

  7.   

    ////////////////////////////////////////////////////////////////////////////////////////////////
    m_pMyWnd->CreateEx(WS_EX_CLIENTEDGE,
    AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW,::LoadCursor(NULL, IDC_ARROW), HBRUSH(COLOR_WINDOW+1),NULL), 
    _T("MyPopupWindow"),WS_POPUP | WS_VISIBLE ,CRect(0, 0, 100, 100),this,NULL,NULL);
    ////////////////////////////////////////////////////////////////////////////////////////////////要先注册再创建