Results 1 to 11 of 11

Thread: For all of you GURUS out there ;-)

  1. #1

    Thread Starter
    Fanatic Member wildcat_2000's Avatar
    Join Date
    Nov 2000
    Location
    Italy
    Posts
    727

    mousepointer property with DoEvents... for GURUS ;-)

    Hi all,

    this one is really for all the GURU specialists that are out there ;-) hope you can take me out of this.

    Let's say that I have a project with:

    - a MDI form (MDIform1);
    - 2 child form (form1 and form2).

    In fact, I actually have more than 2, and not all of them are visible at the same time. But let's keep it simple (did I say simple?!?).

    On Form1 and Form2 I have labels which work as buttons (for graphical reasons I prefer using those instead of controls).

    These buttons all have the mousepointer property set to 99 (custom icon), which is a small hand (like the one used for hyperlinks). So that when the mouse is over, the mousepointer changes, and the user understands it's a button (duh!).

    Now, here the hard part begins. When you click on label1 of form1, I fire up a quite heavy routine. I therefore set my
    form1.label1.mousepointer = 11 (hourglass), so that the mouse just stays at hourglass and the user just cannot start anything or click anything in the program until the heavy routine that he has started is done.

    However I was not happy enough, since my routine can be quite long and I wanted my users to be able to stop it at anytime.

    Therefore, I've put up a function that allows them to stop the routine by pressing the ESCAPE key (thanks Chris for this one!). In order to allow this stop, I am using the DoEvents property that allows to check for the key press.

    The problem is: because of this DoEvents function, the mousepointer value is automatically set to 0 (default!), and therefore the user can click on other forms (which cause inevitable overflows, stacking,...).

    Question: how can I solve this problem?

    Things that I've tried:

    1. setting MDIform.enabled = false
    --> doesn't work. It's true, you can't press labels in the forms, but the mousepointer is 0 (arrow).

    2. setting MDIform.mousepointer = 11
    --> doesnt'work, same effect of form1.label1.mousepointer = 11, after the DoEvents the mouse is 0 again.

    3. setting all the labels in all the forms to mousepointer = 11
    --> could work, but then as I said not all the forms are loaded at the same time. This would mean setting up a verification to see which forms are active... seems long and not effective.

    4. setting mousepointer = 11 after all the DoEvents
    --> doesn't work, memory is overflooded, Stack problem.

    5. ...any ideas?


    All of you great GURUS, hope you can solve this one with me! Thanks for reading until here, you definitely would like to help if you kept on reading until these lines, so I already appreciate you efforts [^_^]

    Best regards to you all,

    W.

  2. #2
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362
    Why do you get stack probs by setting the cursor explicitly after the each doevents? Seems odd.


    td.
    "One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig


    [email protected]

    "but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.

  3. #3

    Thread Starter
    Fanatic Member wildcat_2000's Avatar
    Join Date
    Nov 2000
    Location
    Italy
    Posts
    727
    mmmm, you're right. I might have bad recalling for this error.

    The problem, though, remains: since the DoEvents happen all the time, it would mean setting not only MDIform.mousepointer = 11, but also all the labels, and this after every DoEvents, and moreover you would have first to do a routine to find which forms are active and visible...

    I am sure this would considerably slow down the whole process. Isn't there another way?

    Thanks for our reply ;-)

    W.

  4. #4
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362
    So far. You have an MDI parent with many children. At a given point, on of these children will do something (process A). You need to be able to interupt (Cancel) process A with a cancel button on the Child form that kicked it off.

    Question: are the other forms active while process a is doing it's thing.

    Question: why do you think a search and destroy on all forms, changing lbls pointer property would take a long time. It'll take a fraction of a second.
    e.g. global routine (psuedo code)
    Code:
    Public Sub ChangeLblPointer(frm as Form,Pointer)
    Dim ctl as control
      For Each ctl In frm.control
        If TypeName(ctl) = "Label" Then ctl.MousePointer=pointer
      Next
      Set ctl = Nothing
    End Sub

    td.



    "One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig


    [email protected]

    "but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.

  5. #5

    Thread Starter
    Fanatic Member wildcat_2000's Avatar
    Join Date
    Nov 2000
    Location
    Italy
    Posts
    727

    ok, but...

    No there are no other ongoing processes except for the one fired up by the child that started it up all, so Ok I'll try this. I'll put the sub you've suggested in a module, and call it after every DoEvents.

    Thanks for your suggestions.

  6. #6

    Thread Starter
    Fanatic Member wildcat_2000's Avatar
    Join Date
    Nov 2000
    Location
    Italy
    Posts
    727
    Any other suggestions?

  7. #7
    Hyperactive Member Paul Warren's Avatar
    Join Date
    Jun 2000
    Location
    UK
    Posts
    282
    hmmm, interesting. I've just run this code on a child form and it works fine ? Are you sure it's related to the DoEvents ?

    Create a blank project with a MDI and child then stick this code into the child. Show the child when the MDI is loaded and let me know what happens.

    Code:
    Private bEnd As Boolean
    
    Private Sub Command1_Click()
    
    Screen.MousePointer = vbHourglass
    
    Do
    
        DoEvents
    
    Loop Until bEnd
    
    Screen.MousePointer = vbDefault
    
    End Sub
    
    Private Sub Form_KeyPress(KeyAscii As Integer)
    
    Select Case KeyAscii
    
        Case vbKeyEscape
            bEnd = True
            
    End Select
    
    End Sub
    That's Mr Mullet to you, you mulletless wonder.

  8. #8

    Thread Starter
    Fanatic Member wildcat_2000's Avatar
    Join Date
    Nov 2000
    Location
    Italy
    Posts
    727
    Paul,

    in your exemple is that you're still using a command1_click.
    My problem starts using a label1_click, where the label1.mousepointer = 99 when the form is loaded.

    However there's something new in your code: you're using Screen as the object, while I've always (was I blocked in my thinking ? used a form object.

    Maybe I would just have then to set, as you kindly suggest,

    Code:
    Screen.MousePointer = 11
    and instead of my Form1.Label1.MousePointer = 11

    ...what do you think?

  9. #9
    Hyperactive Member tumblingdown's Avatar
    Join Date
    Mar 2000
    Posts
    362
    yer, use the screen.

    the code i gave you was psuedo code to give you an idea.


    td.
    "One logical slip and an entire scientific edifice comes tumbling down." - Robert M. Pirsig


    [email protected]

    "but if Einstein is right and God is in the details, reality requires that we sometimes get religion." - Scott Meyers.

  10. #10
    Hyperactive Member Paul Warren's Avatar
    Join Date
    Jun 2000
    Location
    UK
    Posts
    282
    Wildcat_2000, yep that should do it. It's also worth using the VB constants because if Microsoft ever change the values for the hourglass, etc your code will automatically pick them up and save you changing and recompiling your code. YOu may already be doing this of course and just putting the numbers in for clarity. In which case ignore the last bit.
    That's Mr Mullet to you, you mulletless wonder.

  11. #11

    Thread Starter
    Fanatic Member wildcat_2000's Avatar
    Join Date
    Nov 2000
    Location
    Italy
    Posts
    727
    Thank you very much both for your precious suggestions. If this doesn't work, you'll soon seem me posting here again ;-)

    Best regards to you all,

    W.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width