J
Jon Lewis
I'm trying to tile a series of instances of the same Form by reteiving the a
form's position using GetWindowsRect, adding a fixed amount (actually the
title bar height) to the Left & Top elements and then using SetWindowsPos
with the new Left & Top values on the subsequent form.
However, extra X (a tiny bit) and Y (quite alot) shift happens.
So I tested the procedure by doing a GetWindowsRect and SetWindowsPos on the
same Form, leaving the Left & Top values the same. I would expect the Form
to remain in the same position but it doesn't. The MoveWindow api produces
exactly the same results.
The code that follows illustrates this. (Drop into a form - cmdMove is
obviously a command button).
I'm working within MSAccess so I don't know if this is an api issue or to do
with a peculiarity of Access forms.
Can anyone explain or suggest a resolution please?
BTW I can't use code from within the forms themselves so DoCmd.MoveSize
won't work for me.
TIA
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function MoveWindow Lib "user32" (ByVal hWnd As Long, _
ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As
Long, _
ByVal bRepaint As Long) As Long
Private Declare Function SetWindowPos Lib "user32.dll" (ByVal hWnd As Long,
_
ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, _
ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function GetWindowRect Lib "user32.dll" _
(ByVal hWnd As Long, lpRect As RECT) As Long
Private Const SWP_NOSIZE = &H1 'don't resise the window
Private Const HWND_TOP = 0 'Put the window at the top of the Z-order.
Private Sub cmdMove_Click()
Dim R As RECT, s As RECT, t As RECT
Call GetWindowRect(Me.hWnd, R)
MsgBox R.Left & ", " & R.Top
MsgBox "Set"
Call SetWindowPos(Me.hWnd, HWND_TOP, R.Left, R.Top, 1, 1, SWP_NOSIZE)
Call GetWindowRect(Me.hWnd, s)
MsgBox s.Left & ", " & s.Top
MsgBox "Move"
Call MoveWindow(Me.hWnd, R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top,
True)
Call GetWindowRect(Me.hWnd, t)
MsgBox t.Left & ", " & t.Top
End Sub
form's position using GetWindowsRect, adding a fixed amount (actually the
title bar height) to the Left & Top elements and then using SetWindowsPos
with the new Left & Top values on the subsequent form.
However, extra X (a tiny bit) and Y (quite alot) shift happens.
So I tested the procedure by doing a GetWindowsRect and SetWindowsPos on the
same Form, leaving the Left & Top values the same. I would expect the Form
to remain in the same position but it doesn't. The MoveWindow api produces
exactly the same results.
The code that follows illustrates this. (Drop into a form - cmdMove is
obviously a command button).
I'm working within MSAccess so I don't know if this is an api issue or to do
with a peculiarity of Access forms.
Can anyone explain or suggest a resolution please?
BTW I can't use code from within the forms themselves so DoCmd.MoveSize
won't work for me.
TIA
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Function MoveWindow Lib "user32" (ByVal hWnd As Long, _
ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As
Long, _
ByVal bRepaint As Long) As Long
Private Declare Function SetWindowPos Lib "user32.dll" (ByVal hWnd As Long,
_
ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, _
ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function GetWindowRect Lib "user32.dll" _
(ByVal hWnd As Long, lpRect As RECT) As Long
Private Const SWP_NOSIZE = &H1 'don't resise the window
Private Const HWND_TOP = 0 'Put the window at the top of the Z-order.
Private Sub cmdMove_Click()
Dim R As RECT, s As RECT, t As RECT
Call GetWindowRect(Me.hWnd, R)
MsgBox R.Left & ", " & R.Top
MsgBox "Set"
Call SetWindowPos(Me.hWnd, HWND_TOP, R.Left, R.Top, 1, 1, SWP_NOSIZE)
Call GetWindowRect(Me.hWnd, s)
MsgBox s.Left & ", " & s.Top
MsgBox "Move"
Call MoveWindow(Me.hWnd, R.Left, R.Top, R.Right - R.Left, R.Bottom - R.Top,
True)
Call GetWindowRect(Me.hWnd, t)
MsgBox t.Left & ", " & t.Top
End Sub