Ooops
October 28, 2020, 06:18:54 AM

Author Topic: [bb] SetPointer by sswift [ 1+ years ago ]  (Read 1229 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bb] SetPointer by sswift [ 1+ years ago ]
« on: June 29, 2017, 12:28:42 AM »
Title : SetPointer
Author : sswift
Posted : 1+ years ago

Description : This function allows you to change the mouse pointer in Blitz.  

I based it off several code snippets others have posted.  

I added all the constants they had, plus one that I found through testing, and I grouped them by usage for easy access.  

I also modified the names of the constants slightly to make them easier to remember, and named my function something which fits more with the terminology Blitz uses for its functions.

So basically, I've tidied things up a bit.

UPDATE:
I have added the ability to load custom cursors with one function call, and use them exactly the same as you would any of the system cursors.

UPDATE:
Added function to prevent windows from resetting the mouse pointer to an arrow on occassion.  You should call this new function before changing your pointer, or else it will change back to an arrow at random.


Code :
Code: BlitzBasic
  1. ; -----------------------------------------------------------------------------------------------------------------------------------
  2. ;
  3. ; This code allows you to change the mouse pointer in Blitz.
  4. ; To use these functions, first place the following in the file "user32.decls" in your userlibs folder:
  5. ;
  6. ;       .lib "user32.dll"
  7. ;       LoadCursor%(Instance, CursorName):"LoadCursorA"
  8. ;       LoadCursorFromFile%(Filename$):"LoadCursorFromFileA"
  9. ;       SetCursor%(Cursor):"SetCursor"
  10. ;   SetClassLong%(hWnd%, nIndex%, dwNewLong%):"SetClassLongA"
  11. ;
  12. ; Then, in your program, call SetPointer() using one of the constants below, like so:
  13. ;
  14. ;       SetPointer(PTR_WAIT)
  15. ;
  16. ;
  17. ; Additional notes:
  18. ;
  19. ;       The LoadCursor function loads the cursor resource only if it has not been loaded.  Otherwise, it retrieves the handle
  20. ;       to the existing resource.  In other words, loading a cursor multiple times in the same app without freeing it should
  21. ;       not cause a memory leak.
  22. ;
  23. ;       See this page for information on these functions and on how to load a cursor from a file:
  24. ;       http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/cursors/cursorreference/cursorfunctions/loadcursor.asp
  25. ;
  26. ; -----------------------------------------------------------------------------------------------------------------------------------
  27.  
  28.  
  29. ; Normal
  30.         Const PTR_ARROW                 = $7F00         ; Normal cursor.
  31.         Const PTR_SIZENONE              = $7F81         ; No cursor
  32.        
  33. ; Busy
  34.         Const PTR_WAIT                  = $7F02         ; Hourglass.
  35.         Const PTR_SIZEHOURGLASS = $7F8A         ; Normal cursor, with small hourglass in the top right corner.
  36.         Const PTR_SIZECD                = $7F97         ; Normal cursor, with a CD loading icon in the top right corner.
  37.  
  38. ; Text
  39.         Const PTR_IBEAM                 = $7F01         ; Cursor used over text that can be selected or modified.
  40.         Const PTR_SIZEHAND              = $7F89         ; Hand cursor - Index finger pointing up.  Used for web links.
  41.  
  42.  
  43. ; Resizing / Movement
  44.         Const PTR_SIZENWSE              = $7F82         ; Black arrows, top left to bottom right.
  45.         Const PTR_SIZENESW              = $7F83         ; Black arrows, top right to bottom left.
  46.         Const PTR_SIZEWE                = $7F84         ; Black arrows, left to right
  47.         Const PTR_SIZENS                = $7F85         ; Black arrows, top to bottom
  48.         Const PTR_SIZEMOVE              = $7F86         ; Black arrows, in a cross formation.
  49.         Const PTR_SIZEDENIED    = $7F88         ; Circle with diagonal line
  50.  
  51. ; Help
  52.         Const PTR_SIZEHELP              = $7F8B         ; Normal cursor, with a large black question mark to the right of it.
  53.  
  54. ; Mouse wheel
  55.         Const PTR_SIZEMOVENS    = $7F8C         ; Large black arrows with a dot between them, pointing top to bottom.
  56.         Const PTR_SIZEMOVEWE    = $7F8D         ; Large black arrows with a dot between them, pointing left to right.
  57.         Const PTR_SIZEMOVENSEW  = $7F8E         ; Large black arrows with a dot between them, pointing in all four directions.
  58.         Const PTR_SIZEMOVEN             = $7F8F         ; Large black arrow with a dot below it pointing up.
  59.         Const PTR_SIZEMOVES             = $7F90         ; Large black arrow with a dot below it pointing down.
  60.         Const PTR_SIZEMOVEW             = $7F91         ; Large black arrow with a dot below it pointing left.
  61.         Const PTR_SIZEMOVEE             = $7F92         ; Large black arrow with a dot below it pointing right.
  62.         Const PTR_SIZEMOVENW    = $7F93         ; Large black arrow with a dot below it pointing towards the top left.
  63.         Const PTR_SIZEMOVENE    = $7F94         ; Large black arrow with a dot below it pointing towards the top right.
  64.         Const PTR_SIZEMOVESW    = $7F95         ; Large black arrow with a dot below it pointing towards the bottom left.
  65.         Const PTR_SIZEMOVESE    = $7F96         ; Large black arrow with a dot below it pointing towards the bottom right.
  66.  
  67. ; Graphics
  68.         Const PTR_CROSS                 = $7F03         ; Plus sign for picking accurately.
  69.         Const PTR_PEN                   = $7F77         ; A diagonal pen tablet pen with the tip at the top left. (Couldn't find this constant's real name.)
  70.  
  71. ; Misc
  72.         Const PTR_UPARROW               = $7F04         ; Thin black arrow with white outline, pointing up.  Not sure what this is used for.
  73.  
  74. ; Custom pointers
  75.  
  76.         Const MAX_CUSTOM_POINTERS = 10          ; Allocate storage for the custom pointers.
  77.         Dim PTR_CUSTOM(MAX_CUSTOM_POINTERS)            
  78.                
  79.         Const PTR_ZOOMIN                = $0000         ; Store the array index of each custom pointer here for easy access.
  80.         Const PTR_ZOOMOUT               = $0001
  81.  
  82. ; -----------------------------------------------------------------------------------------------------------------------------------
  83. ; This function allows you to load custom pointers from files.
  84. ; Call it once at the start of your program.
  85. ;
  86. ; Note:
  87. ; Cursors loaded with this function DO NOT NEED TO BE, and SHOULD NOT BE, "freed".
  88. ;
  89. ; According to MSDN, both LoadCursor and LoadCursorFromFile load "shared" cursors.
  90. ; MSDN indicates that shared cursors are deleted automatically when the application they were loaded from is shut down.
  91. ; It also specfically says that you should not use the DestroyCursor function to delete shared cursors loaded by these functions.
  92. ;
  93. ; See this page for more info:
  94. ; http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/resources/cursors/cursorreference/cursorfunctions/destroycursor.asp
  95. ; -----------------------------------------------------------------------------------------------------------------------------------
  96. Function LoadPointers()
  97.  
  98.         ; One entry for each custom cursor.
  99.         PTR_CUSTOM(PTR_ZOOMIN)  = LoadCursorFromFile("zoomin.cur")
  100.         PTR_CUSTOM(PTR_ZOOMOUT) = LoadCursorFromFile("zoomout.cur")
  101.  
  102. End Function
  103.  
  104.  
  105. ; -----------------------------------------------------------------------------------------------------------------------------------
  106. ; This functoon changes the mouse pointer.
  107. ; It can accept constants for system pointers, or custom pointers you have loaded in the loadpointers() function.
  108. ; -----------------------------------------------------------------------------------------------------------------------------------
  109. Function SetPointer(Pointer)
  110.  
  111.         Local Cursor
  112.        
  113.         ; If pointer is greater than the max number of custom pointers, then it must be referencing a system pointer.
  114.         If (Pointer > MAX_CUSTOM_POINTERS)
  115.                 Cursor = LoadCursor(0, Pointer)
  116.         Else
  117.                 Cursor = PTR_CUSTOM(Pointer)
  118.         EndIf
  119.        
  120.         SetCursor(Cursor)      
  121.        
  122. End Function
  123.  
  124.  
  125. ; -----------------------------------------------------------------------------------------------------------------------------------
  126. ; You should call this function at the start of your program if you want to change the pointer in your program.
  127. ; If you don't, then windows will occasionally reset the pointer to the arrow cursor after you have changed it.
  128. ;
  129. ; Window is the pointer to your main window.
  130. ;
  131. ; You may need to call this function once for all windows you create in your application.
  132. ; -----------------------------------------------------------------------------------------------------------------------------------
  133. Function DisablePointerReset(Window)
  134.  
  135.         Local hWnd     
  136.         Local GCL_HCURSOR = -12
  137.  
  138.         hWnd = QueryObject(Window, 1)
  139.         SetClassLong(hWnd, GCL_HCURSOR, 0)
  140.        
  141. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal