0

this question is about a tooltip that you can implement very easy in order
to track mouse location via it's coordinates the only problem for me is to add the ability to track the coordinates on a specific window after setting it to foreground ... and it's not a form , but a 3rd party application .

the code which works for me on the visual studio windows form is

ToolTip trackTip;

    private void TrackCoordinates()
    {
        trackTip = new ToolTip();
        this.MouseMove += new MouseEventHandler(Form1_MouseMove);
    }

    void Form1_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
    {
        String tipText = String.Format("({0}, {1})", e.X, e.Y);
        trackTip.Show(tipText, this, e.Location);
    }

//thats a code i have seen somewhere on the web and then again after some more googling found the msdn source at the url :

msdn source url

so the question remains if you'll be kind to answer : how do i get tool tip coordinates of a 3rd party (other than Vs winform window)

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
LoneXcoder
  • 2,121
  • 6
  • 38
  • 76

2 Answers2

0

subsclass the target window and listen for WM_MOUSEMOVE messages.

Or

Use a timer and grab the mouse screen coordinates.

Sam Axe
  • 33,313
  • 9
  • 55
  • 89
0

You need to use one of the following (as it is explained in this question):

1.Using Windows Forms. Add a reference to System.Windows.Forms

public static Point GetMousePositionWindowsForms() 
{ 
    System.Drawing.Point point = Control.MousePosition; 
    return new Point(point.X, point.Y); 
} 

2.Using Win32

[DllImport("user32.dll")] 
[return: MarshalAs(UnmanagedType.Bool)] 
internal static extern bool GetCursorPos(ref Win32Point pt); 

[StructLayout(LayoutKind.Sequential)] 
internal struct Win32Point 
{ 
    public Int32 X; 
    public Int32 Y; 
}; 
public static Point GetMousePosition() 
{ 
    Win32Point w32Mouse = new Win32Point(); 
    GetCursorPos(ref w32Mouse); 
    return new Point(w32Mouse.X, w32Mouse.Y); 
} 
Community
  • 1
  • 1
Salvador Sarpi
  • 981
  • 1
  • 8
  • 19