AutoHotkey Community

It is currently May 27th, 2012, 1:27 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 18 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: April 14th, 2010, 11:38 am 
This code seems to work on Windows XP as well.

Code:
 
;(id = mywindowid)
WinGetPos,,,Width ,Height , ahk_id id
device := DllCall("GetDC", UInt, id)
context := DllCall("gdi32.dll\CreateCompatibleDC", UInt, device)
pixels := DllCall("gdi32.dll\CreateCompatibleBitmap", UInt, device, Int, Width, Int, Height)
DllCall("gdi32.dll\SelectObject", UInt, context, UInt, pixels)
DllCall("PrintWindow", "UInt", id, UInt, context, UInt, 0)
PixelRetrieved := DllCall("GetPixel", UInt, context, Int, X, Int, Y)
DllCall("ReleaseDC", "UInt", id, "UInt", device)
DllCall("gdi32.dll\DeleteDC", UInt, context)
DllCall("gdi32.dll\DeleteObject", UInt, pixels)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: September 11th, 2011, 7:43 pm 
Offline

Joined: July 6th, 2008, 9:19 am
Posts: 101
Hi i'm trying to get the colour of pixel that is hidden behind other windows. I've tried the test code in this thead and it works when i switch to aero theme. But for some reason I cant get it to work. Must be miss applying something somewhere. Any Ideas?

Code:
a::
WinGet, active_id, ID, A
pc_wID = ahk_id %active_id%

colour := PixelColor(20, 386, pc_wID)
PixelGetColor, OutputVar, 20, 386
MsgBox, newfunction : %colour% Built in: %OutputVar%

return



PixelColor(pc_x, pc_y, pc_wID)
{   
   If pc_wID
   {
      pc_hDC := DllCall("GetDC", "UInt", pc_wID)
      WinGetPos, , , pc_w, pc_h, ahk_id %pc_wID%
      pc_hCDC := DllCall("CreateCompatibleDC", "UInt", pc_hDC)
      pc_hBmp := DllCall("CreateCompatibleBitmap", "UInt", pc_hDC, "Int", pc_w, "Int", pc_h)
      pc_hObj := DllCall("SelectObject", "UInt", pc_hCDC, "UInt", pc_hBmp)
      DllCall("PrintWindow", "UInt", pc_wID, "UInt", pc_hCDC, "UInt", 0)
      pc_fmtI := A_FormatInteger
      SetFormat, IntegerFast, Hex
      pc_c := DllCall("GetPixel", "UInt", pc_hCDC, "Int", pc_x, "Int", pc_y, "UInt")
      pc_c := pc_c >> 16 & 0xff | pc_c & 0xff00 | (pc_c & 0xff) << 16
      pc_c .= ""
      SetFormat, IntegerFast, %pc_fmtI%
      DllCall("DeleteObject", "UInt", pc_hBmp)
      DllCall("DeleteDC", "UInt", pc_hCDC)
      DllCall("ReleaseDC", "UInt", pc_wID, "UInt", pc_hDC)
      ;MsgBox, colour: %pc_c%
      Return pc_c
   }
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: September 11th, 2011, 8:02 pm 
Code:
a::
WinGet, active_id, ID, A
colour := PixelColor(20, 386, active_id)
PixelGetColor, OutputVar, 20, 386,rgb
MsgBox, newfunction : %colour% Built in: %OutputVar%

return



PixelColor(pc_x, pc_y, pc_wID)
{   
   If pc_wID
   {
      pc_hDC := DllCall("GetDC", "UInt", pc_wID)
      WinGetPos, , , pc_w, pc_h, ahk_id %pc_wID%
      pc_hCDC := DllCall("CreateCompatibleDC", "UInt", pc_hDC)
      pc_hBmp := DllCall("CreateCompatibleBitmap", "UInt", pc_hDC, "Int", pc_w, "Int", pc_h)
      pc_hObj := DllCall("SelectObject", "UInt", pc_hCDC, "UInt", pc_hBmp)
      DllCall("PrintWindow", "UInt", pc_wID, "UInt", pc_hCDC, "UInt", 0)
      pc_fmtI := A_FormatInteger
      SetFormat, IntegerFast, Hex
      pc_c := DllCall("GetPixel", "UInt", pc_hCDC, "Int", pc_x, "Int", pc_y, "UInt")
      pc_c := pc_c >> 16 & 0xff | pc_c & 0xff00 | (pc_c & 0xff) << 16
      pc_c .= ""
      SetFormat, IntegerFast, %pc_fmtI%
      DllCall("DeleteObject", "UInt", pc_hBmp)
      DllCall("DeleteDC", "UInt", pc_hCDC)
      DllCall("ReleaseDC", "UInt", pc_wID, "UInt", pc_hDC)
      ;MsgBox, colour: %pc_c%
      Return pc_c
   }
}


Report this post
Top
  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 18 posts ]  Go to page Previous  1, 2

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bon and 11 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group