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

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Weird Form Focus Problems With the Mouse (VB6 SP5 and Windows2K)

    Author
    Topic
    #360782

    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

    Viewing 1 reply thread
    Author
    Replies
    • #544091

      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.

      • #544209

        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

        • #544306

          Well, all I can say is that I can’t duplicate that behavior on NT. shrug 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.

          • #544387

            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

            • #544483

              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.

            • #544908

              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

    • #544606

      I can’t reproduce this- but would somewthing like this work?

      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
      
      • #544886

        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

        • #544903

          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.

          • #544907

            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

    Viewing 1 reply thread
    Reply To: Weird Form Focus Problems With the Mouse (VB6 SP5 and Windows2K)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: