AfxCallWndProc and Custom Control Development
Hi
In Programming with Microsoft Visual C++.NET book, author shows a custom
control dll. In his code:
/////////////////////////////////////////
LRESULT CALLBACK AFX_EXPORT
RygWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CWnd* pWnd;
pWnd = CWnd::FromHandlePermanent(hWnd);
if (pWnd == NULL) {
// Assume that client created a CRygWnd window
pWnd = new CRygWnd();
pWnd->Attach(hWnd);
}
ASSERT(pWnd->m_hWnd == hWnd);
ASSERT(pWnd == CWnd::FromHandlePermanent(hWnd));
LRESULT lResult = AfxCallWndProc(pWnd, hWnd, message,
wParam, lParam);
return lResult;
}
//////////////////////////////////////////
I downloaded The Ultimate Toolbox code, there is no call to AfxCallWndProc
For example:
///////////////////////////////////////////
BOOL COXTabViewContainer::Create(CWnd* pParentWnd, CRect
rect/*=CRect(0,0,0,0)*/,
DWORD dwStyle/*=WS_CHILD|WS_VISIBLE*/,
UINT nID/*=AFX_IDW_PANE_FIRST*/)
{
ASSERT(pParentWnd != NULL);
ASSERT(dwStyle & WS_CHILD);
ASSERT(nID != 0);
// the Windows scroll bar styles bits turn on the smart scrollbars
DWORD dwCreateStyle=dwStyle&~(WS_HSCROLL|WS_VSCROLL);
dwCreateStyle&=~WS_BORDER;
dwCreateStyle|=WS_CHILD;
// define our own window class
WNDCLASS wndClass;
wndClass.style=CS_DBLCLKS;
wndClass.lpfnWndProc=AfxWndProc;
wndClass.cbClsExtra=0;
wndClass.cbWndExtra=0;
wndClass.hInstance=AfxGetInstanceHandle();
wndClass.hIcon=0;
wndClass.hCursor=::LoadCursor(NULL,IDC_ARROW);
wndClass.hbrBackground=(HBRUSH)(COLOR_BTNFACE+1);
wndClass.lpszMenuName=NULL;
wndClass.lpszClassName=_T("TabViewContainer");
if(!AfxRegisterClass(&wndClass))
return FALSE;
if (!CreateEx(WS_EX_CLIENTEDGE,wndClass.lpszClassName,NULL,
dwCreateStyle,rect.left,rect.top,rect.Width(),rect.Height(),
pParentWnd->m_hWnd,(HMENU)(INT_PTR)nID,NULL))
{
return FALSE; // create invisible
}
// remove WS_EX_CLIENTEDGE style from parent window
pParentWnd->ModifyStyleEx(WS_EX_CLIENTEDGE, 0, SWP_DRAWFRAME);
// sign
::SetWindowLongPtr(GetSafeHwnd(),GWL_USERDATA,ID_TABVIEWCONTAINER_SIGN);
SetScrollStyle(0,TRUE);
CalcLayout();
return TRUE;
}
///////////////////////////////////////////
In MSJ for AfxCallWndProc:
"You can think of AfxWndProc as a function with a big switch statement that
routes WM_XXX messages to your window class's OnXXX handler functions. This
is a first-order approximation of how AfxWndProc works:
// This is a gross simplification
LRESULT AfxWndProc(HWND hwnd, UINT msg, ...)
{
CWnd* pWnd = CWnd::FromHandle(hwnd);
switch (msg) {
case WM_CREATE:
pWnd->OnCreate(...);
return 0;
case WM_SETFOCUS:
pWnd->OnSetFocus(...);
return 0;
..
..
..
// etc.
}
return 0L;
}"
If AfxWndProc routes WM_XXX messages to window class's OnXXX handler
functions, why didn't Ultimate toolbox use it?
If i derive a class from any MFC wnd class(CWnd, CFrameWnd, CEdit etc...)
haven't it got all the default wndproc for messages(because i derived it from
CWnd class)? So why do we need to call AfxWndProc?