c# 中如何根据进程名获得指定的窗体在屏幕中Location

如何根据进程名获得指定的窗体在屏幕中Location?注:不是本窗体的位置,是某个进程中的某个窗体的位置。比如打开一个notepad获取它的Point?... 如何根据进程名获得指定的窗体在屏幕中Location?注:不是本窗体的位置,是某个进程中的 某个窗体的位置。比如 打开一个notepad 获取它的Point ? 展开
 我来答
dragon2snow
2009-09-10 · TA获得超过1099个赞
知道小有建树答主
回答量:1150
采纳率:0%
帮助的人:1135万
展开全部
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Runtime.InteropServices;
using WINDOWINFO = WindowsFormsApplication1.tagWINDOWINFO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("user32.dll", SetLastError = true)]
static extern bool GetWindowInfo(IntPtr hwnd, ref WINDOWINFO pwi);

private void button1_Click(object sender, EventArgs e)
{
Process [] ps = Process.GetProcessesByName("Config");
foreach (var p in ps)
{
IntPtr handle = p.MainWindowHandle;
WINDOWINFO info = new WINDOWINFO();
info.cbSize = (uint)Marshal.SizeOf(info);
GetWindowInfo(handle, ref info);
MessageBox.Show(info.rcWindow.top.ToString() + ":" +
info.rcWindow.left.ToString());
}

}
}

[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct tagWINDOWINFO
{
/// DWORD->unsigned int
public uint cbSize;

/// RECT->tagRECT
public tagRECT rcWindow;

/// RECT->tagRECT
public tagRECT rcClient;

/// DWORD->unsigned int
public uint dwStyle;

/// DWORD->unsigned int
public uint dwExStyle;

/// DWORD->unsigned int
public uint dwWindowStatus;

/// UINT->unsigned int
public uint cxWindowBorders;

/// UINT->unsigned int
public uint cyWindowBorders;

/// ATOM->WORD->unsigned short
public ushort atomWindowType;

/// WORD->unsigned short
public ushort wCreatorVersion;
}

[System.Runtime.InteropServices.StructLayoutAttribute(System.Runtime.InteropServices.LayoutKind.Sequential)]
public struct tagRECT
{

/// LONG->int
public int left;

/// LONG->int
public int top;

/// LONG->int
public int right;

/// LONG->int
public int bottom;
}
}

MessageBox显示的就是location ,我输出的可能X,Y反了,但都一样
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式