Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro and change mouse pointer 2

Status
Not open for further replies.

GilMerc

IS-IT--Management
Nov 12, 2003
115
0
0
CA
Hi,

I want to change a mouse pointer when the macro start a report. Somebody know how can manage a mouse pointer in this case?

thank's

Gilles.
 
Hi Gilles

If the script is running as a compiled VB app you can use the form.mousepointe syntax.
Otherwise I am not sure if there is a way in a cognos macro to do it.

Dreffed


Dreffed
 
You will beed to make an API call to SetCursor. The following macro will display a pointer/hourglass cursor when executing as an mcx.

Declare Function LoadCursor Lib "user32" _
Alias "LoadCursorA" _
(ByVal hInstance As Long, _
ByVal lCursorName As Long) As Long

Declare Function SetCursor Lib "user32" _
(ByVal hCursor As Long) As Long

Declare Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Long)

Const HOUR_GLASS_CURSOR = 32514

Sub Main()

Dim hCursor As Long
Dim hOriginalCursor As Long

hCursor = LoadCursor(0, HOUR_GLASS_CURSOR)
hOriginalCursor = SetCursor(hCursor)

' To test, remove the comment from the sleep line below
' Display cursor for 10 seconds

' Sleep 10000

' Run Report here

' Change the cursor back to the original
SetCursor hOriginalCursor

End Sub


/Roland
 
Roland,

The script that you inclued in your message works but if I include in my macro it doesn't. The cursor take an orginal apearance when the instruction that follow SetCursor will execute.

Do you know why it's not works? Do you know something that change a cursor appearence when it execute?

thank, Gilles.
 
Gilles,

I believe the WinAPI call will not be effective because the macro maintains no open window while it runs. Normally that API call would give an hourglass cursor when you mouse over the application that calls it. With no open window, the call is ineffective (my guess).

If you have access to the Cognos support site, look in the Supportlink archives for the term 'ShowStatus'. There is an excellent article on how to create an activeX control that relays status information on macro progress to the end user. That may be what you are really looking for.

Regards,

Dave Griffin


The Decision Support Group
Reporting Consulting with Cognos BI Tools
"Magic with Data"
[pc2]
Want good answers? Read FAQ401-2487 first!
 
It's now works!!!!!

Ho surprise, I start the macro from mcx and not from .mac(F5) and the cursor appearance change when I use the API and stay in this status while I don't change it to original appearance.
Thank's to Roland for the API.

Dave, I think that not works in developper environnement because a window controler is .mac file and it receives for windows an instruction to reset a cursor appearance to original. When the .mcx is executed, the controler is the dialog box.

Gilles.
 
Roland,

When I try to test this, it works fine from the .mcx based on your code above. When I insert a msgbox function before the cursor change to indicate the start of the test, the cursor does not change after the msgbox is closed. As I would want to use this after a dialog box call to get user input, any thoughts on why the behavior changes?

Thanks,

Dave Griffin


The Decision Support Group
Reporting Consulting with Cognos BI Tools
"Magic with Data"
[pc2]
Want good answers? Read FAQ401-2487 first!
 
Dave,

Do you have a dialog box? If you don't, effectively a cursor doesn't change because a cursor pointed on other windows program like desktop or on explorer. If you have a dialog box a cursor changed when it pass over the dialog box, I try it and it works.

Gilles.
 
Gilles,

That is fine for when the dialog box is up, but the macro suspends operation until the dialog box is filled in and the 'OK' button is pressed. It's the status of the cursor change (or lack thereof) AFTER that happens (while the macro runs with the parameters passed) that I would want to control. Have you gotten this part to work with the cursor change?

Dave Griffin


The Decision Support Group
Reporting Consulting with Cognos BI Tools
"Magic with Data"
[pc2]
Want good answers? Read FAQ401-2487 first!
 
Dave,

The operation are not suspends when a dialog box is up. All events can be control. If you want to compute some operations when a user take a selection in drop down list, you can. You can change a cursor status, take operations and recover an original cursor status, it's easy.

Show help on dialog box.

It's possible that I don't understand what you want to do.

Gilles.
 
Gilles,

Sorry about the misunderstanding. When the dialog box is up, only dialog events processed through the dialog function can process. The code in the body of the macro does not proceed until the dialog is closed. This is where the majority of the activity occurs, and while it is running end users often get confused over whether the macro is executing or not. This is where I would like to have the ease of a simple cursor change, not while the dialog box is up.

