dave2k
November 14th, 2005, 11:42 AM
so far this works, but was wondering whether there is a more code-efficient way of getting the value of a pixel from a window, even if it's covered?
::GetWindowRect(hWnd, &rc);
int w = rc.right-rc.left;
int h = rc.bottom-rc.top;
HDC hdc = ::GetDC(0);
HDC memDC = ::CreateCompatibleDC ( hdc );
HBITMAP memBM = ::CreateCompatibleBitmap ( hdc, w, h );
HBITMAP hOld = (HBITMAP)::SelectObject ( memDC, memBM );
tPrintWindow pPrintWindow = 0;
HINSTANCE handle = GetModuleHandle("user32.dll");
if ( handle == 0 )
handle = LoadLibrary("User32.dll");
if ( handle )
pPrintWindow = (tPrintWindow)GetProcAddress(handle, "PrintWindow");
if ( pPrintWindow )
pPrintWindow(hWnd, memDC, 0 );
COLORREF cr = GetPixel(memDC, 10, 10);
if(cr != CLR_INVALID)
{
// make a string
char psz[100];
sprintf(psz, "%x", cr);
// print
MessageBox(NULL, psz, "working", MB_OK);
}
cheers
::GetWindowRect(hWnd, &rc);
int w = rc.right-rc.left;
int h = rc.bottom-rc.top;
HDC hdc = ::GetDC(0);
HDC memDC = ::CreateCompatibleDC ( hdc );
HBITMAP memBM = ::CreateCompatibleBitmap ( hdc, w, h );
HBITMAP hOld = (HBITMAP)::SelectObject ( memDC, memBM );
tPrintWindow pPrintWindow = 0;
HINSTANCE handle = GetModuleHandle("user32.dll");
if ( handle == 0 )
handle = LoadLibrary("User32.dll");
if ( handle )
pPrintWindow = (tPrintWindow)GetProcAddress(handle, "PrintWindow");
if ( pPrintWindow )
pPrintWindow(hWnd, memDC, 0 );
COLORREF cr = GetPixel(memDC, 10, 10);
if(cr != CLR_INVALID)
{
// make a string
char psz[100];
sprintf(psz, "%x", cr);
MessageBox(NULL, psz, "working", MB_OK);
}
cheers