Change mouse pointer icon simplified: SetMouseIcon

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
USCode
Addict
Addict
Posts: 923
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle

Change mouse pointer icon simplified: SetMouseIcon

Post by USCode »

I know lots of folks have requested the ability to set the mouse pointer icon when hovering over specific gadgets but I'd settle for just a simple command to change the mouse pointer icon, not necessarily when it is over a specific gadget.

In particular it would be nice to change it to a "busy" icon (hourglass on windows) during long processing, then back to the default arrow when done.

You then can easily change the mouse pointer icon when over specific gadgets by trapping the mouse enter/leave events for the specific gadgets and change the icon to whatever you see fit then using the new mouse pointer icon command.

Maybe something like SetMouseIcon(#Image) and GetMouseIcon() please? :D
User avatar
Erlend
Enthusiast
Enthusiast
Posts: 114
Joined: Mon Apr 19, 2004 8:22 pm
Location: NORWAY

Post by Erlend »

Til we get a native solution, maby you could use this?

Code: Select all

Enumeration
  #CURSOR_CROSSHAIR
  #CURSOR_NORMAL
  #CURSOR_WAIT
  #CURSOR_IBEAM
  #CURSOR_HAND
  #CURSOR_HELP
  #CURSOR_MOVE
  #CURSOR_UPARROW
EndEnumeration

Procedure LoadCursor(Type) 
    CompilerIf #PB_Compiler_OS=#PB_OS_Linux
    Select Type
      Case #CURSOR_HELP:Cursor=#GDK_QUESTION_ARROW
      Case #CURSOR_HAND:Cursor=#GDK_HAND2
      Case #CURSOR_IBEAM:Cursor=#GDK_XTERM
      Case #CURSOR_NORMAL:Cursor=#GDK_ARROW
      Case #CURSOR_CROSSHAIR:Cursor=#GDK_CROSSHAIR
      Case #CURSOR_WAIT:Cursor=#GDK_WATCH
      Case #CURSOR_MOVE:Cursor=#GDK_FLEUR   
      Case #CURSOR_UPARROW:Cursor=#GDK_CENTER_PTR
    EndSelect
    ProcedureReturn gdk_cursor_new_(Cursor)
    CompilerElse
    Select Type
      Case #CURSOR_HELP:Cursor=#IDC_HELP
      Case #CURSOR_HAND:Cursor=#IDC_HAND
      Case #CURSOR_IBEAM:Cursor=#IDC_IBEAM
      Case #CURSOR_NORMAL:Cursor=#IDC_ARROW
      Case #CURSOR_CROSSHAIR:Cursor=#IDC_CROSS
      Case #CURSOR_WAIT:Cursor=#IDC_WAIT    
      Case #CURSOR_MOVE:Cursor=#IDC_SIZEALL
      Case #CURSOR_UPARROW:Cursor=#IDC_UPARROW      
    EndSelect
    ProcedureReturn LoadCursor_(0,Cursor)
    CompilerEndIf
EndProcedure

ProcedureDLL SetCursor(Handle,Cursor)
  CompilerIf #PB_Compiler_OS=#PB_OS_Linux
    *widget.gtkwidget=Handle
    gdk_window_set_cursor_(*widget\window, Cursor)
  CompilerElse
    SetWindowLong_(Handle,#GCL_HCURSOR,Cursor)
    ;Should set a property instead and handle the #WM_SETCURSOR event in window procedure
  CompilerEndIf
EndProcedure
USCode
Addict
Addict
Posts: 923
Joined: Wed Mar 24, 2004 11:04 pm
Location: Seattle

Almost there!

Post by USCode »

Thanks, looks pretty good!
You've already done some of the work for Fred there! 8)

Also, I really want to commend you for making the effort to make it partially cross-platform! To me, that is one of the KEY strengths/advantages of applications developed in PB!

We just need some OSX code in there and it'd be good to go! Though in my original post I proposed we have the ability to create an image object from any file we choose ... but using the OS's common pre-defined icons is a good idea as well and would probably work for the vast majority of uses.
User avatar
Erlend
Enthusiast
Enthusiast
Posts: 114
Joined: Mon Apr 19, 2004 8:22 pm
Location: NORWAY

Post by Erlend »

The code snippit I posted is actually only part of a larger project to create a canvas gadget witch is more or less finished allready, and OSX support for this function as well as the canvas gadget is on my todo list:-)
mike.harris
User
User
Posts: 10
Joined: Fri Jul 04, 2008 9:15 pm
Location: Caerphilly, Wales

Post by mike.harris »

Erland

I am just starting out with Windows programming with Purebasic and found your code. Unfortunately it never changes the mouse cursor.
From the look of it it should work on Windows.
Code run as below

LoadCursor(#CURSOR_WAIT)
.... 10 second job
LoadCursor(#CURSOR_NORMAL)

Thanks

Mike
User avatar
Kaeru Gaman
Addict
Addict
Posts: 4826
Joined: Sun Mar 19, 2006 1:57 pm
Location: Germany

Post by Kaeru Gaman »

I'm not sure, but maybe LoadCursor produces an event.
if so, the event must be processed before the change takes place,
that means you have to run past a (Wait)WindowEvent() to see the change.
oh... and have a nice day.
eesau
Enthusiast
Enthusiast
Posts: 589
Joined: Fri Apr 27, 2007 12:38 pm
Location: Finland

Post by eesau »

mike.harris wrote:Erland

I am just starting out with Windows programming with Purebasic and found your code. Unfortunately it never changes the mouse cursor.
From the look of it it should work on Windows.
Code run as below

LoadCursor(#CURSOR_WAIT)
.... 10 second job
LoadCursor(#CURSOR_NORMAL)
You should also use SetCursor()...
mike.harris
User
User
Posts: 10
Joined: Fri Jul 04, 2008 9:15 pm
Location: Caerphilly, Wales

Post by mike.harris »

eesau

Thanks for this tip, I will check it out.

Mike
Post Reply