in reply to Re: Detect Pixel Color on WinXP
in thread Detect Pixel Color on WinXP
Well, that's the theory. In practice I always get#Private Declare Function ReleaseDC Lib "user32" (ByVal hWnd As Long, +ByVal hDC As Long) As Long Win32::API->Import( 'user32', 'long ReleaseDC(long hWnd, long hDC)', ); #Private Declare Function GetDesktopWindow Lib "user32" () As Long Win32::API->Import( 'user32', 'long GetDesktopWindow()', ); sub PixelColor { my ($hwnd, $x, $y) = @_; my $dc = GetDC($hwnd); my $rgb = GetPixel($dc, $x, $y); ReleaseDC($hwnd, $dc); return $rgb < 0 ? undef: sprintf "%06x", $rgb; } print PixelColor(GetDesktopWindow(), 100, 100);
p.s. This hWnd should be a property of your control or canvas, or whatever terminology you might be used to.
p.p.s. For people who feel like trying this out, make sure you have at least version 0.40 of Win32::API, or you'll get a deep recursion error on the Import method — something to do with AUTOLOAD, because that method doesn't exist. Needless to say, it won't work, either.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Detect Pixel Color on WinXP
by Mr. Muskrat (Canon) on Sep 16, 2003 at 13:05 UTC |