SetCursor_() - Pippet in paint??

Just starting out? Need help? Post your questions and find answers here.
Hydrate
Enthusiast
Enthusiast
Posts: 436
Joined: Mon May 16, 2005 9:37 pm
Contact:

SetCursor_() - Pippet in paint??

Post 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???
.::Image::.
Tranquil
Addict
Addict
Posts: 952
Joined: Mon Apr 28, 2003 2:22 pm
Location: Europe

Post 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.
Tranquil
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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 
Last edited by netmaestro on Mon Nov 27, 2006 11:50 pm, edited 4 times in total.
BERESHEIT
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Post by rsts »

Nicely done.

thanks
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

It has an ugly green background and it flickers, is that on purpose?
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
BERESHEIT
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post by netmaestro »

http://www.networkmaestro.com/pipette.bmp

Could you try pulling the bmp in with LoadImage and see if it helps?
BERESHEIT
Hydrate
Enthusiast
Enthusiast
Posts: 436
Joined: Mon May 16, 2005 9:37 pm
Contact:

Post by Hydrate »

It works just fine, thank you very much.
.::Image::.
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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.
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post 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 :)
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post 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...
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
BERESHEIT
User avatar
netmaestro
PureBasic Bullfrog
PureBasic Bullfrog
Posts: 8451
Joined: Wed Jul 06, 2005 5:42 am
Location: Fort Nelson, BC, Canada

Post 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.
BERESHEIT
Sparkie
PureBatMan Forever
PureBatMan Forever
Posts: 2307
Joined: Tue Feb 10, 2004 3:07 am
Location: Ohio, USA

Post by Sparkie »

Same (frog)green result Netmaestro :cry:
What goes around comes around.

PB 5.21 LTS (x86) - Windows 8.1
Post Reply