关于MFC中CWnd::CreateEx的一点疑惑
以下是从MFC中复制的代码.
BOOL CWnd::CreateEx(DWORD dwExStyle, LPCTSTR lpszClassName,
LPCTSTR lpszWindowName, DWORD dwStyle,
int x, int y, int nWidth, int nHeight,
HWND hWndParent, HMENU nIDorHMenu, LPVOID lpParam)
{
// allow modification of several common create parameters
CREATESTRUCT cs;
cs.dwExStyle = dwExStyle;
cs.lpszClass = lpszClassName;
cs.lpszName = lpszWindowName;
cs.style = dwStyle;
cs.x = x;
cs.y = y;
cs.cx = nWidth;
cs.cy = nHeight;
cs.hwndParent = hWndParent;
cs.hMenu = nIDorHMenu;
cs.hInstance = AfxGetInstanceHandle();
cs.lpCreateParams = lpParam;
if (!PreCreateWindow(cs))
{
PostNcDestroy();
return FALSE;
}
AfxHookWindowCreate(this);
HWND hWnd = ::CreateWindowEx(cs.dwExStyle, cs.lpszClass,
cs.lpszName, cs.style, cs.x, cs.y, cs.cx, cs.cy,
cs.hwndParent, cs.hMenu, cs.hInstance, cs.lpCreateParams);
#ifdef _DEBUG
if (hWnd == NULL)
{
TRACE1("Warning: Window creation failed: GetLastError returns 0x%8.8X\n",
GetLastError());
}
#endif
if (!AfxUnhookWindowCreate())
PostNcDestroy(); // cleanup if CreateWindowEx fails too soon
if (hWnd == NULL)
return FALSE;
ASSERT(hWnd == m_hWnd); // should have been set in send msg hook
return TRUE;
}
上面函数的最后:ASSERT(hWnd == m_hWnd); // should have been set in send msg hook
问题:他说m_hWnd被赋值,在发送hook消息的时候. 但是阅读上面代码 ,在创建窗口之后根本没有发送这个消息,唯一可能的地方就是"if (!AfxUnhookWindowCreate())",但是我查看了AfxUnhookWindowCreate()函数,也没有发送过什么消息啊.请高手指点......
BOOL CWnd::CreateEx(DWORD dwExStyle, LPCTSTR lpszClassName,
LPCTSTR lpszWindowName, DWORD dwStyle,
int x, int y, int nWidth, int nHeight,
HWND hWndParent, HMENU nIDorHMenu, LPVOID lpParam)
{
// allow modification of several common create parameters
CREATESTRUCT cs;
cs.dwExStyle = dwExStyle;
cs.lpszClass = lpszClassName;
cs.lpszName = lpszWindowName;
cs.style = dwStyle;
cs.x = x;
cs.y = y;
cs.cx = nWidth;
cs.cy = nHeight;
cs.hwndParent = hWndParent;
cs.hMenu = nIDorHMenu;
cs.hInstance = AfxGetInstanceHandle();
cs.lpCreateParams = lpParam;
if (!PreCreateWindow(cs))
{
PostNcDestroy();
return FALSE;
}
AfxHookWindowCreate(this);
HWND hWnd = ::CreateWindowEx(cs.dwExStyle, cs.lpszClass,
cs.lpszName, cs.style, cs.x, cs.y, cs.cx, cs.cy,
cs.hwndParent, cs.hMenu, cs.hInstance, cs.lpCreateParams);
#ifdef _DEBUG
if (hWnd == NULL)
{
TRACE1("Warning: Window creation failed: GetLastError returns 0x%8.8X\n",
GetLastError());
}
#endif
if (!AfxUnhookWindowCreate())
PostNcDestroy(); // cleanup if CreateWindowEx fails too soon
if (hWnd == NULL)
return FALSE;
ASSERT(hWnd == m_hWnd); // should have been set in send msg hook
return TRUE;
}
上面函数的最后:ASSERT(hWnd == m_hWnd); // should have been set in send msg hook
问题:他说m_hWnd被赋值,在发送hook消息的时候. 但是阅读上面代码 ,在创建窗口之后根本没有发送这个消息,唯一可能的地方就是"if (!AfxUnhookWindowCreate())",但是我查看了AfxUnhookWindowCreate()函数,也没有发送过什么消息啊.请高手指点......
...全文
相关推荐
吕鑫:《VC++就业培训宝典之MFC视频教程》第十一章 第一节 调用CWnd::Create和CWnd::CreateEx函数手动创建控件
1、调用CWnd::Create函数手动创建编辑框、下拉控件以及按钮等控件;2、调用CWnd::CreateEx函数手动创建下陷风格的编辑框和列表控件等;3、调用CWnd::Create函数手动创建日
CWnd-MFC中文手册
创建子窗口的过程通常分为两步:首先,调用CWnd构造函数创建CWnd对象,接着调用Create成员函数创建子窗口并将其与CWnd对象关联。
MFC中自定义窗口类名技巧
#### 示例代码分析```cppBOOL CWnd::CreateEx(DWORD dwExStyle, LPCTSTR lpszClassName, LPCTSTR lpszWindowName,
mfc实现点击一个窗口弹出另一个窗口
**创建新窗口**: 弹出新窗口通常通过Create或CreateEx函数完成,这些函数需要提供窗口类名、父窗口句柄、窗口样式等参数。新窗口类也需要继承自CWnd,并有自己的消息映射。5.
MFC调用QT类库
若要在MFC中动态创建QT控件,例如QLabel或QPushButton,你需要继承自CWnd类并重写CreateEx方法。然后在CreateEx中创建QT的控件,并将其添加到MFC的窗口中。


