473,624 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Open a form to the position of the mouse

I have a command button on a continuous subform and I want the user to
click it to open a small popup form that opens in the position of the
mouse (which is the same as the position of the command button on each
record of the continuous subform.)
I'm hoping someone can tell me how to do this.
Thanks,
lq

Nov 13 '05 #1
6 25680
Rog
DoCmd.OpenForm yourform
DoCmd.MoveSize a, b, c, d

where a=right, b=down, c=width, d=height in twips.

Not sure how you can determine where your mouse pointer is located
though.

Rog

Nov 13 '05 #2
Rog
Check out this thread:
http://groups-beta.google.com/group/...20b2dc3cccd4ef

Nov 13 '05 #3
Rog wrote:
DoCmd.OpenForm yourform
DoCmd.MoveSize a, b, c, d

where a=right, b=down, c=width, d=height in twips.

Not sure how you can determine where your mouse pointer is located
though.


Perhaps, thinking out loud, when the button to open the form is clicked you open the form
in hidden mode.

Once the user clicks the mouse, in the MouseDown or MouseUp code you would then move the
form with the DoCmd.MoveSize( ) call and then make the form visible. I'm not even sure if
you can move a hidden form with MoveSize().

I left out the hardest part - once the form is opened hidden you'll need to be able to
handle the mouse click wherever it occurs within the user's desktop. Since that could be
outside the Access window you'll need to be able to subclass or hook the system mouse
event. Not sure how that would be done but a great resource is the O'Reilly book
"Subclassin g & Hooking With Visual Basic".

It should be evident that this isn't an easy task to accomplish (unless your last name is
Lebans). Of course someone may have a better idea...

--
'---------------
'John Mishefske
'---------------
Nov 13 '05 #4
I figured this out on my own so I'm posting a solution for anyone
having the same concerns:

Put the following in a code module:

Declare Sub GetCursorPos Lib "user32" (lpPoint As typPOINTAPI)

Type typPOINTAPI
x As Long
Y As Long
End Type

Declare Function apiGetWindowRec t Lib "user32" Alias _
"GetWindowR ect" (ByVal hwnd As Long, lpRect As RECT_Type) As Long
Declare Function apiGetDC Lib "user32" Alias "GetDC" _
(ByVal hwnd As Long) As Long
Declare Function apiReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal _
hwnd As Long, ByVal hdc As Long) As Long
Declare Function apiGetDeviceCap s Lib "gdi32" Alias "GetDeviceC aps"
(ByVal _
hdc As Long, ByVal nIndex As Long) As Long
Declare Function apiGetActiveWin dow Lib "user32" Alias _
"GetActiveWindo w" () As Long
Declare Function apiGetParent Lib "user32" Alias "GetParent" (ByVal _
hwnd As Long) As Long
Declare Function apiGetClassName Lib "user32" Alias "GetClassNa meA" _
(ByVal hwnd As Long, ByVal lpClassname As String, ByVal _
nMaxCount As Long) As Long

Global Const TWIPSPERINCH = 1440

Sub ConvertPixelsTo Twisps(l As Long, t As Long, x As Long, Y As Long)
On Error GoTo myErr

Dim hdc As Long, hwnd As Long, RetVal As Long, XPIXELSPERINCH,
YPIXELSPERINCH

Const LOGPIXELSX = 88
Const LOGPIXELSY = 90

'get the current number of pixels per inch, which is
resolution-dependent:
hdc = apiGetDC(0)
XPIXELSPERINCH = apiGetDeviceCap s(hdc, LOGPIXELSX)
YPIXELSPERINCH = apiGetDeviceCap s(hdc, LOGPIXELSY)
RetVal = apiReleaseDC(0, hdc)

'compute and return the measurements in twips:
If l > 0 Then l = (l / XPIXELSPERINCH) * TWIPSPERINCH '>left
If t > 0 Then t = (t / XPIXELSPERINCH) * TWIPSPERINCH '>top
x = (x / XPIXELSPERINCH) * TWIPSPERINCH '>width
Y = (Y / YPIXELSPERINCH) * TWIPSPERINCH '>height

myExit:
Exit Sub
myErr:
msgbox Err.Number & " " & Err.Description
Resume myExit
End Sub

In the module opening your form paste the following:

Function OpenMyForm(myFr m as String)
'myFrm is the name of your form to open to your current mouse pointer
location

