zoukankan      html  css  js  c++  java
  • C# GetWindowRect用法

    函数功能:该函数返回指定窗口的边框矩形的尺寸。该尺寸以相对于屏幕坐标左上角的屏幕坐标给出。

    函数原型:BOOL GetWindowRect(HWND hWnd,LPRECTlpRect);

    参数:

    hWnd:窗口句柄。

    lpRect:指向一个RECT结构的指针,该结构接收窗口的左上角和右下角的屏幕坐标。

    返回值:如果函数成功,返回值为非零:如果函数失败,返回值为零。若想获得更多错误信息,请调用GetLastError函数。

    C#中使用该函数首先导入命名空间:

    using System.Runtime.InteropServices;

    然后写API引用部分的代码,放入 class 内部

    [DllImport("user32.dll")]
    private static extern int GetWindowRect(IntPtr hwnd,out  Rect lpRect);

    这个函数有两个个参数,第一个参数是指定窗口句柄;第二个参数接收窗口的左上角和右下角的屏幕坐标,它是Rect结构。Rect结构定义如下:

    public struct Rect
    {
        public int Left;
        public int Top;
        public int Right;
        public int Bottom;
    }
    
    演示代码:
    IntPtr hwnd = FindWindow("", "计算器");   
    Rect rect = new Rect();   
    GetWindowRect(hwnd, out lpRect); 

    转载自:http://blog.csdn.net/dangdaa/article/details/7001810

  • 相关阅读:
    JZ5 替换空格
    数学分析 H 1 复习要点(部分)
    算法贪心
    Python之位运算
    sorted复杂排序cmp_to_key
    算法位运算
    Python3新特性总结 持续更新
    算法树
    H5 ios端微信浏览器下底部工具固定方法
    Eclipse 安装windows10环境
  • 原文地址:https://www.cnblogs.com/hongfei/p/2824866.html
Copyright © 2011-2022 走看看