Windows Messages and Pixel colors..
-
Is it possible to grab a certain pixel's color using WM messages? If so, which WM should I send and what kind of wParam and lParam would I need to send? Thanks, ~Mike
you can use GetPixel
COLORREF GetPixel( HDC hdc, // handle to DC int nXPos, // x-coordinate of pixel int nYPos // y-coordinate of pixel );
why do you need SendMessage ? -
you can use GetPixel
COLORREF GetPixel( HDC hdc, // handle to DC int nXPos, // x-coordinate of pixel int nYPos // y-coordinate of pixel );
why do you need SendMessage ? -
Because I need to retrieve pixel colors from an inactive window.. Is it possible? Thanks ~Mike
__Cerb wrote: Is it possible? not sure... an inactive window isn't drawn!! .. needs to get the wm_paint to be redrawn..
-
__Cerb wrote: Is it possible? not sure... an inactive window isn't drawn!! .. needs to get the wm_paint to be redrawn..
-
What about ::GetDC(HWND hwnd) and ::ScreenToClient(HWND hwnd, LPPOINT lpPoint) ??? is there a way I could use those to get a pixel color?
-
What about ::GetDC(HWND hwnd) and ::ScreenToClient(HWND hwnd, LPPOINT lpPoint) ??? is there a way I could use those to get a pixel color?
if you have the window handle then use
GetWindowDC
to get the HDC (device context) then useGetPixel
directly... but the problem is when the window needs repaint.. in this case it amy give you another color,,, try this first and let us know the results :) -
if you have the window handle then use
GetWindowDC
to get the HDC (device context) then useGetPixel
directly... but the problem is when the window needs repaint.. in this case it amy give you another color,,, try this first and let us know the results :)Damn, it still won't work.
CString szWndName,szWndClass; szWndName = "My window"; szWndClass = "My window's class"; HWND hwnd = ::FindWindow(szWndName,szWndClass); ::PostMessage(hwnd,WM_PAINT,0,0); HDC hDC = ::GetWindowDC(hwnd); CString str; int iPixel; iPixel = ::GetPixel(hDC,50,75); str.Format("%d",iPixel); AfxMessageBox(str);
It keeps returning -1, and it should return 263172 Any ideas? -
Damn, it still won't work.
CString szWndName,szWndClass; szWndName = "My window"; szWndClass = "My window's class"; HWND hwnd = ::FindWindow(szWndName,szWndClass); ::PostMessage(hwnd,WM_PAINT,0,0); HDC hDC = ::GetWindowDC(hwnd); CString str; int iPixel; iPixel = ::GetPixel(hDC,50,75); str.Format("%d",iPixel); AfxMessageBox(str);
It keeps returning -1, and it should return 263172 Any ideas? -
can you tell me what is the purpose of this operation ? maybe wecan find a way around it... why do you need to get the color of an in-active window ?