How to change a mouse cursor to a wait cursor (hourglass) in a command line application

Posted on 2005-04-28
Last Modified: 2011-09-20
I have a command line application that is called when a button is pressed in a seperate application (which cannot be modified). Since the command line application takes some time to run I would like to change the mouse cursor to a wait cursor (hourglass). I've tried:

Cursor.Current = Cursors.WaitCursor
 ' some method calls
Cursor.Current = Cursors.Default

I think this does not work because I have no control or form. Is there any way around this?

My code is:

    Function ResetLogin() As Boolean
        ' Purpose: Reset the login info
        Dim sUserName As String
        Dim sPassword As String
            deleteUserNameAndPassword(sUserName, sPassword)
            promptUserForUserNameAndPassword(sUserName, sPassword)
            Cursor.Current = Cursors.WaitCursor
            validateUserNameAndPassword(sUserName, sPassword)
        Catch ex As Exception
            MsgBox("Error: Could not start or login.  " & ex.Message, MsgBoxStyle.Exclamation + MsgBoxStyle.MsgBoxSetForeground, AppName)
            Return False
            Cursor.Current = Cursors.Default
        End Try

        MsgBox("Reset login information successfully.  ", MsgBoxStyle.Information + MsgBoxStyle.MsgBoxSetForeground, AppName)
        Return True
    End Function

If you need any other information please let me know.
Thanks in advance for your help.
Question by:andrewting
    LVL 2

    Expert Comment

    this does not work
            System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
    so, try this:
            Me.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
    If none works, it is because cursor is inherited by forms of windows
    I think that you should change the cursor where you have a button. You'll be able to determine the time required to load the other application in various ways depending on what the other application is.
    Another idea is to declare a form and dispose it at the end:
    Dim tempForm as New Form
    Me.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor

    Author Comment

    Hi koouroshparsa,
    I've tried all of your suggestions.
    1. I am unable to do Me.Cursor.Current since my function is in a module and not in a class.
    2. Unfortunately I can not change the cursor to where I have the button because that form is in a completely seperate application and my application can not 'talk' to it but only gets called by it.
    3.  I've tried this as well and unfortunately this does not work.
    LVL 96

    Accepted Solution

    You need a visible form in order to change the cursor from your application.  You might be able to use the SetCursor Windows API, but I haven't tested that theory.


    Author Comment

    Thanks Bob.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now