-
May 23rd, 2018, 11:45 PM
#1
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?
-
May 24th, 2018, 12:24 AM
#2
Fanatic Member
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 ?
-
May 24th, 2018, 08:01 AM
#3
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.
-
May 24th, 2018, 09:09 AM
#4
Re: Form Freeze/Halt when mouse click and hold
Last edited by dz32; Apr 26th, 2019 at 11:19 AM.
-
May 24th, 2018, 09:19 AM
#5
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. To all, peace and happiness.
-
May 24th, 2018, 09:32 AM
#6
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?
-
May 24th, 2018, 10:04 AM
#7
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. To all, peace and happiness.
-
May 24th, 2018, 01:24 PM
#8
Fanatic Member
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.
-
May 24th, 2018, 07:19 PM
#9
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|