Posts: 2
Threads: 1
Joined: Apr 2008
Is there any way to get the pixel color of part of the cursor? I tried but it just picks up the color of the window that is underneath it. Thanks for the help.
Posts: 12,071
Threads: 140
Joined: Dec 2002
04-28-2008, 10:35 AM
(This post was last modified: 03-19-2021, 04:56 PM by Gintaras.)
Function
GetColorInCursor
;/
function# x y [flags] ;;flags: 1 x y are relative to the hot spot
;Returns a color in the current cursor (mouse pointer).
;Returns -1 on failure.
;x, y - pixel coordinates relative to the top-left corner of the cursor. If flag 1 used - relative to the hot spot (which is at the mouse position) of the cursor.
;EXAMPLE
;rep
,;1
,;out "0x%X" GetColorInCursor(0 0 1) ;;color at the hot spot (mouse position)
__MemBmp mb; POINT p
if(!GetCursorBitmap(mb &p)) ret CLR_INVALID
if(flags&1) x+p.x; y+p.y
ret GetPixel(mb.dc x y)
Function
GetCursorBitmap
;/
function# __MemBmp&mb [POINT*hotspot]
;Gets memory bitmap of the current cursor (mouse pointer).
;Transparent parts will be white.
;Also can optionally get hotspot position within the cursor.
;Returns cursor handle on success, 0 on failure.
CURSORINFO ci.cbSize=sizeof(CURSORINFO)
if(!GetCursorInfo(&ci)) ret
if(hotspot)
,ICONINFO ii
,if(!GetIconInfo(ci.hCursor &ii)) ret
,DeleteObject ii.hbmMask
,DeleteObject ii.hbmColor
,hotspot.x=ii.xHotspot; hotspot.y=ii.yHotspot
,
mb.Create(32 32)
RECT r.right=32; r.bottom=32; FillRect mb.dc &r GetStockObject(WHITE_BRUSH)
if(!DrawIconEx(mb.dc 0 0 ci.hCursor 32 32 0 0 DI_NORMAL)) ret
ret ci.hCursor
Posts: 2
Threads: 1
Joined: Apr 2008
Thank you Gintaras! Just what I wanted.