Home | Forums | Contact | Search | Syndication  
 
 [login] [create account]   Thursday, November 21, 2024 
 
How To: Set Mouse Cursor in Legacy Views  
Description:  So, have you ever wanted to change the cursor to an HourGlass during a long running process in order to provide better feedback to the user? SalesLogix v6.1.1 has this feature for new ActiveX Forms and Controls, but there is not a feature like this for Legacy Views. This article outlines the code needed to do just this.

Category:  Architect How To Articles
Author:  Todd Hardin
Submitted:  1/13/2004
   
Stats: 
Article has been read 20317 times

Rating: - 5.0 out of 5 by 3 users
 

fiogf49gjkf0d
Introduction

So, have you ever wanted to change the cursor to an HourGlass during a long running process in order to provide better feedback to the user? SalesLogix v6.1.1 (now working in SP1a) has this feature for new ActiveX Forms and Controls, but there does not appear to be a feature like this for Legacy Views.

Solution

Example Bundle:
Attached is a small bundle (See related articles section below) demonstrating how to use Win32 API to set the cursor to hour glass. Also attached source code in text file for anyone wanting to have a quicker look. Hopefully someone has not already done this as it took me several hours to track this down and get it to work in SalesLogix.

How it was done - Win 32 API's:

GetCursor, LoadCursor, SetCursor

(Kudo's to Dan Appleman's VB Programmer Guide to the Win32 API.)

The catch is that Delphi likes to take back control of the cursor (and reset it) as soon as your script yields (ProcessWindowMessages, etc). So, you have to remember to judiciously set the cursor back to HourGlass throughout your code where needed - but this seems to work just fine.

The Code

option explicit

'Author:     Todd Hardin, Customer Systems Inc.
'Date:       January 11, 2004
'Release:    Released to public domain 
'Disclaimer: No warranty is expresed nor implied
'            Use at own risk


Declare Function GetCursor Lib "user32" Alias "GetCursor" () As Long
Declare Function LoadCursorBynum Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lpCursorName As Long) As Long
Declare Function SetCursor Lib "user32" Alias "SetCursor" (ByVal hCursor As Long) As Long

' Standard Cursor IDs
Public Const IDC_ARROW = 32512&
Public Const IDC_IBEAM = 32513&
Public Const IDC_WAIT = 32514&
Public Const IDC_CROSS = 32515&
Public Const IDC_UPARROW = 32516&
Public Const IDC_SIZE = 32640&
Public Const IDC_ICON = 32641&
Public Const IDC_SIZENWSE = 32642&
Public Const IDC_SIZENESW = 32643&
Public Const IDC_SIZEWE = 32644&
Public Const IDC_SIZENS = 32645&
Public Const IDC_SIZEALL = 32646&
Public Const IDC_NO = 32648&
Public Const IDC_APPSTARTING = 32650&

Public vbCRLF as String

sub main
    on error goto errMain
    dim lhCursorOrig as Long
    dim lhVoid as Long

    'init global helper variables
    vbCRLF = chr$(13) & chr$(10)

    SetPropertyOf "edtStatus", "Text", "Step 1..."
    ProcessWindowMessages

    'retrieve original cursor to use during clean-up at end of process
    lhCursorOrig = GetCursor

    'Set cursor to Wait (i.e. Hour Glass)
    SetCursorWait

    'process is never yielded, so this edit box property update will not be seen on the view.
    SetPropertyOf "edtStatus", "Text", "Step 2..."
    'ProcessWindowMessages  '<-- un-comment to update display
    'SetCursorWait		 '<-- note that you must un-comment as well to reset cursor to HourGlass

    'An  "busy" loop 
    'demonstrates that hour glass cursor will continue to display during uninterupted operations.
    dim j as Long
    dim i as Long
    for i = 1 to 32000
	 j = j + i

        'process is never yielded, so this edit box property update will not be seen on the view.
        SetPropertyOf "edtStatus", "Text", "Step 3 - " & CStr(j)
    next  'busy loop...

    'yield process
    ProcessWindowMessages

    'As soon as you yield your process, the cursor will/may (usually, but not always) 
    'change back to whatever cursor the SLX view has defined 
    '(i.e. usually the arrow pointer since we cannot manipulate cursors on legacy views).
    'Ending the script instance will have the same effect as this yields the script process.
    SetPropertyOf "edtStatus", "Text", "Step 4 - Finished"

    'RESET Cursor State
    'just like a good camper... put everything back the way you found it ... pack it in / pack it out
    lhVoid = SetCursor(lhCursorOrig)


