"rkc" <rk*@yabba.dabba.do.rochester.rr.bomb> wrote in news:Tytxb.106977
$1********@twister.nyroc.rr.com:
"Lyle Fairfield" <Mi************@Invalid.Com> wrote in message
news:Xn*******************@130.133.1.4... > "Lyle Fairfield" <Mi************@Invalid.Com> wrote in message
> news:Xn*******************@130.133.1.4...
wbHDSBHekp is the web browser control.
PlaceForm is another story.
A mystery it seems.
I always wanted to be a mystery writer ... or even a mystery weapon of mass
destruction. I suppose I have a greater chance at the former:
Option Explicit
Private Declare Function GetWindowRect Lib "user32" _
(ByVal hwnd As Long, lpRect As Rectangle) As Long
Private Declare Function SetWindowPos Lib "user32" _
(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 Const HWND_TOP As Long = 0
Private Const HWND_TOPMOST As Long = -1
Private Const SWP_NOZORDER As Long = &H4
Private Const SWP_NOOWNERZORDER As Long = &H2
Private Type Dimensions
Width As Long
Height As Long
End Type
Private Type Rectangle
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Sub PlaceForm(ByRef Form As Form, Optional ByVal Center As Boolean,
Optional Below As Boolean)
Dim AccessDimensions As Dimensions
Dim AccessRectangle As Rectangle
Dim AccessWindow As Long
Dim CallingForm As Form
Dim CallingFormDimensions As Dimensions
Dim CallingFormRectangle As Rectangle
Dim CallingFormWindow As Long
Dim FormDimensions As Dimensions
Dim FormRectangle As Rectangle
Dim FormWindow As Long
Dim WindowStyleInformation As Long
Dim Slack As Long
On Error Resume Next
AccessWindow = hWndAccessApp
GetWindowRect AccessWindow, AccessRectangle
With AccessRectangle
AccessDimensions.Width = .Right - .Left
AccessDimensions.Height = .Bottom - .Top
End With
Set CallingForm = Application.Screen.ActiveForm
If Not CallingForm Is Nothing Then
CallingFormWindow = CallingForm.hwnd
GetWindowRect CallingFormWindow, CallingFormRectangle
With CallingFormRectangle
CallingFormDimensions.Width = .Right - .Left
CallingFormDimensions.Height = .Bottom - .Top
End With
End If
FormWindow = Form.hwnd
GetWindowRect FormWindow, FormRectangle
With FormRectangle
FormDimensions.Width = .Right - .Left
FormDimensions.Height = .Bottom - .Top
End With
If Center = True Then
FormRectangle.Top = (AccessRectangle.Bottom -
FormDimensions.Height) / 2
FormRectangle.Left = (AccessRectangle.Right - FormDimensions.Width)
/ 2
ElseIf Below = True Then
FormRectangle.Left = CallingFormRectangle.Left
FormRectangle.Top = CallingFormRectangle.Bottom
Else
FormRectangle.Left = CallingFormRectangle.Right
' How much room is there to the right of the form now
Slack = AccessRectangle.Right - FormRectangle.Left
' if there is not enough room on rhs
If Slack < FormDimensions.Width Then
Slack = CallingFormRectangle.Left - AccessRectangle.Left
' if there's enough room on lhs
If Slack > FormDimensions.Width Then
' move it
FormRectangle.Left = CallingFormRectangle.Left -
FormDimensions.Width
End If
End If
FormRectangle.Top = CallingFormRectangle.Top
' How much room is there below the form now
Slack = AccessRectangle.Bottom - FormRectangle.Top
' if there is not enough room on rhs
If Slack < FormDimensions.Height Then
' move it up until so there is enough room
FormRectangle.Top = AccessRectangle.Bottom -
FormDimensions.Height
End If
' but in any case don't move it out of the access window
If FormRectangle.Top < AccessRectangle.Top Then
FormRectangle.Top = AccessRectangle.Top
End If
End If
SetWindowPos FormWindow, HWND_TOP, FormRectangle.Left,
FormRectangle.Top, FormDimensions.Width, FormDimensions.Height,
SWP_NOZORDER
End Sub
This sub which centers a form, or places it below or beside the form that
called it, has grown without a lot of structure and in response to many
needs, so there may be some redundancy in the code. I'll fix it up as soon
as I have some spare time ... 2008 probably.
--
Lyle
(for e-mail refer to
http://ffdba.com/contacts.htm)