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)
(wincore.cpp)

BOOL CWnd::PreCreateWindow(CREATESTRUCT& cs)
判断lpszClass 是否注册若为空,则注册为默认的AFX_WND_REG

由于该PreCreateWIndow是个虚函数,所以可以在该函数中设置自己的窗口属性。

MFC将所有的窗口处理函数都注册成DefWndProc,那是不是MFC将所有的消息都发送到DefWndProc中去了呢?很抱歉不是,而是都发送到了AfxWndProc函数去了。你可能要问为什么,这也是我想知道的,那我们就看看MFC代码吧:
BOOL CWnd::CreateEx(...)
{
...
PreCreateWindow(cs);
AfxHookWindowCreate(this);
HWND hWnd = ::CreateWindowEx(...);
...
}
void AFXAPI AfxHookWindowCreate(CWnd *pWnd)
{
...
pThreadState->m_hHookOldCbtFilter =
::SetWindowsHookEx(WH_CBT,_AfxCbtFilterHook,NULL,::GetCurrentThreadId());
...
}
_AfxCbtFilterHook(int code, WPARAM wParam, LPARAM lParam)
{
...
if(!afxData.bWin31)
{
_AfxStandardSubclass((HWND)wParam);
}
...
}
void AFXAPI _AfxStandardSubclass(HWND hWnd)
{
...
oldWndProc =
(WNDPROC)SetWindowLong(hWnd,GWL_WNDPROC,(DWORD)AfxGetAfxWndProc());
}
WNDPROC AFXAPI AfxGetAfxWndProc()
{
...
return &AfxWndProc;
}

http://www.vckbase.com/document/viewdoc/?id=1048

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值