Net/WFP窗体枚举类
2020-12-13 02:06
标签:style c class blog code java Net/WFP窗体枚举类,搜素材,soscw.com Net/WFP窗体枚举类 标签:style c class blog code java 原文地址:http://www.cnblogs.com/andy1987/p/3756760.htmlusing System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows;
using System.Xml;
// author: andy , 20140521
// WPF下窗体枚举
namespace DrawCanvas {
public class XmalWinEnumHelper {
private delegate bool EnumChildDelegateProc(IntPtr hWnd, IntPtr lParam);
public struct POINT
{
public int X;
public int Y;
public POINT(int x, int y)
{
this.X = x;
this.Y = y;
}
}
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool EnumChildWindows(IntPtr hwndParent, XmalWinEnumHelper.EnumChildDelegateProc lpEnumFunc, IntPtr lParam);
[DllImport("user32.dll")]
private static extern bool ScreenToClient(IntPtr hWnd, ref XmalWinEnumHelper.POINT lpPoint);
[DllImport("user32.dll")]
private static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool IsWindowVisible(IntPtr hWnd);
//=> FUNCITON
public static Listint> GetChildWindows(IntPtr hWndParent) {
Listint> list = new Listint>();
GCHandle value = GCHandle.Alloc(list);
XmalWinEnumHelper.EnumChildDelegateProc lpEnumFunc = new XmalWinEnumHelper.EnumChildDelegateProc(XmalWinEnumHelper.DoEnumChildWindowsProc);
XmalWinEnumHelper.EnumChildWindows(hWndParent, lpEnumFunc, GCHandle.ToIntPtr(value));
value.Free();
list.Sort();
return list;
}
private static bool DoEnumChildWindowsProc(IntPtr hWnd, IntPtr lParam) {
Listint> list = GCHandle.FromIntPtr(lParam).Target as Listint>;
if (list != null && XmalWinEnumHelper.IsWindowVisible(hWnd)) {
list.Add(hWnd.ToInt32());
}
return true;
}
public static bool ConvertPointFromScreenToClient(IntPtr hWnd, ref System.Windows.Point pt) {
if (hWnd.ToInt32() == 0) {
return false;
}
XmalWinEnumHelper.POINT pOINT = new XmalWinEnumHelper.POINT((int)pt.X, (int)pt.Y);
bool flag = XmalWinEnumHelper.ScreenToClient(hWnd, ref pOINT);
if (flag) {
pt.X = (double)pOINT.X / 1.0;
pt.Y = (double)pOINT.Y / 1.0;
}
return flag;
}
public static string GetWindowTitle(IntPtr hWnd) {
StringBuilder stringBuilder = new StringBuilder(512);
XmalWinEnumHelper.GetWindowText(hWnd, stringBuilder, 512);
return stringBuilder.ToString();
}
}
}
下一篇:C语言文件操作