'general SLX LogixErrors handler
'check before exiting routine
If LogixErrors Then
   msgbox "SLX API error occured: " & vbCRLF & _
	   "Error Code: " & LogixErrorCode & vbCRLF & _
	   "Error Description: " & vbCRLF & _
	   LogixErrorText
end if
Exit Sub  '<-- normail exit

errMain:
    msgbox "debug - an error occured." & err.description
end sub

sub SetCursorWait()
    dim lhCursorWait as Long
    dim lhCursorPrev as Long

    'Load an instance of the desired cursor to use
    'when loading special system cursors, use hInstance value of zero and retrieve cursor by number
    lhCursorWait = LoadCursorBynum(Clng(0), IDC_WAIT)
    lhCursorPrev = SetCursor(lhCursorWait)

    'most efficient / compact version
    'dim lhVoid   
    'lhVoid = SetCursor(LoadCursorBynum(0&, 32514&))

Exit Sub  '<-- normal exit
errSlxSetCursor:
    msgbox "debug - an error occured." & err.description
End sub


Well, better late than never guys!
Todd Hardin,
Customer Systems Inc.
 

About the Author

Todd Hardin
(SalesLogix Business Partner)
Sage - PSG

fiogf49gjkf0d
Long time SLX Consultant and SLX Fanatic - Go SLX!
Have been working with SLX from the very first release
Hobbies: SCUBA, SCUBA, SCUBA! - I am an SSI SSCUBA Instructor


View online profile for Todd Hardin
 

[ back to top] [ send to a friend]  

Rate This Article you must log-in to rate articles. [login here] 
 
Please log in to rate article.
 

Related Articles 
 - How To: Set Mouse Cursor in Legacy Views Sample Bundle - Submitted by: Todd Hardin

 

Comments & Discussion you must log-in to add comments. [login here] 
 
Author Article Comments and Discussion
Bob (RJ)Ledger

slxdeveloper.com Forum Top 10 Poster!

Cursor...
Posted: 1/23/2004 10:00:45 AM
fiogf49gjkf0d
Cool...
RJLedger
 
Ryan Farley

slxdeveloper.com Site Administrator
slxdeveloper.com Forum Top 10 Poster!

Re: How To: Set Mouse Cursor in Legacy Views
Posted: 1/24/2004 12:29:18 PM
fiogf49gjkf0d
Now if only you could "include scripts" for legacy basic plugins like you can with the new VBScript plugins. Would make things much easier to only have to include this each time you needed it.

-Ryan
 
Christian B. Mortensen
 

Re: How To: Set Mouse Cursor in Legacy Views
Posted: 3/16/2005 10:27:46 AM
fiogf49gjkf0d
How do you set the mouse cursor in 6.1?? Can't figure it out.
 
Robert Levine
 

Re: How To: Set Mouse Cursor in Legacy Views
Posted: 11/13/2006 1:07:51 PM
fiogf49gjkf0d
I too would like to know how to set the Mouse Cursor in SalesLogix 6.2.4. I think I need more than a region on a Form and a property setting. We all would like to set the cursor from within VBA code. Any suggestions?
 
Ryan Farley

slxdeveloper.com Site Administrator
slxdeveloper.com Forum Top 10 Poster!

Re: How To: Set Mouse Cursor in Legacy Views
Posted: 11/14/2006 5:28:14 PM
fiogf49gjkf0d
The only methods available (unless you roll your own COM exposed object to call from your scripts) are Form.Cursor and Control.Cursor. This will change the cursor over the object (ie: form) in question. A bit limited, but the only built-in methods to change the cursor.
 
 

       Visit the slxdeveloper.com Community Forums!
Not finding the information you need here? Try the forums! Get help from others in the community, share your expertise, get what you need from the slxdeveloper.com community. Go to the forums...
 



 slxdeveloper.com is brought to you courtesy of Ryan Farley & Customer FX Corporation.
 This site, and all contents herein, are Copyright © 2024 Customer FX Corporation. The information and opinions expressed here are not endorsed by Sage Software.

code of conduct | Subscribe to the slxdeveloper.com Latest Article RSS feed
   
 
page cache (param): 11/21/2024 4:42:23 PM