|
-
Jun 5th, 2003, 07:08 AM
#1
Thread Starter
Lively Member
Move Form Event?
Is is possible to catch the Move Event of a form without using a message handler?
-
Jun 5th, 2003, 07:10 AM
#2
By 'using a message handler', do you mean subclassing?
If so, then the only other way is to use a timer and check the position against the old position. But that's not a very nice way.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Jun 5th, 2003, 07:18 AM
#3
Thread Starter
Lively Member
Thanks for you quick response crptcblade.
I hope there is another way to get around it.
Thanks again...
-Pls excuse my grammar-
-
Jun 5th, 2003, 07:18 AM
#4
Here's some code (that I found somewhere around here) that forces your form to stay on the screen. Just change the WM_MOVING case code as you need :
VB Code:
'** In a standard module
Option Explicit
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) _
As Long
Private 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
Private Declare Function DefWindowProc Lib "user32" Alias "DefWindowProcA" (ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) _
As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, _
Source As Any, _
ByVal Length As Long)
Private Const GWL_WNDPROC = (-4)
Private Const WM_MOVING = &H216
Private Const WMSZ_LEFT = 1
Private Const WMSZ_RIGHT = 2
Private Const WMSZ_TOP = 3
Private Const WMSZ_TOPLEFT = 4
Private Const WMSZ_TOPRIGHT = 5
Private Const WMSZ_BOTTOM = 6
Private Const WMSZ_BOTTOMLEFT = 7
Private Const WMSZ_BOTTOMRIGHT = 8
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private mPrevProc As Long
Public Sub Hook(ByVal hwnd As Long)
mPrevProc = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WndProc)
End Sub
Public Sub Unhook(ByVal hwnd As Long)
Call SetWindowLong(hwnd, GWL_WNDPROC, mPrevProc)
mPrevProc = 0&
End Sub
Private Function PScreenWidth() As Long
PScreenWidth = (Screen.Width \ 15)
End Function
Private Function PScreenHeight() As Long
PScreenHeight = (Screen.Height \ 15)
End Function
Public Function WndProc(ByVal hwnd As Long, ByVal uMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) _
As Long
On Error Resume Next
Dim r As RECT
Dim lTemp As Long
If uMsg = WM_MOVING Then
Call CopyMemory(r, ByVal lParam, Len(r))
If r.Left < 0 Then
lTemp = r.Right - r.Left
r.Left = 0
r.Right = lTemp
End If
If r.Right > PScreenWidth Then
lTemp = r.Right - r.Left
r.Right = PScreenWidth
r.Left = r.Right - lTemp
End If
If r.Top < 0 Then
lTemp = r.Bottom - r.Top
r.Top = 0
r.Bottom = lTemp
End If
If r.Bottom > PScreenHeight Then
lTemp = r.Bottom - r.Top
r.Bottom = PScreenHeight
r.Top = r.Bottom - lTemp
End If
Call CopyMemory(ByVal lParam, r, Len(r))
End If
If mPrevProc& Then
WndProc = CallWindowProc(mPrevProc, hwnd, uMsg, wParam, lParam)
Else
WndProc = DefWindowProc(hwnd, uMsg, wParam, lParam)
End If
End Function
VB Code:
'** In your form
Option Explicit
Private Sub Form_Load()
Call Hook(Me.hwnd)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call Unhook(Me.hwnd)
End Sub
Has someone helped you? Then you can Rate their helpful post. 
-
Jun 5th, 2003, 07:39 AM
#5
Thread Starter
Lively Member
Thanks manavo11, but I really don't want to subclass it if possible.
-
Jun 5th, 2003, 07:54 AM
#6
You could install a WH_CBT hook which would notify you if any of your forms moved - although if you are shy of subclassing then hooking is probably anaethema to you....
How about a component that does the subclassing on your behalf?
-
Jun 5th, 2003, 11:13 AM
#7
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
|