-
October 27th, 2009, 10:07 PM
#1
GetPixel() in Fullscreen mode
Code:
HDC myhdc;
HWND myhwnd;
DWORD color;
int r, g, b;
myhwnd= GetForegroundWindow();
myhdc= GetWindowDC(myhwnd);
POINT lp;
GetCursorPos(&lp);
color = GetPixel(myhdc, lp.x, lp.y);
r = GetRValue(color );
g = GetGValue(color );
b = GetBValue(color );
ReleaseDC(myhwnd,myhdc);
FillRect(10,10,10,10, r,g,b,255);
This works fine in window mode, I know it has something to do with getting the DC but Im not quite sure how I would make it work for fullscreen or make it cross compatible between fullscreen/window modeif needed.
Thanks :]
-
October 27th, 2009, 11:26 PM
#2
Re: GetPixel() in Fullscreen mode
Um... when is this code getting executed? This looks like Win32 code rather than MFC code (?). You rarely want to do any graphics work except in response to a WM_PAINT message, in which case you'll be able to get the device context by calling BeginPaint.
Otherwise, you can call GetDC using the HWND you got from CreateWindow, but you shouldn't be writing to the screen outside of responding to WM_PAINT. I would put the GetPixel in there as well and store the value for later use if that's what you need.
-
October 27th, 2009, 11:37 PM
#3
Re: GetPixel() in Fullscreen mode
Its written in endscene in direct x
I write out the rgb values and they are messed. its not just the drawing
Last edited by RogerThat123; October 27th, 2009 at 11:44 PM.
-
October 27th, 2009, 11:58 PM
#4
Re: GetPixel() in Fullscreen mode
I know almost nothing about DirectX, but from the little bit I've toyed with it, isn't there a call to CreateWindow at the beginning of the program to create an always-on-top window? You should be able to get the HWND from that and thereby its DC.
Hopefully someone knowing more about DirectX can help. Sorry. :-(
-
October 28th, 2009, 12:16 AM
#5
Re: GetPixel() in Fullscreen mode
Well it works in windowed mode, thats the thing ? So i have no idea why that would affect it,
-
October 28th, 2009, 06:15 AM
#6
Re: GetPixel() in Fullscreen mode
Since it's DirectX. The better solution would be to avoid using GDI altogether and retrive the pixel you need directly from the DirectX canvas you used to draw the image on.
GDI's GetPixel is terribly terribly bad performance, especially when Desktop Composition is enabled. It'll just ruin any kind of performance you're trying to achieve.
Then again, it's fairly safe to say that any kind of "get pixel" approach to just about anything is most likely already ridden by poor design issues. There's very little need to ever use GetPixel or similar in a proper graphics program.
-
October 28th, 2009, 06:19 AM
#7
Re: GetPixel() in Fullscreen mode
Also note that while full screen DirectX needs you to make a top level window. Even obtaining a handle to that window does not guarantee you can read pixel values from DirectX.
Acceleration features in the graphic card may circumvent the GDI and the window entirely and accelerate screen updates by writing to the videoframe buffer directly.
-
October 28th, 2009, 10:15 AM
#8
Re: GetPixel() in Fullscreen mode
Well im not concerned about performance really. Its for a project.
-
October 28th, 2009, 10:20 AM
#9
Re: GetPixel() in Fullscreen mode
To get a DC for the entire screen you need the ::GetDCEx from the Win32 (not the one from the MFC).
-
October 28th, 2009, 11:03 AM
#10
Re: GetPixel() in Fullscreen mode
TargethDC = GetDCEx (TargetHwnd, NULL, NULL);
sorta works, doesnt give the correct color but it does change color at least, the color sort of resembles what its over sometimes but not a lot.
Its ok to pass NULL Im assuming
-
October 29th, 2009, 08:38 AM
#11
Re: GetPixel() in Fullscreen mode
The above probably won't work as expected if desktop composition is enabled (in Vista/ Win7).
you can force a read on a composed pixel by requesting a screen DC (not a window DC)
Code:
CDC dcScreen;
dcScreen.CreateDC(_T("DISPLAY"), NULL, NULL, NULL);
But expect this to be slowing down things a lot. Depending on your videocard, this could be as bad as slowing down the framerate of your DirectX program by a factor 10. If you need to read several pixels, you probably want to look for alternate solutions.
-
November 11th, 2009, 02:13 AM
#12
Re: GetPixel() in Fullscreen mode
Originally Posted by RogerThat123
Code:
HDC myhdc;
HWND myhwnd;
DWORD color;
int r, g, b;
myhwnd= GetForegroundWindow();
myhdc= GetWindowDC(myhwnd);
POINT lp;
GetCursorPos(&lp);
color = GetPixel(myhdc, lp.x, lp.y);
r = GetRValue(color );
g = GetGValue(color );
b = GetBValue(color );
ReleaseDC(myhwnd,myhdc);
FillRect(10,10,10,10, r,g,b,255);
This works fine in window mode, I know it has something to do with getting the DC but Im not quite sure how I would make it work for fullscreen or make it cross compatible between fullscreen/window modeif needed.
Thanks :]
Is this what you looking for?
Code:
HDC dc = ::GetDC(0); // will get dc to entire screen
color = GetPixel(dc, lp.x, lp.y);
::ReleaseDC(0,dc);
Cheers
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|