[英]How to get the topLeft screen position of Visual studio 2008's editor window?
我想為vs2008創建一個插件,在vs2008的編輯器上顯示一個透明的表單/窗口。
在下面的代碼中,“aw.Left”和“aw.Top”是相對值,兩者都是1。
題:
你知道如何獲得編輯器部分的左/上屏幕位置嗎?
或者我可以將插入符號移動到頂部/左側字符位置,但是您知道如何獲得插入符號的屏幕位置嗎?
萬分謝意。
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;
您可以使用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
進行相反的操作。 使用這兩個,您還可以獲得一個點相對於另一個窗口的位置(假設您知道兩個窗口的窗口句柄)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.