GetPixel Color

Started by
3 comments, last by RogerThat123 14 years, 7 months ago
 
        HDC TargethDC;
	HWND TargetHwnd;
	DWORD ColorR;
	
	TargetHwnd = GetForegroundWindow();
	TargethDC = GetWindowDC(TargetHwnd);

	ColorR = GetPixel(TargethDC,gMouse.x,gMouse.y);
	
	ReleaseDC(TargetHwnd,TargethDC);

	r = GetRValue(ColorR);
	g = GetGValue(ColorR);
	b = GetBValue(ColorR);
gMouse is my custom mouse coordinates that return the mouse coordinate inside my application starting from 0,0 top left inside all windows borders. I need it to not return any colors of the windows border, you know the top window bar and edges around. As I said its an artificial mouse, and it returns the coordinate from the top left of my window (not including window outline). ... also, this method doesnt work when its in full screen, what should I use rather than GetForegroundWindow to work for full screen? [Edited by - RogerThat123 on October 10, 2009 8:59:54 PM]
Advertisement
If full screen you could just get the pixel from your backbuffer/frontbuffer
Are you using directx?
When you do GetWindowDC() you're getting a device context of the entire window. If you used GetDC() instead you'd get a device context for the client area of the window (i.e. the area without the caption bar and borders)
In terms of the GetForegroundWindow() problem, you can use WindowFromPoint(), given you convert your mouse coordinates to screen coordinates. You'd be the only one that would know how to do this conversion. But if you're using 0,0 as top left and you're using pixel units you can probably use ClientToScreen() to do the conversion.

Again, as mentioned before, if you're using DirectX then there are probably better ways to be doing this.
GetDC made the color onlycapture if i like moved the mouse really quick while holding the mouse button and if i left it on a pixel for 0.02 seconds or more it would just change to black or white.

im not using direct x no

This topic is closed to new replies.

Advertisement