用api(GetWindowRect)获取窗体矩形的问题

laugh8 2009-12-30 02:22:36
代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace GetHWND
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//根据类名和窗体标题查找该窗体句柄
[DllImport("user32.dll", EntryPoint = "FindWindowEx")]
public static extern IntPtr FindWindowEx(
int hWnd1,
int hWnd2,
string lpsz1,
string lpsz2
);

// 获得窗口矩形
[DllImport("user32")]
public static extern int GetWindowRect(int hwnd, ref RECT lpRect);


// 获得客户区矩形
[DllImport("user32.dll")]
public static extern int GetClientRect(IntPtr hWnd, ref RECT lpRect);

// 矩形结构
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
int left;
int top;
int right;
int bottom;
}

private void Form1_Load(object sender, EventArgs e)
{
}

private void button1_Click(object sender, EventArgs e)
{
IntPtr i = FindWindowEx(0, 0, "#32770", "多多游戏-对对碰V2.24");
RECT rc=new RECT();
if (i.ToInt32() != 0)
{
GetWindowRect(i, ref rc);
messagebox.show( rc.left)==================>此处,无法用rc.点出任何属性.而用断点查看,发现rc中的确有值
}

}
}
}
分数不富裕,还请理解.
...全文
201 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
laugh8 2009-12-30
  • 打赏
  • 举报
回复
明白.试一下!谢谢啊.
liyoubaidu 2009-12-30
  • 打赏
  • 举报
回复
public int left;
laugh8 2009-12-30
  • 打赏
  • 举报
回复
再顶
laugh8 2009-12-30
  • 打赏
  • 举报
回复
别沉

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