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 simplificat