How does Get_Object_From_Window work? << Back

Get_Object_From_Window is a command defined in VDFBase.pkg. Most people are not aware of the existence of such command. Anyway, it retrieves the object handle from a window handle. This command will not work with any ActiveX controls (such as cCjGrid/cCJReportControl) Internally, the object handle is stored inside the "extra bytes" inside the window handle. In order to retrieve the object handle from a window handle, you need to call GetWindowLong. The function GetClassLong is going to give you how many extra bytes the window has. Note that the actual object handle is AFTER the byte 0x000000DF. The following C code is going to show you how to retrieve the object handle from a window handle. This article is a precursor to an in-depth look at possibility of VDF automation (which has been done already!) I am building that article up a little by little :)

DWORD GetObjectFromWindow(HWND hWnd)
	DWORD dwOffset = GetClassLong(hWnd,GCL_CBWNDEXTRA);
	BOOL bObjectHandle = FALSE;
	for (DWORD dwCurrent = 0; dwOffset>=4; dwOffset-=4, dwCurrent+=4)
		DWORD dwAddress = GetWindowLong(hWnd,dwCurrent);
		if (bObjectHandle) return dwAddress;
		if (dwAddress == 0xDF) bObjectHandle = TRUE;
	return 0;
Free Web Hosting