免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開APP
userphoto
未登錄

開通VIP,暢享免費電子書等14項超值服

開通VIP
C# 圖像處理: 獲取當前活動窗口句柄,獲取窗口大小及位置

需調(diào)用API函數(shù)

需在開頭引入命名空間 using System.Runtime.InteropServices;

獲取當前窗口句柄:GetForegroundWindow()

[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]

public static extern IntPtr GetForegroundWindow();

返回值類型是IntPtr,即為當前獲得焦點窗口的句柄

使用方法 : IntPtr myPtr=GetForegroundWindow();

獲取到該窗口句柄后,可以對該窗口進行操作.比如,關閉該窗口或在該窗口隱藏后,使其顯示

[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]

public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);

其中ShowWindow(IntPtr hwnd, int nCmdShow);

nCmdShow的含義

0 關閉窗口

1 正常大小顯示窗口

2 最小化窗口

3 最大化窗口

使用實例: ShowWindow(myPtr, 0);

獲取窗口大小及位置:

需要調(diào)用方法GetWindowRect(IntPtr hWnd, ref RECT lpRect)

[DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Bool)]

static extern bool GetWindowRect(IntPtr hWnd, ref RECT lpRect);

[StructLayout(LayoutKind.Sequential)]

public struct RECT {

public int Left; //最左坐標

public int Top; //最上坐標

public int Right; //最右坐標

public int Bottom; //最下坐標 }

示例:

InPtr awin = GetForegroundWindow(); //獲取當前窗口句柄

RECT rect = new RECT();

GetWindowRect(awin, ref rect);

int width = rc.Right - rc.Left; //窗口的寬度

int height = rc.Bottom - rc.Top; //窗口的高度

int x = rc.Left;

int y = rc.Top;

本站僅提供存儲服務,所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權內(nèi)容,請點擊舉報。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
C#+API實現(xiàn)指定窗體激活
在Winform中嵌入exe程序
從C#程序中調(diào)用非受管DLLs
C#啟動一個外部程序(2)
C# GetWindowThreadProcessId用法 .
獲取窗體句柄并操縱它
更多類似文章 >>
生活服務
分享 收藏 導長圖 關注 下載文章
綁定賬號成功
后續(xù)可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點擊這里聯(lián)系客服!

聯(lián)系客服