Hi guys,

This is driving me absolutly mad !!!

I'm trying to make a custom cursor. I simply want the usual arrow with another icon mixed with it. The arrow icon is 32x32 and the one I wish to add is 16x16. It's so when the mouse is over a node in my prog, the cursor uses the
extra 16x16 icon to display a number 0-9. The numbers are already icons at this point, so I just need to combine the two !!

I could just make 10 different cursors and that would be solved, but I would like to use other icons too. Maybe a cross
icon next to the arrow to show a node is not connected, etc.

I've tried GetIconInfo and drawing the mask into a DC and Blting it onto the larger icon at an offset but I lose transparency. I've tried copying the color and mask array from the 16x16 into the 32x32 icon but it gets mashed. I've tried using imagelists and using an overlay for the 16x16 and end up with the correct result but on a white background. Aaaahhhrrrrggggg !!! Heh !!

I'm sure this is only gonna be about 50 lines of code but I'm going around in circles and I'm gonna start kicking the dog for no reason if I dont solve it soon :)

Anyone know of any code snippits around that might help me. I've googled a few examples but they only show how to mix icons of the same size, which doesnt help much !

Thanks alot,

Posted on 2004-02-24 08:05:45 by Emerson
Cursors are a bit more difficult because the mask and data are stored in a single image but this is my OverlayIcon routine that will overlay one color icon on top of the other. The first icon is the bottom one, posx/y is the relative offset of the overlay from 0,0

OverlayIcon FRAME hIcon1,hIcon2,posx,posy

LOCAL hBitmap :D
LOCAL hMask :D

invoke GetDC,NULL
mov [hWinDC],eax
invoke CreateCompatibleDC,[hWinDC]
mov [hmemDC],eax

invoke CreateCompatibleBitmap,[hWinDC],32,32
mov [hBitmap],eax
invoke ReleaseDC,NULL,[hWinDC]

invoke SelectObject,[hmemDC],[hBitmap]
push eax
invoke DrawIconEx,[hmemDC],0,0,[hIcon1],0,0,0,0,DI_NORMAL
invoke DrawIconEx,[hmemDC],[posx],[posy],[hIcon2],\
pop eax
invoke SelectObject,[hmemDC],eax
invoke DeleteDC,[hmemDC]

invoke CreateMask,[hBitmap],0
mov [hMask],eax

mov D[iinfo.fIcon],TRUE
mov D[iinfo.xHotspot],0
mov D[iinfo.yHotspot],0
mov eax,[hMask]
mov D[iinfo.hbmMask],eax
mov eax,[hBitmap]
mov D[iinfo.hbmColor],eax
invoke CreateIconIndirect,OFFSET iinfo
push eax
invoke DeleteObject,[hMask]
invoke DeleteObject,[hBitmap]
pop eax


CreateMask FRAME hIcoBmp,crTransparent
LOCAL hdc1 :D
LOCAL hdc2 :D
LOCAL OldObj1 :D
LOCAL OldObj2 :D
LOCAL hMaskBmp :D
LOCAL crBkgnd :D
LOCAL crText :D

invoke GetDC,NULL
mov [hDC],eax
invoke CreateCompatibleDC,[hDC]
mov [hdc1],eax
invoke CreateCompatibleDC,[hDC]
mov [hdc2],eax
invoke ReleaseDC,NULL,[hDC]

invoke GetObject,[hIcoBmp],SIZEOF BITMAP,OFFSET bmp

invoke CreateBitmap,[bmp.bmWidth],[bmp.bmHeight],1,1,NULL
mov [hMaskBmp],eax

invoke SelectObject,[hdc1],[hMaskBmp]
mov [OldObj1],eax
invoke SelectObject,[hdc2],[hIcoBmp]
mov [OldObj2],eax
invoke SetBkColor,[hdc2],[crTransparent]
mov [crBkgnd],eax
invoke BitBlt,[hdc1],0,0,[bmp.bmWidth],[bmp.bmHeight],[hdc2],0,0,SRCCOPY
invoke SetTextColor,[hdc2],0FFFFFFh
mov [crText],eax
invoke SetBkColor,[hdc2],0
invoke BitBlt,[hdc2],0,0,[bmp.bmWidth],[bmp.bmHeight],[hdc1],0,0,SRCAND
invoke SetBkColor,[hdc2],[crBkgnd]
invoke SetTextColor,[hdc2],[crText]

invoke SelectObject,[hdc1],[OldObj1]
invoke SelectObject,[hdc2],[OldObj2]
invoke DeleteDC,[hdc1]
invoke DeleteDC,[hdc2]

mov eax,[hMaskBmp]
Posted on 2004-02-24 09:09:33 by donkey
Hey thanks Donkey, thats a good start !!

I understand a bit more about the mask now. I tested this code with LoadCursor and IDC_ARROW as one of the icons and IDC_CROSS for the other. It maintains transparency although the result is an inverted cursor. Close but not quite, I'll keep playing :)

I wasnt using SetTextColor or SetBkColor at all in my efforts, I didnt think they would have any effect. You learn something new everyday :alright:


Posted on 2004-02-24 10:51:19 by Emerson
No probs Emerson,

I never really thought there was much interest in this kind of thing so I never posted the demo. I have uploaded it to my site. It also shows how to use a different transparency color if necessary (I generally use 0FF00FFh as my transparency I am never likely to use pink in an icon :) ). You can find it in the GoAsm projects.
Posted on 2004-02-24 10:56:06 by donkey