I have used the ShowStatus function I mentioned, but some of my clients do not allow ActiveX controls to be registered by a user without giving them Admin rights to their computer. This cursor change would give them some indication the macro is running without requiring that change.

Dave Griffin


The Decision Support Group
Reporting Consulting with Cognos BI Tools
"Magic with Data"
[pc2]
Want good answers? Read FAQ401-2487 first!
 
I think I'm a little confused with what you're looking for Dave.

Does this help ...

'Declarations

'Constants
'---------------------------
Const NORMAL_CURSOR = 32512
Const HOUR_GLASS_CURSOR = 32514

Sub SetMousePointer(lMousePointer As Long)

Dim hCursor As Long
Dim hOriginalCursor As Long

hCursor = LoadCursor(0, lMousePointer)
hOriginalCursor = SetCursor(hCursor)

End Sub

Sub Main

SetMousePointer HOUR_GLASS_CURSOR

'Do some processing here

SetMousePointer NORMAL_CURSOR

End Sub


Thanks,
Roland
 
Thanks Roland for your precision on your function.

Dave, if the process occurs before a dialog box is open, is it possible to put this process in a initialize status of dialog box(where operation% = 1). In this case, you can change cursor appearance and, if is possible, you can put a message that says initialisation occurs.

Gilles.
 
Gilles,

I'll give it a try, but I'm not optimistic. My testing thus far has not gone well.

Roland,

What I am looking for is an easy way to let the end-user know the macro is still running. Currently, if the macro is calling a long stored procedure, creating a long ascii file, or running Impromptu with a long report in non-visible mode, they tend to think it failed and start it again. When I try this with this cursor change it works fine as long as there is no interface (dialog or msgbox) but doesn't change the cursor if there is.

I'll keep plugging away at it. There is no logical reason it shouldn't work.

Regards,

Dave Griffin


The Decision Support Group
Reporting Consulting with Cognos BI Tools
"Magic with Data"
[pc2]
Want good answers? Read FAQ401-2487 first!
 
Hi Guys,

Ok, I think I know where you guys are headed. We needed to hold the cursor state in a static variable so that we could test and set the appropriate cursor in the function. :)

Declare Function LoadCursor Lib "user32" Alias "LoadCursorA" (ByVal hInstance As Long, ByVal lCursorName As Long) As Long
Declare Function SetCursor Lib "user32" (ByVal hCursor As Long) As Long
Declare Function GetCursor Lib "user32" () As Long
Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Declare Function FileDlgFunction(identifier$, action, suppvalue)

'-------------Cursor Change Constants-----------
Const NORMAL_CURSOR = 32512
Const HOUR_GLASS_CURSOR = 32514

Sub SetMousePointer(lMouseCursor As Long)

Dim hCursor As Long

hCursor = LoadCursor(0, lMouseCursor)
SetCursor hCursor

End Sub

Sub Main

Dim button as integer
Dim identifier$
Dim action as Integer
Dim suppvalue as Integer
Begin Dialog newdlg 183, 52, "Show Hide Hour Glass", .FileDlgFunction
OkButton 130, 6, 50, 14
CancelButton 130, 23, 50, 14
CheckBox 29, 11, 62, 15, "Show HourGlass Cursor", .CheckBox1
End Dialog

Dim dlg As newdlg
button = Dialog(dlg)

End Sub


Function FileDlgFunction(identifier$, action, suppvalue)

Static CurCursor As String

On Error resume next

If CurCursor = "Normal" Then
SetMousePointer HOUR_GLASS_CURSOR
Else
SetMousePointer NORMAL_CURSOR
End If


Select Case action

Case 1

Case 2 'user changed control or clicked a button
If DlgControlID(identifier$)=2 then
If CurCursor = "Normal" Then
CurCursor = "HourGlass"
Else
CurCursor = "Normal"
End If
End If
End Select

End Function

Note: This works with mac's as well as mcx's.

Regards,
Roland
 
Also ... I can convert the above sample code to an SBH file (if your interested) and include the whole Cursor logic in a subroutine so that you will have minimal changes to make to your existing programs (ie: just "Include" the SBH file and then reference the subroutine to set the cursor - from anywhere in your code).

Looking for more macro challenges!

Have a good one!
Roland
 
Roland,

Once I have the cursor API call working, I intended to move it into a standard library SBH file I already have. You're right. That's the way to go.

Dave Griffin


The Decision Support Group
Reporting Consulting with Cognos BI Tools
"Magic with Data"
[pc2]
Want good answers? Read FAQ401-2487 first!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top