Fetching the pixel color outside you'r app.

Windows specific questions.
Post Reply
TbbW
Posts: 348
Joined: Aug 19, 2005 10:08
Contact:

Fetching the pixel color outside you'r app.

Post by TbbW »

Anyone know how to get the color of a pixel outside you'r FB app ?

As if the color of you'r background pic on you'r desktop is green then it returns green.

Or if i where to move a window over the cordinate where it's monitoring it would return a diffrent color.
TbbW
Posts: 348
Joined: Aug 19, 2005 10:08
Contact:

Post by TbbW »

Got the answer from mysoft on irc:

Code: Select all

dim as hdc ScreenDC = GetDC(GetDesktopWindow())
dim as uinteger BGRA = GetPixel(ScreenDC,X,Y)
Eponasoft
Posts: 264
Joined: Jul 26, 2007 2:40

Post by Eponasoft »

By the way, it's "your", not "you'r".

Your = something that belongs to you, something that is yours.
You're = a short version of "you are".

"You're going home to your wife."
TbbW
Posts: 348
Joined: Aug 19, 2005 10:08
Contact:

Post by TbbW »

Eponasoft wrote:By the way, it's "your", not "you'r".

Your = something that belongs to you, something that is yours.
You're = a short version of "you are".

"You're going home to your wife."
That post you just did contributed absolutly 0 to this or any other topic of this forum.

You'r wife/mommy must be proud.
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Post by counting_pine »

@TbbW, Ordinarily I'd agree about spelling pedantry, but "you'r" is a particularly egregious error. Are you doing it deliberately?
TbbW
Posts: 348
Joined: Aug 19, 2005 10:08
Contact:

Post by TbbW »

counting_pine wrote:@TbbW, Ordinarily I'd agree about spelling pedantry, but "you'r" is a particularly egregious error. Are you doing it deliberately?
First post, no call it a slip on the kboard.

Third post, yes.
Mihail_B
Posts: 273
Joined: Jan 29, 2008 11:20
Location: Romania
Contact:

Post by Mihail_B »

TbbW wrote:Got the answer from mysoft on irc:

Code: Select all

dim as hdc ScreenDC = GetDC(GetDesktopWindow())
dim as uinteger BGRA = GetPixel(ScreenDC,X,Y)
This doesn't seem to work .... (WinXP SP5) ....
I get all the time : &hffffffff ... strange ...(it seems i'll have to use the classical method ... unless you come with some answer ....)
FotonCat
Posts: 37
Joined: Nov 26, 2009 11:47
Location: Russia
Contact:

Post by FotonCat »

This doesn't seem to work .... (WinXP SP5) ....
I get all the time : &hffffffff ... strange ...(it seems i'll have to use the classical method ... unless you come with some answer ....)
Maybe this is because you use Windows XP Service Pack 5
:) Windows XP has only three official Service Packs :)
MichaelW
Posts: 3500
Joined: May 16, 2006 22:34
Location: USA

Post by MichaelW »

The desktop window is not the screen - it’s effectively the window that is below all of the other windows. Your GetPixel call is returning CLR_INVALID, indicating that the specified pixel is outside of the current clipping region, and as the code below shows, this is because the desktop window has an empty clipping region.

Code: Select all

#include "windows.bi"
dim as HDC hdcDesktop, hdcScreen
dim as COLORREF c
dim as RECT rc
hdcDesktop = GetDC( GetDesktopWindow() )
print "CLR_INVALID = "; hex(CLR_INVALID);"h"
if GetPixel(hdcDesktop,10,10) = CLR_INVALID then
    print "pixel is outside of current clipping region"
end if
print "NULLREGION = "; NULLREGION
if GetClipBox( hdcDesktop, @rc ) = NULLREGION then
    print "region is empty"
end if
print rc.left, rc.top, rc.right, rc.bottom
print
hdcScreen = GetDC(0)
print hex(GetPixel( hdcScreen, 10, 10 ));"h"
print "SIMPLEREGION = "; SIMPLEREGION
if GetClipBox( hdcScreen, @rc ) = SIMPLEREGION then
    print "region is a single rectangle"
end if
print rc.left, rc.top, rc.right, rc.bottom
sleep

Code: Select all

CLR_INVALID = FFFFFFFFh
pixel is outside of current clipping region
NULLREGION =  1
region is empty
 0             0             0             0

808080h
SIMPLEREGION =  2
region is a single rectangle
 0             0             1280          1024
GetDesktopWindow

GetDC

GetPixel

GetClipBox
Post Reply