|
-
Apr 19th, 2002, 10:23 AM
#1
Thread Starter
Fanatic Member
Detecting form movement - how??
I need to detect when my window has been moved by the user. I can't find an event and searches have been quite unhelpful. Can anybody help??
The liver is bad. It must be punished.
-
Apr 19th, 2002, 10:28 AM
#2
You could subclass it for the WM_MOVE or WM_MOVING message.
-
Apr 19th, 2002, 10:32 AM
#3
Thread Starter
Fanatic Member
Hmm, I have absolutely no idea on how that is done ? (I'm more a db guy)? Do you have a link easily available
The liver is bad. It must be punished.
-
Apr 19th, 2002, 10:32 AM
#4
Fanatic Member
You could also do it with the very simple (but slow) way of using a loop or timer.
VB Code:
Do while Running
If (me.left <> oldX) or (me.top <> oldY) Then
'Code for when the form moves.
End If
Loop
OR
VB Code:
Private Sub tmrMove_timmer()
If (me.left <> oldX) or (me.top <> oldY) Then
'Code for when the form moves.
End If
End Sub
Hope this helps.
-
Apr 19th, 2002, 10:35 AM
#5
Fanatic Member
The loop would be faster, but you have to make sure to place a doevents in it somewhere. You would also have to exit the loop before you could shut down the program (otherwise the program would still use memory & processer power). Thats what the running boolean is for.
-
Apr 19th, 2002, 10:37 AM
#6
Thread Starter
Fanatic Member
The timer could work, but I would get my arse kicked for using one. Hmmm, I'd better do a search on sub-classing. Thanks anyway Gaming_world.
The liver is bad. It must be punished.
-
Apr 19th, 2002, 10:43 AM
#7
Fanatic Member
The loop would work too, although it is also slower then sub-classing. It mostly depends on what you are doing. If the program is for something when speed is not critical, a timer would work. If a timer would be too slow, but speed is not life & death, the loop would work. If it is a game, where speed is life & death, you need sub-classing.
-
Apr 19th, 2002, 10:47 AM
#8
Frenzied Member
The EventVB.dll has a class called ApiWindow which has both a Move and a Moving event which you can use thus:
VB Code:
Option Explicit
Dim WithEvents vbLink As EventVB.APIFunctions
Dim WithEvents vbWnd As EventVB.ApiWindow
Private Sub Form_Load()
Set vbLink = New APIFunctions
Set vbWnd = New ApiWindow
vbWnd.hWnd = Me.hWnd
'\\ Subclass this form
vbLink.SubclassedWindows.Add vbWnd
End Sub
Private Sub vbWnd_Move(ByVal x As Long, ByVal y As Long, Cancel As Boolean)
Me.Caption = "Moved to : " & x & "," & y
End Sub
Private Sub vbWnd_Moving(ByVal MoveEdges As EventVB.WindowSizingEdges, MoveRectangle As EventVB.APIRect)
With MoveRectangle
Me.Caption = "Moving - " & .Left & "," & .Top
End With
End Sub
The difference is that the Moving event fires while the form is being dragged and the Move event fires after the move has occured.
If you change the MoveRectangle property in the Moving event you can control how (and if) the form can be moved. For example, to prevent the form being moved below half way down the form....
VB Code:
Private Sub vbWnd_Moving(ByVal MoveEdges As EventVB.WindowSizingEdges, MoveRectangle As EventVB.APIRect)
With MoveRectangle
If .Top > (Screen.Height / 2) / Screen.TwipsPerPixelY Then
.Top = (Screen.Height / 2) / Screen.TwipsPerPixelY
End If
End With
End Sub
End Sub
HTH,
Duncan
Last edited by MerrionComputin; Apr 19th, 2002 at 10:57 AM.
-
Apr 19th, 2002, 10:51 AM
#9
Thread Starter
Fanatic Member
Merrion you star! That looks exactly like what I'm looking for. Thank you very much. I'll try it on Monday now as I've fallen out of work mode!
The liver is bad. It must be punished.
-
Apr 19th, 2002, 10:53 AM
#10
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
|