Erwin Craps
Erwin.Craps at ithelps.be
Fri Sep 19 10:53:03 CDT 2003
Yep this does work. I already found the solution with the formInfo class that included in ' From Access 2002 Desktop Developer's Handbook ' by Litwin, Getz, and Gunderloy (Sybex) ' Copyright 2001. All rights reserved. That uses pixels to. I'm adding some code to this class to PositionToMouseCursor...cause i use this FormInfo all the time. Thx... That's another beer or three at my expenses... That brings the total at 379 beers (or other, same priced, beverages) Erwin -----Original Message----- From: accessd-bounces at databaseadvisors.com [mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Brett Barabash Sent: Friday, September 19, 2003 4:56 PM To: 'Access Developers discussion and problem solving' Subject: RE: [AccessD] Screen position of mouse. Unless... You use the MoveWindow API call to reposition your form. Here is the code in it's entirety: Private Declare Function MoveWindow Lib "user32" Alias "MoveWindow" (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 GetWindowRect Lib "user32" Alias "GetWindowRect" (ByVal hwnd As Long, lpRect As RECT) As Long Private Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Type POINTAPI x As Long y As Long End Type Public Sub RepositionForm(frm As Form) Dim typPA As POINTAPI Dim typRect AS RECT 'Determine current window dimensions GetWindowRect frm.hwnd, typRect 'Determine mouse cursor position GetCursorPos typPA 'Reposition form to match mouse cursor MoveWindow frm.hwnd, typPA.x, typPA.y, (typRect.Right - typRect.Left), (typRect.Bottom - typRect.Top), 1 End Sub Easy, done... I am using code almost identical to this for a custom popup menu I created. -----Original Message----- From: Stuart McLachlan [mailto:stuart at lexacorp.com.pg] Sent: Friday, September 19, 2003 8:55 AM To: Access Developers discussion and problem solving Subject: Re: [AccessD] Screen position of mouse. On 19 Sep 2003 at 14:58, Erwin Craps wrote: > I can't find how to know the postition of the mouse on the screen. > > I have a pop-up form I want to pop-up at the same place as where the > mouse cursor is at that time. So I want to put put the code in the > on_open event of the pop-up form in question > > lngMouseLeft = ???.Left > lngMouseTop = ???.Top > > me.move lngMouseLeft, lngMouseTop > It gets quite tricky. You can find the current mouse position in pixels easily enough: In a module: Type POINTAPI x As Long y As Long End Type Declare Function GetCursorPos Lib "USER32.DLL" (lpPoint As POINTAPI) As Long In your event: Dim mptr As POINTAPI Dim result As Long result = GetCursorPos(mptr) Msgbox "Mouse is at Screen position " & mptr.x & " : " & mptr.y & " in pixels" However, that doesn't really help. Forms are positioned in twips relative to their parent (usually the main application window). You need to get a handle to the parent window using the GetActiveWindow() and GetWindow() API calls then get the location of that window using GetWindowPlacement. Then you need to convert these pixel figures to twips and use Docmd.MoveSize to place the from at an appropriate position within it's parent. -- Lexacorp Ltd http://www.lexacorp.com.pg Information Technology Consultancy, Software Development,System Support. _______________________________________________ AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com ------------------------------------------------------------------------ -------------------------------------------- This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify the originator of the message. This footer also confirms that this email message has been scanned for the presence of computer viruses. Any views expressed in this message are those of the individual sender, except where the sender specifies and with authority, states them to be the views of Tappe Construction Co. Scanning of this message and addition of this footer is performed by SurfControl E-mail Filter software in conjunction with virus detection software. _______________________________________________ AccessD mailing list AccessD at databaseadvisors.com http://databaseadvisors.com/mailman/listinfo/accessd Website: http://www.databaseadvisors.com