|
-
Aug 9th, 2000, 10:52 AM
#1
Thread Starter
Fanatic Member
Is there some property/method thing so you can detect when a form is being moved/has been moved? Can't seem to find anything, but then I'm just like that...
-
Aug 9th, 2000, 11:08 AM
#2
Hyperactive Member
No property that I know of
There is no property I know of that detects that but I know a means of detecting if the form has been moved with a little code. I am not sure if it is quite what you are looking for, but it does work.
Code:
Private Sub Form_Activate()
Dim left1 As Integer
Dim top1 As Integer
left1 = Form1.left
top1 = Form1.top
Do
If (left1 <> Form1.left) or (top1 <> Form1.top) Then
'(your code)
end if
DoEvents 'keeps windows processes functioning
Loop
End Sub
You can place that directly into your form's activation. I hope it is what you are looking for.(By the way if you want to know if it has been moved multiple times then change left1 and top1 every time the form is moved)
Tell me if it works and if you have a question, just post.
Good Luck,
Joe
-
Aug 9th, 2000, 11:08 AM
#3
You can Subclass your Form.
Code for a Module
Code:
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Const GWL_WNDPROC = (-4)
Const WM_MOVE = &H3
Const WM_EXITSIZEMOVE = &H232
Global WndProcOld As Long
Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If wMsg = WM_EXITSIZEMOVE Then
'The Form has finished moving
MsgBox ("Form1 has been moved")
End If
If wMsg = WM_MOVE Then
'The Form is moving
Form1.Print "Form is moving"
End If
WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
End Function
Sub SubClassWnd(hwnd As Long)
WndProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindProc)
End Sub
Sub UnSubclassWnd(hwnd As Long)
SetWindowLong hwnd, GWL_WNDPROC, WndProcOld&
WndProcOld& = 0
End Sub
Code for Form
Code:
Private Sub Form_Load()
SubClassWnd Me.hwnd
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnSubclassWnd Me.hwnd
End Sub
-
Aug 9th, 2000, 12:31 PM
#4
Hyperactive Member
Or you could set its left and top properties. The then under form_move create a if statement to see if the value match.
Matt 
-
Aug 9th, 2000, 12:51 PM
#5
There is no Form_Move event.
-
Aug 10th, 2000, 04:45 AM
#6
Thread Starter
Fanatic Member
Thanks chaps.
- Joe, yup, it works ok but I'm a bit wary of enless loops like that, and it does seem to behave a little strangely when you close it.
- Megatron, like it - any chance you eplaining to me just what the hell SUBCLASS means? As senior developer here at Microsoft (joke) , I think it's something I should understand.
Anyway, thanks for all your help guys... -Nick
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
|