Dim TipPoint As typPOINTAPI, myvar1 As Long, myvar2 As Long, myFrm As
String, myStatusFile As String
'get the current mouse position:
GetCursorPos TipPoint

myvar1 = (TipPoint.x)
myvar2 = (TipPoint.Y)

Call ConvertPixelsTo Twisps(myvar1, myvar2, 0, 0)

DoCmd.OpenForm myFrm

'>position the form
DoCmd.MoveSize myvar1, myvar2

End Function

John Mishefske wrote:
Rog wrote:
DoCmd.OpenForm yourform
DoCmd.MoveSize a, b, c, d

where a=right, b=down, c=width, d=height in twips.

Not sure how you can determine where your mouse pointer is located
though.


Perhaps, thinking out loud, when the button to open the form is clicked you open the form
in hidden mode.

Once the user clicks the mouse, in the MouseDown or MouseUp code you would then move the
form with the DoCmd.MoveSize( ) call and then make the form visible. I'm not even sure if
you can move a hidden form with MoveSize().

I left out the hardest part - once the form is opened hidden you'll need to be able to
handle the mouse click wherever it occurs within the user's desktop. Since that could be
outside the Access window you'll need to be able to subclass or hook the system mouse
event. Not sure how that would be done but a great resource is the O'Reilly book
"Subclassin g & Hooking With Visual Basic".

It should be evident that this isn't an easy task to accomplish (unless your last name is
Lebans). Of course someone may have a better idea...

--
'---------------
'John Mishefske
'---------------


Nov 13 '05 #5
Lauren have you tested your solution under the following scenarios?

The Main Access application Window sized smaller then if maximized.

The Main Access application Window sized smaller then if maximized and
not in the top left corner

Your form's Popup property for both Yes and No.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"lauren quantrell" <la************ *@hotmail.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.com.. .
I figured this out on my own so I'm posting a solution for anyone
having the same concerns:

Put the following in a code module:

Declare Sub GetCursorPos Lib "user32" (lpPoint As typPOINTAPI)

Type typPOINTAPI
x As Long
Y As Long
End Type

Declare Function apiGetWindowRec t Lib "user32" Alias _
"GetWindowR ect" (ByVal hwnd As Long, lpRect As RECT_Type) As Long
Declare Function apiGetDC Lib "user32" Alias "GetDC" _
(ByVal hwnd As Long) As Long
Declare Function apiReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal _
hwnd As Long, ByVal hdc As Long) As Long
Declare Function apiGetDeviceCap s Lib "gdi32" Alias "GetDeviceC aps"
(ByVal _
hdc As Long, ByVal nIndex As Long) As Long
Declare Function apiGetActiveWin dow Lib "user32" Alias _
"GetActiveWindo w" () As Long
Declare Function apiGetParent Lib "user32" Alias "GetParent" (ByVal _
hwnd As Long) As Long
Declare Function apiGetClassName Lib "user32" Alias "GetClassNa meA" _
(ByVal hwnd As Long, ByVal lpClassname As String, ByVal _
nMaxCount As Long) As Long

Global Const TWIPSPERINCH = 1440

Sub ConvertPixelsTo Twisps(l As Long, t As Long, x As Long, Y As Long)
On Error GoTo myErr

Dim hdc As Long, hwnd As Long, RetVal As Long, XPIXELSPERINCH,
YPIXELSPERINCH

Const LOGPIXELSX = 88
Const LOGPIXELSY = 90

'get the current number of pixels per inch, which is
resolution-dependent:
hdc = apiGetDC(0)
XPIXELSPERINCH = apiGetDeviceCap s(hdc, LOGPIXELSX)
YPIXELSPERINCH = apiGetDeviceCap s(hdc, LOGPIXELSY)
RetVal = apiReleaseDC(0, hdc)

'compute and return the measurements in twips:
If l > 0 Then l = (l / XPIXELSPERINCH) * TWIPSPERINCH '>left
If t > 0 Then t = (t / XPIXELSPERINCH) * TWIPSPERINCH '>top
x = (x / XPIXELSPERINCH) * TWIPSPERINCH '>width
Y = (Y / YPIXELSPERINCH) * TWIPSPERINCH '>height

myExit:
Exit Sub
myErr:
msgbox Err.Number & " " & Err.Description
Resume myExit
End Sub

In the module opening your form paste the following:

Function OpenMyForm(myFr m as String)
'myFrm is the name of your form to open to your current mouse pointer
location

