Jump to content
  • Advertisement
Sign in to follow this  
RogerThat123

GetPixel Color

This topic is 3354 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

 
        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]

Share this post


Link to post
Share on other sites
Advertisement
If full screen you could just get the pixel from your backbuffer/frontbuffer
Are you using directx?

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!