Results 1 to 11 of 11
  1. #1
    Star Lounger
    Join Date
    Jan 2001
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Weird Form Focus Problems With the Mouse (VB6 SP5 and Windows2K)

    Weird Form Focus Problems With the Mouse

    Here is a weird behavior;

    VB6 SP5 and Windows2K

    I have a form with the form MouseMove event set to Me.Setfocus; when the application runs, if I click on a blank space on the windows taskbar, the form still is the top window but its taskbar button is no longer pressed (form is no longer focused); now, if i move the mouse over the form, the form flickers rapidly about 20-30 times, settting itself to focus and unfocus alternatively before it stops and remains in a focused state; occasionally, this behavior will happen just when I start the application and not unfocus the application first.

    Anybody have an ideas what could be causing this? Is this a bug with VB6? How might I fix this? My current workaround is to do a loop in the MousMove event that will set the focus about 20 times so that the flickering is less noticeable (it ends quicker); Is there something I am overlooking when dealing with MouseMove and focusing a form?

    Thank you!

    --Llyal

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Weird Form Focus Problems With the Mouse (VB6 SP5 and Windows2K)

    Your setfocus event is happening over and over because that's the nature of MouseMove--it occurs every time the x and y coordinates change. It's not peculiar to VB forms, either. What you need to do is determine if the form is already the active object (that is, if it already has the focus), and only set the focus if it isn't.
    Charlotte

  3. #3
    Star Lounger
    Join Date
    Jan 2001
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Weird Form Focus Problems With the Mouse (VB6 SP5 and Windows2K)

    Charlotte,

    I am trying to set the form focus without clicking on the form. I think that if I set the form focus in the MouseMove event, it should not matter if I set it once or many times, the form should not arbitrarily "unfocus" . Try duplicating the problem i have described and you will see: Make a blank form in VB6 and set the form MouseMove event to Me.Setfocus; Run it; Now unfocus the window by clicking on another window or a blank space on the taskbar; Now move the mouse cursor over the form. Right after the mouse cursor enters the form, the form focus state rapidly flickers on and off for 5-30+ times before stopping. This is weird behavior. My workaround is to set the form focus 20+ times in the MouseMove event to "speed through" this flickering.

    To me, unless I am doing something wrong, this looks like a bug, either with the VB6 form MouseMove event or with the way Windows 2000 handles its windows.

    Or am I doing something worng?

    --Llyal

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Weird Form Focus Problems With the Mouse (VB6 SP5 and Windows2K)

    Well, all I can say is that I can't duplicate that behavior on NT. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15> If I set a form to show modeless and set the mousemove event of the form to setfocus back to it, that's what it does. I see a slight flicker if I move the mouse around because the event keeps firing when the x and y coordinates change, but I don't see it lose focus again. I don't generally use modeless forms unless they have a special purpose, but even when I forced one to show that way, I didn't see the behavior you described.
    Charlotte

  5. #5
    Star Lounger
    Join Date
    Jan 2001
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Weird Form Focus Problems With the Mouse (VB6 SP5 and Windows2K)

    Charlotte,

    I checked this problem out on an NT box- I found no problem there, so this might be a problem with windows 2000; I also checked this problem out on a freshly set up machine and the flickering still persists, again pointing out the OS as the problem;

    It looks like my workaround is the only way to go- not a nice solution, but it works ok.

    Thanks for the help!

    --Llyal

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Weird Form Focus Problems With the Mouse (VB6 SP5 and Windows2K)

    Do you have Active Desktop installed? I always deselect it when I install, so I can't guess at whether it might be part of the problem.
    Charlotte

  7. #7
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Weird Form Focus Problems With the Mouse (VB6 SP5 and Windows2K)

    I can't reproduce this- but would somewthing like this work?
    <pre>Option Explicit

    Public blnInitiated As Boolean

    Private Sub Form_Initialize()
    blnInitiated = False
    End Sub

    Private Sub Form_LostFocus()
    blnInitiated = False
    End Sub

    Private Sub Form_MouseMove(Button As Integer, _
    Shift As Integer, X As Single, Y As Single)
    If Not blnInitiated Then
    Me.SetFocus
    blnInitiated = True
    End If
    End Sub
    </pre>

    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  8. #8
    Star Lounger
    Join Date
    Jan 2001
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Weird Form Focus Problems With the Mouse (VB6 SP5 and Windows2K)

    Geoff,

    I tried your code; neither the form_LostFocus or form_GotFocus events fire eventhough the form flickers from a focused and unfocused state;

    If I set Me.Setfocus when the form is unfocused, shouldn't the form_GotFocus event fire?

    Geoff, are you replicating this problem on a windows 2K SP2 machine? I have tried it on three and get the same problem; this problem does not occur on NT or Win98, so if you do it on those platforms you won't see the problem; If you are using Win2K, and cannot verify any of my problems, then I will need to re-evaluate my situation;

    Thanks for the help!

    --Llyal

  9. #9
    Platinum Lounger
    Join Date
    Dec 2000
    Location
    Queanbeyan, New South Wales, Australia
    Posts
    3,730
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Weird Form Focus Problems With the Mouse (VB6 SP5 and Windows2K)

    Llyal,

    I'm actually on Win95!

    The idea behind my code was just to stop the Setfocus in the Mousemove from executing more than once, by setting a flag when it had executed. Although I could not reproduce your problem, I posted that as a possible pointer to getting around the problem. I used the form_Activate to explicitly set a value, but that's not strictly necessary.

    The form_getFocus only fires on receiving focus from another form within the project- not when the project itself receieves focus from another application.
    Subway Belconnen- home of the Signboard to make you smile. Get (almost) daily updates- follow SubwayBelconnen on Twitter.

  10. #10
    Star Lounger
    Join Date
    Jan 2001
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Weird Form Focus Problems With the Mouse (VB6 SP5 and Windows2K)

    Geoff,

    For my application, if i only set the focus once, when the focus-flickering-bonanza starts, the form becomes unfocused and remains unfocused (which is not desirable);

    Don't lose sleep over this- I have found a work around that gives me what I want without problems;

    --Llyal

  11. #11
    Star Lounger
    Join Date
    Jan 2001
    Posts
    69
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Weird Form Focus Problems With the Mouse (VB6 SP5 and Windows2K)

    No; my windows 2000 set up if like a "minimal" NT box;

    Don't lose sleep over this- I have found a workaround that is good enough;

    --Llyal

Posting Permissions

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