Dim TipPoint As typPOINTAPI, myvar1 As Long, myvar2 As Long, myFrm As
String, myStatusFile As String
'get the current mouse position:
GetCursorPos TipPoint

myvar1 = (TipPoint.x)
myvar2 = (TipPoint.Y)

Call ConvertPixelsTo Twisps(myvar1, myvar2, 0, 0)

DoCmd.OpenForm myFrm

'>position the form
DoCmd.MoveSize myvar1, myvar2

End Function

John Mishefske wrote:
Rog wrote:
DoCmd.OpenForm yourform
DoCmd.MoveSize a, b, c, d

where a=right, b=down, c=width, d=height in twips.

Not sure how you can determine where your mouse pointer is located
though.


Perhaps, thinking out loud, when the button to open the form is clicked you open the form in hidden mode.

Once the user clicks the mouse, in the MouseDown or MouseUp code you would then move the form with the DoCmd.MoveSize( ) call and then make the form visible. I'm not even sure if you can move a hidden form with MoveSize().

I left out the hardest part - once the form is opened hidden you'll need to be able to handle the mouse click wherever it occurs within the user's desktop. Since that could be outside the Access window you'll need to be able to subclass or hook the system mouse event. Not sure how that would be done but a great resource is the O'Reilly book "Subclassin g & Hooking With Visual Basic".

It should be evident that this isn't an easy task to accomplish (unless your last name is Lebans). Of course someone may have a better idea...

--
'---------------
'John Mishefske
'---------------


Nov 13 '05 #6
Stephen,
I have tested this with the Access 2000 application window in various
states including maximized, smaller and larger than the form calling
the function. I have used and tested it on popup and non-popup forms
alike, however the form that opens using this method is always set as a
popup form, since I use it as a substitute for a shortcut menu.
lq

Nov 13 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3593
by: x muzuo | last post by:
Hi guys, I have got a prob of javascript form validation which just doesnt work with my ASP code. Can any one help me out please. Here is the code: {////<<head> <title>IIBO Submit Page</title> </head> <style type="text/css">
1
385
by: lauren quantrell | last post by:
I have a command button on a continuous subform and I want the user to click it to open a small popup form that opens in the position of the mouse (which is the same as the position of the command button on each record of the continuous subform.) I'm hoping someone can tell me how to do this. Thanks, lq
8
12660
by: NeoAsimov | last post by:
Hello, There is what I want to do. I worked on the problem since 6 hours but I had a problem (probably stupid) and I dont know how to resolve it. I need to have an Mouse Event Click when I click on the frame of a window form ( like the title bar of a window).
3
5738
by: Robert Lochon | last post by:
Hi ! I've got this strange problem : When I press the left-button and move my mouse, my form moves just as intended. But if I make big movements, the cursor shifts slightly. And it ends with the mouse cursor completly out of the form, which is not what I want, of course. Here's the relevant snippet of my code :
0
1370
by: Raj Chudasama | last post by:
In dot net 2003 on Xp when you go to the file menu and select Open file a dialog box opens up on the left hand side there are items such as history My Projects Desktop Favorites My Network places
18
2948
by: Colin McGuire | last post by:
Hi - this was posted last weekend and unfortunately not resolved. The solutions that were posted almost worked but after another 5 days of working on the code everynight, I am not further ahead. If you do have any ideas I would really like to hear them. Thanks Colin - 0 - 0 - 0 - I want a glorified popup/context menu on a button that shows only when
5
1739
by: sagar | last post by:
is there any way to find the position of mouse click on a form actually the problem is i m having more than one controls on a form i want to find which control is selected using mouse down any help is fine for me thanks
1
12612
by: Marcolino | last post by:
Hi, I'm new with VB.net and I comming from VB6 programming. I need to open a little form in Modal and child of MDI, with the top- left corner where the mouse has clicked. I tryed this code but the form show everywhere but not where i need: Private Sub btnDataAcquisto_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDataAcquisto.Click Dim frm As New frmKeeperDate
3
4284
by: Boki | last post by:
Hi All, I saw the paint.net program, when mouse hover, the color palette become 100% opacity. I try the code below, the issue is I also have some other controls ( textbox/button ) in my form, it should be a better way to do it in fewer codes, right ? ( set all hover function to the same as form ? )
0
8172
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8677
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8620
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7158
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5563
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.