如何获取窗口的位置? [英] How to get window's position?

查看:152
本文介绍了如何获取窗口的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道获得process'es窗口位置的方式。我一直在寻找一个在互联网上,但没有结果。感谢:)

 过程[] =流程Process.GetProcessesByName(记事本);
过程洛尔=流程[0];IntPtr的P = lol.MainWindowHandle;


解决方案

试试这个:

 函数[DllImport(user32.dll中,字符集= CharSet.Auto)
公共静态外部的IntPtr FindWindow函数(字符串strClassName,串strWindowName);函数[DllImport(user32.dll中)]
公共静态的extern BOOL GetWindowRect(HWND的IntPtr,楼盘rect矩形);公共结构矩形{
   公众诠释左{搞定;组; }
   公众诠释顶级{获得;组; }
   公众诠释权{搞定;组; }
   公众诠释底{搞定;组; }
}流程[] =流程Process.GetProcessesByName(记事本);
过程洛尔=流程[0];
IntPtr的PTR = lol.MainWindowHandle;
矩形NotepadRect =新的矩形();
GetWindowRect(PTR,楼盘NotepadRect);

I'd like to know the way of getting process'es window position. I've been looking for that on the internet but with no results. Thanks :)

Process[] processes = Process.GetProcessesByName("notepad");
Process lol = processes[0];

IntPtr p = lol.MainWindowHandle;

解决方案

Try this:

[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr FindWindow(string strClassName, string strWindowName);

[DllImport("user32.dll")]
public static extern bool GetWindowRect(IntPtr hwnd, ref Rect rectangle);

public struct Rect {
   public int Left { get; set; }
   public int Top { get; set; }
   public int Right { get; set; }
   public int Bottom { get; set; }
}

Process[] processes = Process.GetProcessesByName("notepad");
Process lol = processes[0];
IntPtr ptr = lol.MainWindowHandle;
Rect NotepadRect = new Rect();
GetWindowRect(ptr, ref NotepadRect);

这篇关于如何获取窗口的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