5

I want to create an addin for vs2008, to show a transparent form/window on the editor of vs2008.

in following code, the "aw.Left" and "aw.Top" is relative value, both is 1.

QUESTION:

  1. do you know how to get the left/top screen position of the editor part?

  2. or I can move the caret to top/left char position, but do you know how to get the screen position of caret?

Great thanks.

    public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
    {
        handled = false;
        if(executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
        {
            if(commandName == "MyAddin1.Connect.MyAddin1")
            {
                Window aw = _app.ActiveWindow;
                int left = aw.Left;
                int top = aw.Top;

editor part

Siddharth Rout
  • 147,039
  • 17
  • 206
  • 250
whunmr
  • 2,435
  • 2
  • 22
  • 35
  • [`LinkedWindowFrame`](http://msdn.microsoft.com/en-us/library/vstudio/envdte.window.linkedwindowframe.aspx) allegedly gets the parent so you can just go up and up and up until you have the absolute position. Or you could make your overlay a child of the window and avoid needing the absolute position. – ta.speot.is Nov 02 '13 at 04:49
  • Maybe you can do it with macros – Kuzgun Nov 08 '13 at 07:27

1 Answers1

0

You can use the Win32 ClientToScreen function.

Declare the following external function:

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct POINT
{
    public int x;
    public int y;
};

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool ClientToScreen(IntPtr hwndClient, ref POINT lpPoint);

You can call this as follows

POINT pt = new POINT();
pt.x = left;
pt.y = top;
ClientToScreen(myForm.Handle, ref pt);

After this, pt should contain the absolute coordinates of pt. Use ScreenToClient for the opposite operation. Using the two, you can also get the location of one point relative to another window (given you know the window handle of both windows).

PMF
  • 14,535
  • 3
  • 23
  • 49