dcsimg
Results 1 to 9 of 9

Thread: Form Freeze/Halt when mouse click and hold

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2014
    Posts
    824

    Form Freeze/Halt when mouse click and hold

    When you click on the caption/title of the form, right/left mouse click, it interrupt the processes in the form.
    so, if I have a text scrolling inside the form, it will stop if I click on the caption, if I right click it will stop until I release the button.
    that is also one reason I create my own controlbox (caption, min/max close buttons) so I can avoid that.
    anyone knows a way to use the form controlbox without the freeze when clicking on the caption?

  2. #2
    Addicted Member
    Join Date
    Nov 2013
    Posts
    214

    Re: Form Freeze/Halt when mouse click and hold

    Have you considered using a windows timer (SetTimer) and running text scrolling routine from the timer callback ?

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2014
    Posts
    824

    Re: Form Freeze/Halt when mouse click and hold

    not tried that. but what about the refresh? it seem that the whole form is freezed, that means it component as well.
    the text scrolling is just an example, as this issue is on all my projects that uses the default form controlbox.
    that is why i create a custom controlbox to get around the problem. but i would like to use the default form controlbox sometimes.

  4. #4
    Hyperactive Member
    Join Date
    Jun 2015
    Posts
    313

    Re: Form Freeze/Halt when mouse click and hold

    [...]
    Last edited by dz32; Apr 26th, 2019 at 11:19 AM.

  5. #5
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    5,800

    Re: Form Freeze/Halt when mouse click and hold

    I don't think a timer event is going to work. We must remember that VB6 is single-threaded. And when you drag a form by its title-bar, you are totally taking control of the thread until you've dropped it, so nothing else is going to run until you're finished with that process. That's never really bothered me though.

    I'll be interested if someone figures out a work-around though. It would probably take a mouse hook, and then possibly do a DoEvents in the mouse hook callback. And that doesn't "feel" like very good coding at all.

    Good Luck,
    Elroy

    Hmmm, actually, I'm wrong. Interestingly enough, a timer does keep firing its events. I just threw together this code to test. Form1, Timer1, Text1:

    Code:
    
    Option Explicit
    
    
    Private Sub Form_Activate()
        Timer1.Interval = 200
        Timer1.Enabled = True
    End Sub
    
    Private Sub Timer1_Timer()
        Form1.Text1.Text = Timer()
    End Sub
    
    I was quite surprised. Apparently, there's a partial DoEvents somewhere in the code when the thread is controlled by the non-client area of a form.

    EDIT2: Here's my conclusion. Events will still fire. However, if code is running in a loop, it will be suspended until the non-client area has done its thing.
    Last edited by Elroy; May 24th, 2018 at 09:28 AM.
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Dec 2014
    Posts
    824

    Re: Form Freeze/Halt when mouse click and hold

    on point Elroy, thats the purpose of this thread, is there a way that will not require subclassing the mouse and "disable" normal behavior, because if we are doing that, its easier to just make a controlbox on your own.
    when Im doing my own, I don't "hold-up" everything else when the form is moving/resizing. so, the "controlbox" is not a loop, but more of a condition, that allow everything else to run.

    so a solution could be multi-threading? how to make the form controlbox in another thread?

  7. #7
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    5,800

    Re: Form Freeze/Halt when mouse click and hold

    Wow, that sounds like it would work. It just seems like a lot of hoops to jump through just so your form keeps animating while you're dragging it around by the title-bar (or you new spoofed title-bar).

    If I were insistent upon doing that, I'd start with one of the proven multi-threading entries in the CodeBank, probably The Trick's. (Krool also has one I'd probably trust.)

    Good Luck,
    Elroy
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  8. #8
    Addicted Member
    Join Date
    Nov 2013
    Posts
    214

    Re: Form Freeze/Halt when mouse click and hold

    If you use the SetTimer API, the code in the callback function should run asychroniously emulating muti-threading ... I don't have VB6 installed but I can make it work in a userform in VBA.

  9. #9
    Addicted Member
    Join Date
    Nov 2013
    Posts
    214

    Re: Form Freeze/Halt when mouse click and hold

    If you have excel installed, you could give this a try :

    1- Standard Module :
    Code:
    Option Explicit
    
    Private Declare Function WindowFromAccessibleObject Lib "oleacc" (ByVal pacc As IAccessible, phwnd As Long) As Long
    Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
    Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    
    Public Property Let EnabelAPITimer(ByVal Form As Object, ByVal Enable As Boolean)
        Dim hwnd As Long
        WindowFromAccessibleObject Form, hwnd
        If Enable Then
            SetTimer hwnd, ObjPtr(Form), 0, AddressOf TimerProc
        Else
            KillTimer hwnd, Form.Tag
        End If
    End Property
    
    Private Sub TimerProc(ByVal hwnd As Long, ByVal MSG As Long, ByVal nIDEvent As Long, ByVal dwTimer As Long)
        Static i As Long
        Dim oForm As Object
        
        On Error GoTo Xit
        
        CopyMemory oForm, nIDEvent, LenB(nIDEvent)
        oForm.Tag = nIDEvent
        oForm.Label1.Caption = i
        i = i + 1
    Xit:
        
        CopyMemory oForm, 0, LenB(nIDEvent)
    End Sub
    2- Then in your userform add a Label control (that displays a counter) and two buttons to start and stop the timer as follows
    Code:
    Option Explicit
    
    Private Sub CommandButton1_Click()
        EnabelAPITimer(Me) = True
    End Sub
    
    Private Sub CommandButton2_Click()
        EnabelAPITimer(Me) = False
    End Sub
    You should be able to easily adapt the above for VB6.

    With this, I can click the form's caption, moving the form .. etc whithout affecting the Label control smooth updating.
    Last edited by JAAFAR; May 24th, 2018 at 07:22 PM.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width