I am still unable to understand how this source code extracts text from dialog box controls within a given rectangle boundry of a 3rd party application?



Code:
HHOOK	hHook = NULL;
TCHAR	szBuff[2048]; // any buffer
CString ScrapeText(HWND hWnd, RECT& rect)
{
	hHook = SetWindowHookEx(WH_CALLWNDPROC, (HOOKPROC)CallWndProc, AfxGetApp()->GetCurrentInstance(), GetCurrentThread);
		
	RedrawWindow(hWnd, (const RECT*)&rect, NULL,RDW_ALLCHILDREN);

	// unhook after processing
	UnHookWindowsEx(hHook);
	return szBuff; // after concactenation from hook procedure
}

LRESULT CALLBACK CallWndProc(int nCode, WPARAM wParam, LPARAM lParam )
{
	if( nCode < 0 )
		return CallNextHookEx( hHook, nCode, wParam, lParam);

	MSG* pMsg = (MSG*)lParam;

	switch( nCode )
	{
	case HC_ACTION:
		if( pMsg->message == WM_SETTEXT && CLASSOF(pMsg->hWnd) ){
			_tcscat(szBuff, (LPCTSTR)lParam);
		}
		break;
	default:
		break;
	}
	return CallNextHookEx(hHook, nCode, wParam, lParam);
}