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

  • 相关阅读:
    mysql的悲观锁与乐观锁的实现
    java中int和Integer的区别
    node 爬取图片并下载 到本地
    vue-cli3.0使用及配置(部分)
    vue模块组件
    新版公共弹出层
    四面八方拖拽
    js常用功能技巧函数
    localStorage和cookie的跨域解决方案
    前端面试要点
  • 原文地址:https://www.cnblogs.com/hongfei/p/2824866.html
Copyright © 2011-2022 走看看