Get mouse position for input box control?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Get mouse position for input box control?

  1. #1
    CM Guest

    Get mouse position for input box control?


    I need to get the mouse position, when I click on a button it brings up an
    inputbox that I want to position near the mouse pointer, how would I do this?

  2. #2
    Tom Esh Guest

    Re: Get mouse position for input box control?

    On 23 Dec 2002 07:40:21 -0800, "CM" <vb.@127.0.0.1> wrote:
    >I need to get the mouse position, when I click on a button it brings up an
    >inputbox that I want to position near the mouse pointer, how would I do this?


    You can use the GetCursorPos Api function to obtain the current
    screen-relative position. Note it works with pixels, so you'll need to
    convert to twips to position the InputBox.

    'declarations - bas module (or change to Private if declared in Form).
    Public Type POINTAPI
    X As Long
    Y As Long
    End Type

    Public Declare Function GetCursorPos Lib "user32" _
    (lpPoint As POINTAPI) As Long

    '== example usage - anywhere...
    Dim PT As POINTAPI
    GetCursorPos PT
    PT.X = PT.X * Screen.TwipsPerPixelX
    PT.Y = PT.Y * Screen.TwipsPerPixelY
    InputBox "prompt", "title", "default", PT.X, PT.Y


    -Tom
    MVP - Visual Basic
    (please post replies to the newsgroup)

  3. #3
    Guest

    Re: Get mouse position for input box control?


    Thanks thats exactly what I needed. I had the first half just didnt know about
    the conversion.

    Tom Esh <tjeshGibberish@earthlink.net> wrote:
    >On 23 Dec 2002 07:40:21 -0800, "CM" <vb.@127.0.0.1> wrote:
    >>I need to get the mouse position, when I click on a button it brings up

    an
    >>inputbox that I want to position near the mouse pointer, how would I do

    this?
    >
    >You can use the GetCursorPos Api function to obtain the current
    >screen-relative position. Note it works with pixels, so you'll need to
    >convert to twips to position the InputBox.
    >
    >'declarations - bas module (or change to Private if declared in Form).
    >Public Type POINTAPI
    > X As Long
    > Y As Long
    >End Type
    >
    >Public Declare Function GetCursorPos Lib "user32" _
    > (lpPoint As POINTAPI) As Long
    >
    >'== example usage - anywhere...
    >Dim PT As POINTAPI
    >GetCursorPos PT
    >PT.X = PT.X * Screen.TwipsPerPixelX
    >PT.Y = PT.Y * Screen.TwipsPerPixelY
    >InputBox "prompt", "title", "default", PT.X, PT.Y
    >
    >
    >-Tom
    >MVP - Visual Basic
    >(please post replies to the newsgroup)



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center