Page 1 of 3

SetCursor_() - Pippet in paint??

Posted: Mon Nov 27, 2006 12:28 pm
by Hydrate
How could i set the cursor to be the same as the one used for the pippet in paint when used over an imagegadget???

Posted: Mon Nov 27, 2006 12:50 pm
by Tranquil
It seems not to be a part of the system so that you can not use LoadCursor with an IDC_xxxx constant. I think you have to load it from disc.

It should be work by passing the handle of LoadImage() to setcursor_()

Unfortunately I dont have this icon on my harddisc. But you can surely extract it from Paint with some Icontools.

Posted: Mon Nov 27, 2006 1:15 pm
by srod
The following 'icon extractor' only locates 6 icons embedded within mspaint.exe.

Code: Select all

Procedure IconExtract(File.s,Icon.l) 
  ProcedureReturn ExtractIcon_(0,File,Icon) 
EndProcedure 

;/ Test 
#file="c:\windows\system32\mspaint.exe" 

Count=IconExtract(#file,-1) 
OpenWindow(0,0,0,130,70,Str(Count)+" Icons",#PB_Window_SystemMenu|#PB_Window_ScreenCentered) 
CreateGadgetList(WindowID(0)) 
ButtonImageGadget(0,10,10,48,48,IconExtract(#file,pointer)) 
TextGadget(1,80,30,40,20,"n° 1") 

Repeat 
  event=WaitWindowEvent() 
  
  If event= #PB_Event_Gadget And EventGadget()=0 And EventType()=#PB_EventType_LeftClick 
    pointer+1 
    If pointer=Count : pointer=0 : EndIf 
    SetGadgetState(0,IconExtract(#file,pointer)) 
    SetGadgetText(1,"n° "+Str(pointer+1)) 
  EndIf 
Until event=#PB_Event_CloseWindow
The icon you're after is probably in an associated dll somewhere. Shouldn't be too difficult to find.

Posted: Mon Nov 27, 2006 8:01 pm
by netmaestro

Code: Select all

;=================================================== 
; Program:          Pipette Cursor Demo 
; Author:           Lloyd Gallant (netmaestro) 
; Date:             November 27, 2006 
; As taught by:     Sparkie 
;=================================================== 
; 
ProcedureDLL PipetteCursor() 
  *unpacked = AllocateMemory(3128)
  UnpackMemory(?PicPak, *unpacked)
  imgcolor = CatchImage(#PB_Any, *unpacked, 3128)
  bmpcolor = ImageID(imgcolor)
  
  DataSection
    PicPak:
    Data.b $4A,$43,$38,$0C,$00,$00,$2A,$D9,$47,$2B,$B3,$A9,$D0,$20,$69,$14,$61,$88,$12,$CA
    Data.b $08,$B0,$48,$40,$27,$90,$04,$8E,$01,$C6,$5B,$28,$31,$10,$AB,$03,$0C,$02,$12,$09
    Data.b $46,$FF,$BF,$AD,$8F,$22,$59,$84,$F0,$43,$E6,$3B,$8A,$18,$1B,$B2,$0F,$F5,$11,$A8
    Data.b $22,$E4,$21,$C3,$5E,$47,$83,$EE,$43,$FF,$C0,$E6,$BB,$31,$B1,$35,$06,$01,$29,$94
    Data.b $CC,$A6,$1B,$63,$E6,$77,$77,$F2,$14,$1B,$33,$02,$70,$ED,$FB,$33,$36,$1B,$00,$5F
    Data.b $53,$28,$98,$CC,$48,$11,$5F,$14,$21,$00,$1B,$03,$6A,$6D,$8D,$41,$00,$A2,$F9,$3C
    Data.b $00,$98,$6D,$5F,$63,$06,$11,$4C,$02,$40,$8C,$0D,$EA,$49,$4F,$8B,$C2,$EA,$C1,$BD
    Data.b $46,$00,$23,$00,$CE,$81,$DC,$E6,$AE,$2E,$55,$E8,$30,$01,$53,$21,$9B,$D0,$86,$82
    Data.b $6E,$42,$D5,$98,$8D,$26,$8D,$E1,$AD,$F9,$1B,$69,$56,$17,$75,$23,$14,$33,$36,$02
    Data.b $10,$6E,$04,$50,$D5,$62,$5D,$AD,$D5,$1B,$90,$C9,$98,$79,$22,$D0,$4F,$02,$46,$30
    Data.b $F9,$8E,$E1,$BE,$9A,$22,$00,$00,$20,$12
    PicPakend:
  EndDataSection
  
  imgmask = CreateImage(#PB_Any, 32, 32, #PB_Image_DisplayFormat) 
  bmpmask = ImageID(imgmask) 
  
  StartDrawing(ImageOutput(imgmask)) 
   DrawImage(ImageID(imgcolor),0,0)  
   transcol=Point(0,0)        
    For i=0 To 31              
      For j=0 To 31 
        If Point(i,j)=transcol 
          Plot(i,j,#White) 
        Else 
          Plot(i,j,#Black) 
        EndIf 
      Next 
    Next 
  StopDrawing() 
  
  icoInf.ICONINFO 
  icoInf\fIcon = #False 
  icoInf\xHotspot = 8 
  icoInf\yHotspot = 23 
  icoInf\hbmMask = bmpmask 
  icoInf\hbmColor = bmpcolor 
  
  CustomCursor = CreateIconIndirect_(icoInf) 
  ProcedureReturn CustomCursor 
EndProcedure 

;======================================================================= 
; Test program - you can save everything before this as pipette.pbi 
;                and include it in programs to get the pipette cursor 
;======================================================================= 

customcursor = PipetteCursor() 

CreateImage(0, 100,100) 
StartDrawing(ImageOutput(0)) 
  Box(0,0,100,100,#White) 
StopDrawing() 
OpenWindow(0,0,0,400,300,"Pipette Demo",#PB_Window_SystemMenu|#PB_Window_ScreenCentered) 
CreateGadgetList(WindowID(0)) 
ImageGadget(0,120,80,0,0,ImageID(0),#PB_Image_Border) 
SetClassLong_(GadgetID(0), #GCL_HCURSOR, customcursor) 
Repeat 
  ev=WaitWindowEvent() 

Until ev=#PB_Event_CloseWindow 
DestroyIcon_(customCursor) 
End 

Posted: Mon Nov 27, 2006 8:54 pm
by rsts
Nicely done.

thanks

Posted: Mon Nov 27, 2006 9:00 pm
by Trond
It has an ugly green background and it flickers, is that on purpose?

Posted: Mon Nov 27, 2006 9:04 pm
by netmaestro
It has an ugly green background and it flickers
No, I've used this exact method many times over several months now and I've never seen a problem with it. I can't imagine what might cause that, but all the sourcecode is right there, maybe you can see something? Any suggestions/fixes are welcome.

Posted: Mon Nov 27, 2006 9:08 pm
by netmaestro
http://www.networkmaestro.com/pipette.bmp

Could you try pulling the bmp in with LoadImage and see if it helps?

Posted: Mon Nov 27, 2006 9:22 pm
by Hydrate
It works just fine, thank you very much.

Posted: Mon Nov 27, 2006 10:01 pm
by Trond
netmaestro wrote:http://www.networkmaestro.com/pipette.bmp

Could you try pulling the bmp in with LoadImage and see if it helps?
Still the same problem. Almost newly installed Windows XP Pro and everything. It looks almost like the background of the cursor is XORed with whatever is behind it.

Posted: Mon Nov 27, 2006 10:02 pm
by Sparkie
I'm with Trond on this one. There is a semi-transparent green 32 x 32 background. I'd be willing to bet that this will work just fine on my PC at home. :?

Your code and the .bmp both seem to be just fine Netmaestro :)

Posted: Mon Nov 27, 2006 10:05 pm
by Trond
Replace SetCursor_() with this and the flicker is gone:

Code: Select all

SetClassLong_(GadgetID(0), #GCL_HCURSOR, customcursor)
Now for the green background...

Posted: Mon Nov 27, 2006 10:14 pm
by netmaestro
Good one Trond, possibly specifying an imagedepth of 24 on the CatchImage might help, as I've run into odd problems before just leaving the depth parameter off.

Posted: Mon Nov 27, 2006 10:18 pm
by netmaestro
Ok, I've updated the posted source to use the SetClassLong and to pull the image in with the #PB_Image_DisplayFormat flag, so possibly this might help.

Posted: Mon Nov 27, 2006 10:21 pm
by Sparkie
Same (frog)green result Netmaestro :cry: