using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
namespace FormWindow.Cs
{
public class FormWindow
{
public FormWindow FormWindow = new FormWindow();
[DllImport("user32.dll", EntryPoint = "FindWindowA")]
private static extern int FindWindowA(string a, string b);
public int 标题取窗口句柄(string Text)
{
string[] a = new string[2];
a[1] = Text;
return FindWindowA(a[0], a[1]);
}
public int 类名取窗口句柄(string ClassName)
{
string[] a = new string[2];
a[0] = ClassName;
return FindWindowA(a[0], a[1]);
}
[DllImport("user32.dll", EntryPoint = "IsWindow")]
private static extern int IsWindow(int Hwnd);
public bool 句柄是否有效(int Hwnd)
{
if (IsWindow(Hwnd) > 0)
{
return true;
}
else
{
return false;
}
}
[DllImport("user32.dll", EntryPoint = "FlashWindow")]
private static extern int FlashWindow(int HWnd, bool IsTrue);
public void 闪烁窗口(int 窗口句柄)
{
FlashWindow(窗口句柄, true);
}
[DllImport("user32.dll", EntryPoint = "GetActiveWindow")]
private static extern int GetActiveWindow();
public int 取活动窗口句柄()
{
return GetActiveWindow();
}
[DllImport("user32.dll", EntryPoint = "WindowFromPoint")]
private static extern int WindowFromPoint(int x, int y);
public int 坐标取窗口句柄(int x, int y)
{
return WindowFromPoint(x, y);
}
[DllImport("user32.dll", EntryPoint = "AnimateWindow")]
private static extern int AnimateWindow(int hwnd, int dwTime, int dwFlags);
public int 动画窗口(int 窗口句柄, int 持续时间, int 显示方式)
{
return AnimateWindow(窗口句柄, 持续时间, 显示方式);
}
[DllImport("user32.dll", EntryPoint = "MessageBoxA")]
private static extern int MessageBoxA(int Hwnd, string Tip, string Text, int val);
public int 信息框
(int 窗口句柄, string 提示信息, string 信息框标题, int 按钮值)
{
return MessageBoxA(窗口句柄, 提示信息, 信息框标题, 按钮值);
}
[DllImport("user32.dll", EntryPoint = "GetDesktopWindow")]
private static extern int GetDesktopWindow();
public static extern int 取屏幕句柄()
{
return GetDesktopWindow();
}
[DllImport("user32.dll", EntryPoint = "IsZoomed")]
private static extern int IsZoomed(int Hwnd);
public bool 窗口是否最大化(int Hwnd)
{
if (IsZoomed(Hwnd) != 0)
{
return true;
}
else
{
return false;
}
}
[DllImport("user32.dll", EntryPoint = "GetWindowTextA")]
private static extern int GetWindowTextA(int Hwnd, string cch, int lp);
public string 取窗口标题(int Hwnd)
{
string a = "";
GetWindowTextA(Hwnd, a, 255);
return a;
}
}
}
C# FormWindow Class 公开调用方法