Joe Rojas
JRojas at tnco-inc.com
Fri Apr 8 12:40:49 CDT 2005
Thanks for the help Gustav! JR -----Original Message----- From: Gustav Brock [mailto:Gustav at cactus.dk] Sent: Friday, April 08, 2005 1:26 PM To: accessd at databaseadvisors.com Subject: Re: [AccessD] Form Positioning Hi Joe We use the module below for basic screen metrics. You should be able to use the sub CenterForm to model your PositionForm sub by using the handle of the other form and not GetParent(). /gustav <code> Option Compare Database Option Explicit ' Windows handle of desktop. Private Const HWND_DESKTOP As Long = 0 ' Number of Twips per inch. Private Const TWIPS_PER_INCH As Long = 1440 ' Pixel width. Private Const LOGPIXELSX As Long = 88 ' Pixel height. Private Const LOGPIXELSY As Long = 90 ' Screen width. Private Const SM_CXSCREEN As Long = 0 ' Screen height. Private Const SM_CYSCREEN As Long = 1 Public Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Declare Function GetSystemMetrics Lib "user32" ( _ ByVal nIndex As Long) _ As Long Private Declare Function GetDC Lib "user32" ( _ ByVal hwnd As Long) _ As Long Private Declare Function ReleaseDC Lib "user32" ( _ ByVal hwnd As Long, _ ByVal hdc As Long) _ As Long Private Declare Function GetDeviceCaps Lib "gdi32" ( _ ByVal hdc As Long, _ ByVal nIndex As Long) _ As Long Private Declare Function GetParent Lib "user32" ( _ ByVal hwnd As Long) _ As Long Private Declare Function GetWindowRect Lib "user32" ( _ ByVal hwnd As Long, _ lpRect As RECT) _ As Long Public 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 Public Function ScreenWidth() As Long ' Returns the width of the screen in pixels. ScreenWidth = GetSystemMetrics(SM_CXSCREEN) End Function Public Function ScreenHeight() As Long ' Returns the height of the screen in pixels. ScreenHeight = GetSystemMetrics(SM_CYSCREEN) End Function Public Function TwipsPerPixelX() As Single ' Returns the width of a pixel, in twips. Dim lngDC As Long Dim sngTwipsPerPixel As Single lngDC = GetDC(HWND_DESKTOP) sngTwipsPerPixel = TWIPS_PER_INCH / GetDeviceCaps(lngDC, LOGPIXELSX) ReleaseDC HWND_DESKTOP, lngDC TwipsPerPixelX = sngTwipsPerPixel End Function Public Function TwipsPerPixelY() As Single ' Returns the height of a pixel, in twips. Dim lngDC As Long Dim sngTwipsPerPixel As Single lngDC = GetDC(HWND_DESKTOP) sngTwipsPerPixel = TWIPS_PER_INCH / GetDeviceCaps(lngDC, LOGPIXELSY) ReleaseDC HWND_DESKTOP, lngDC TwipsPerPixelY = sngTwipsPerPixel End Function Public Sub CenterForm(frm As Form) Dim rctMDI As RECT Dim lngRetVal As Long Dim lngWidth As Long Dim lngHeight As Long Dim lngLeft As Long Dim lngTop As Long lngRetVal = GetWindowRect(GetParent(frm.hwnd), rctMDI) lngWidth = frm.WindowWidth \ CLng(TwipsPerPixelX()) lngHeight = frm.WindowHeight \ CLng(TwipsPerPixelY()) lngLeft = (rctMDI.Right - rctMDI.Left - lngWidth) \ 2 If lngLeft < 0 Then lngLeft = 0 End If lngTop = (rctMDI.Bottom - rctMDI.Top - lngHeight) \ 2 If lngTop < 0 Then lngTop = 0 End If lngRetVal = MoveWindow(frm.hwnd, lngLeft, lngTop, lngWidth, lngHeight, True) End Sub </code> >>> JRojas at tnco-inc.com 04/06 10:33 pm >>> Hi All, I want to open a form in a specific location with relation to another form. How can I do this? Thanks! JR -- AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com This electronic transmission is strictly confidential to TNCO, Inc. and intended solely for the addressee. It may contain information which is covered by legal, professional, or other privileges. If you are not the intended addressee, or someone authorized by the intended addressee to receive transmissions on behalf of the addressee, you must not retain, disclose in any form, copy, or take any action in reliance on this transmission. If you have received this transmission in error, please notify the sender as soon as possible and destroy this message. While TNCO, Inc. uses virus protection, the recipient should check this email and any attachments for the presence of viruses. TNCO, Inc. accepts no liability for any damage caused by any virus transmitted by this email.