Jump to content

GetPixel?


 Share

Recommended Posts

http://msdn.microsoft.com/library/default....itmaps_0rho.asp

Can't get it to work. Also noticing I have to use 'long' when it says ptr/int etc. in the DLL thread in the dev section.

Global $Handle

Sleep(2000)
; Chang "test" to the window you'll be testing
PixelDrawConstructor( $Handle, "test" )

$GetPixel = GetPixel($Handle, 5, 5)

MsgBox ( "","",  $Handle[1] & "   -   " & $GetPixel[0])

Func PixelDrawConstructor(ByRef $DLLHandle, $WindowTitle)
   $DLLHandle = DllCall ("user32.dll", "int", "GetDC", "hwnd", WinGetHandle($WindowTitle, ""))
EndFunc

Func GetPixel($DLLHandle, $x, $y)
   return DllCall( "gdi32", "long", "GetPixel", "long", $DLLHandle[1], "long", $x, "long", $y )
EndFunc
"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

bump*

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

bump AGAIN*!

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

Thanks. I have an entire period dedicated to programming now, I'll see if I can figure out the problem.

Thanks for clearing things up, once again.

EDIT:

Noticed you edited:

;Newer code below.

EDIT AGAIN:

Why am I using all these wrong data types? Are they even working?

I'm using what layer was using, which is blatantly different then the ones specified in the DLL Call thread in the dev section. Are those wrong?

Edited by Insolence
"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

;===================================================================;
; Settings                                                       ;
;===================================================================;
Opt("WinTitleMatchMode", 2)

;===================================================================;
; Variables                                                     ;
;===================================================================;
Global $Handle

;===================================================================;
; Script                                                           ;
;===================================================================;
; Change to the window you'll be testing
DCConstructor ( $Handle, "SciTE" )

$GetPixel = GetPixel ( $Handle, 5, 5 )

MsgBox ( "", "", $Handle & "   -   " & $GetPixel )

DCDescructor ( $Handle, "SciTE" )

;===================================================================;
; Functions                                                     ;
;===================================================================;
Func DCConstructor ( ByRef $HDC, $WindowTitle )
    #CS 
    
        HDC GetDC(
          HWND hWnd   // handle to window
        );
        
    #CE
    
    $HDC = DllCall ("user32.dll", "ptr", "GetDC", "hwnd", WinGetHandle( $WindowTitle ) )
    $HDC = $HDC[0]
EndFunc  ;==>DCConstructor

Func GetPixel ( $HDC, $x, $y )
    #CS 
    
        COLORREF GetPixel(
          HDC hdc,  // handle to DC
          int nXPos,  // x-coordinate of pixel
          int nYPos   // y-coordinate of pixel
        );
        
    #CE
    
    Local $ret
    $ret = DllCall( "gdi32", "int", "GetPixel", "ptr", $HDC, "int", $x, "int", $y )
    Return $ret[0]
EndFunc  ;==>GetPixel

Func DCDescructor ( ByRef $HDC, $WindowTitle )
    #CS 
    
        int ReleaseDC(
          HWND hWnd,  // handle to window
          HDC hDC    // handle to DC
        );
    
    #CE
    
    $HDC = DllCall ( "user32.dll", "int", "ReleaseDC", "hwnd", WinGetHandle( $WindowTitle ), "ptr", $HDC )
EndFunc  ;==>DCDescructor

All I got so far... seems like the DC is getting set perfectly, as it returns a value.

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

bump*

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

Bumpage*

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

Alright, thanks Lar-bear, I'll try that after school :lmao:

;===================================================================;
; Settings                                                       ;
;===================================================================;
Opt("WinTitleMatchMode", 2)

;===================================================================;
; Variables                                                     ;
;===================================================================;
Global $Handle

;===================================================================;
; Script                                                           ;
;===================================================================;
; Change to the window you'll be testing
DCConstructor ( $Handle, "SciTE" )

$GetPixel = GetPixel ( $Handle, 5, 5 )

MsgBox ( "", "", $Handle & "   -   " & $GetPixel )

DCDescructor ( $Handle, "SciTE" )

;===================================================================;
; Functions                                                     ;
;===================================================================;
Func DCConstructor ( ByRef $HDC, $WindowTitle )
    #CS 
    
        HDC GetDC(
          HWND hWnd   // handle to window
        );
        
    #CE
    
    $HDC = DllCall ("user32.dll", "ptr", "GetDC", "hwnd", WinGetHandle( $WindowTitle ) )
    $HDC = $HDC[0]
EndFunc  ;==>DCConstructor

Func GetPixel ( $HDC, $x, $y )
    #CS 
    
        COLORREF GetPixel(
          HDC hdc,  // handle to DC
          int nXPos,  // x-coordinate of pixel
          int nYPos   // y-coordinate of pixel
        );
        
    #CE
    
    Local $ret
    $ret = DllCall( "gdi32", "int", "GetPixel", "int", $HDC, "int", $x, "int", $y )
    Return $ret[0]
EndFunc  ;==>GetPixel

Func DCDescructor ( ByRef $HDC, $WindowTitle )
    #CS 
    
        int ReleaseDC(
          HWND hWnd,  // handle to window
          HDC hDC    // handle to DC
        );
    
    #CE
    
    $HDC = DllCall ( "user32.dll", "int", "ReleaseDC", "hwnd", WinGetHandle( $WindowTitle ), "ptr", $HDC )
EndFunc  ;==>DCDescructor

Returns -1

Edited by Insolence
"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

Alright, works now.

Cannot get pixels of an inactive window (I suppose that's good), damnit.

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...