I'm trying to expand my knowledge of the Windows API. Why? I'm the curious type and I like a good challenge. So I went ahead and read the docs and came up with this.

#!/usr/bin/perl use strict; use warnings; use Win32::API; #Private Declare Function GetDC Lib "user32" (ByVal hWnd As Long) As L +ong Win32::API->Import( 'user32', 'long GetDC(long hWnd)', ); #Declare Function GetPixel Lib "gdi32" Alias "GetPixel" (ByVal hdc As +Long, ByVal x As Long, ByVal y As Long) As Long Win32::API->Import( 'gdi32', 'long GetPixel(long hdc, long x, long y)', ); sub PixelColor { my ($x, $y) = @_; my $dc = GetDC(''); my $rgb = sprintf "%06x", GetPixel(GetDC(''), $x, $y); return $rgb; } print PixelColor(100, 100), "\n";

Update: Changed "%x" to "%06x".


In reply to Re: Detect Pixel Color on WinXP by Mr. Muskrat
in thread Detect Pixel Color on WinXP by kesterkester

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.