- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
[DllImport("Kernel32.dll", CharSet = CharSet.Auto)]
public static extern bool GetVolumeInformation(
string lpRootPathName, // 欲获取信息的那个卷的根路径
string lpVolumeNameBuffer, // 用于装载卷名(卷标)的一个字串
int nVolumeNameSize, // lpVolumeNameBuffer字串的长度
ref int lpVolumeSerialNumber, // 用于装载磁盘卷序列号的变量
/*指定一个变量,用于装载文件名每一部分的长度。例如,
* 在“c:\component1\component2.ext”的情况下,
* 它就代表component1或component2名称的长度 .
*/
int lpMaximumComponentLength,
int lpFileSystemFlags,
/* 用于装载一个或多个二进制位标志的变量。对这些标志位的解释如下:
*
* FS_CASE_IS_PRESERVED 文件名的大小写记录于文件系统
* FS_CASE_SENSITIVE 文件名要区分大小写
* FS_UNICODE_STORED_ON_DISK 文件名保存为Unicode格式
* FS_PERSISTANT_ACLS 文件系统支持文件的访问控制列表(ACL)安全机制
* FS_FILE_COMPRESSION 文件系统支持逐文件的进行文件压缩
* FS_VOL_IS_COMPRESSED 整个磁盘卷都是压缩的
*/
string lpFileSystemNameBuffer, //指定一个缓冲区,用于装载文件系统的名称(如FAT,NTFS以及其他)
int nFileSystemNameSize //lpFileSystemNameBuffer字串的长度
);
[DllImport("user32.dll", EntryPoint = "GetForegroundWindow")]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll", EntryPoint = "GetActiveWindow")]
public static extern IntPtr GetActiveWindow();
[DllImport("user32.dll", EntryPoint = "GetWindowRect")]
public static extern int GetWindowRect(IntPtr hwnd, ref Rectangle lpRect);
[DllImport("user32.dll", EntryPoint = "FindWindow", CharSet = CharSet.Auto)]
public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", EntryPoint = "GetCursorPos")]
public static extern bool GetCursorPos(out Point pt);
[DllImport("user32.dll", EntryPoint = "WindowFromPoint")]
public static extern IntPtr WindowFromPoint(Point pt);
[DllImport("user32.dll", EntryPoint = "FindWindowEx")]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);
[DllImport("user32.dll", EntryPoint = "GetParent")]
public static extern IntPtr GetParent(IntPtr hWnd);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Winapi)]
public static extern IntPtr GetTopWindow(IntPtr hndw);
public static Point GetDrawingRectang()
{
var hndw = GetActiveWindow();
//var wc = GetChildHandles(hndw, null);
var hnd = GetTopChildWindows();
var rect = new Rectangle();
GetWindowRect(hnd, ref rect);
return rect.Location;
}
public static IntPtr GetTopChildWindows()
{
var hnd =GetTopWindow (GetActiveWindow()) ;
return hnd;
}
/// <summary>
/// 找到句柄
/// </summary>
/// <param name="ipClassName">类名</param>
/// <returns></returns>
public static IntPtr GetHandle(string ipClassName)
{
return FindWindow(ipClassName, null);
}
/// <summary>
/// 子窗口句柄
/// </summary>
/// <param name="hwndParent">父窗口句柄</param>
/// <param name="hwndChildAfter">前一个同目录级同名窗口句柄</param>
/// <param name="lpszClass">类名</param>
/// <returns></returns>
public static IntPtr GetChildHandle(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass)
{
return FindWindowEx(hwndParent, hwndChildAfter, lpszClass, null);
}
/// <summary>
/// 全部子窗口句柄
/// </summary>
/// <param name="hwndParent">父窗口句柄</param>
/// <param name="className">类名</param>
/// <returns></returns>
public static List<IntPtr> GetChildHandles(IntPtr hwndParent, string className)
{
var resultList = new List<IntPtr>();
for (IntPtr hwndClient = GetChildHandle(hwndParent, IntPtr.Zero, className); hwndClient != IntPtr.Zero; hwndClient = GetChildHandle(hwndParent, hwndClient, className))
{
resultList.Add(hwndClient);
}
return resultList;
}
/// <summary>
/// 找类名
/// </summary>
/// <param name="hWnd">句柄</param>
/// <returns></returns>
public static string GetClassName(IntPtr hWnd)
{
var lpClassName = new StringBuilder(128);
if (GetClassName(hWnd, lpClassName, lpClassName.Capacity) == 0)
{
throw new Exception("not found IntPtr!");
}
return lpClassName.ToString();
}
/// <summary>
/// 获取鼠标的屏幕坐标
/// </summary>
/// <returns></returns>
public static Point GetCursorPosPoint()
{
var p = new Point();
if (GetCursorPos( out p))
{
return p;
}
return default (Point);
}
/// 找到句柄
/// <summary>
/// 获取鼠标所在窗口的句柄
/// </summary>
public static IntPtr GetWindowHandle(Point p)
{
return WindowFromPoint(p);
}
/// <summary>
/// 获取有名字窗体句柄
/// </summary>
/// <param name="caption">窗体名</param>
/// <param name="delay">循环查询次数</param>
/// <param name="maxTries">停顿时间</param>
/// <returns>句柄 IntPtr</returns>
static IntPtr FindMainWindowHandle(String caption, int delay, int maxTries)
{
IntPtr mwh = IntPtr.Zero;
bool foundWindow = false;
int attempts = 0;
do
{
mwh = FindWindow(null, caption);
if (mwh == IntPtr.Zero)
{
//Console.WriteLine("Form not yet found\n");
Thread.Sleep(maxTries);
++attempts;
}
else
{
//Console.WriteLine("Form has been found");
foundWindow = true;
}
}
while (!foundWindow && attempts < delay);
if (mwh != IntPtr.Zero)
return mwh;
else
throw new Exception("Coule not find Main Window");
}
|
|