如何获取Visual Studio 2008编辑器窗口的左上方屏幕位置?

5

我希望创建一个适用于vs2008的插件,可以在编辑器上显示一个透明的表单/窗口。

在下面的代码中,“aw.Left”和“aw.Top”是相对值,均为1。

问题:

  1. 你知道如何获取编辑器部分的左/上屏幕位置吗?

  2. 或者我可以将插入符移动到顶部/左侧字符位置,但你知道如何获取插入符的屏幕位置吗?

非常感谢。

    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


LinkedWindowFrame 据说可以获取父级,因此您可以一直向上移动,直到获得绝对位置。或者,您可以将覆盖层设置为窗口的子级,避免需要绝对位置。 - ta.speot.is
也许你可以用宏来实现。 - Kuzgun
1个回答

0
你可以使用Win32的ClientToScreen函数。
声明以下外部函数:
[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);

您可以按照以下方式调用此函数:
POINT pt = new POINT();
pt.x = left;
pt.y = top;
ClientToScreen(myForm.Handle, ref pt);

接下来,pt应该包含pt的绝对坐标。使用ScreenToClient进行相反的操作。使用这两个函数,您还可以获取一个点相对于另一个窗口的位置(前提是您知道两个窗口的句柄)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接