为什么CTreeCtrl类用CreateEx创建WS_POPUP风格树控件debug下出现断言错误,如何解决 WS_POPUP 改为 WS_CHILDCreate以后 ModifyStyle(WS_CHILD, WS_POPUP, ……); SetParent(NULL) 试试看 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不能使用WS_POPUP,这个风格给模态对话框用的 基本控件可以使用WS_POPUP,前提是必须使用CreateEx来创建(这个可以在afxwin.h找到原话) 嗯 我查MSDN也是这么说的,Release版本能编译通过,而且我查看底层代码,发现CreateEx之后调用的是CWnd::Create()函数,而CWnd有CreateEx()函数,为什么不调用后者呢。 实践出真知。将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);} CTreeCtrl::CreateEx virtual BOOL CreateEx( DWORD dwExStyle, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID);CTreeCtrl类重载了CreateEx函数 6楼说的不错,是我的叙述错了,debug下关键是遇到了 ASSERT((dwStyle & WS_POPUP)==0);导致的问题,我思前想后发现 既然他最终调用的是CWnd::CreateEx()函数,我就用强制类型转换试试,结果发现我的想法是正确的。问题已经解决。把其中一句改成 ((CWnd&)m_Tree).CreateEx(0, WC_TREEVIEW, NULL, dwStyle, rect, GetParent(), 0, NULL); 就可以了 ////////////////////////////////////////////////////////////////////////////////////////////////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);////////////////////////////////////////////////////////////////////////////////////////////////要先注册再创建 多线程 http连接占用带宽问题? 定义对象错误 关于Windows下Grep搜索问题 在深圳工作过年回家买点什么好 深圳好像没什么特产? 怎么让DialogBar中的一个Button相应如下消息? 为什么从文件中读数据到char指针数组再delete[] 指针数组出错? sizeof(void*)*1是什么意思哦 新手的问题? 重情重义的进来看一看..... 求问为什么打不开bmp图片?! MFC编辑框将输入识别为十六进制字符而不是字符串 CFileDialog保存文件问题
但是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);
}
virtual BOOL CreateEx(
DWORD dwExStyle,
DWORD dwStyle,
const RECT& rect,
CWnd* pParentWnd,
UINT nID
);
CTreeCtrl类重载了CreateEx函数
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);
////////////////////////////////////////////////////////////////////////////////////////////////要先注册再创建