基本信息
源码名称:C# 遍历所有 窗体句柄 源码
源码大小:1.51KB
文件格式:.cs
开发语言:C#
更新时间:2013-09-16
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍


    #region 遍历窗体类
//    using System; 
//using System.Runtime.InteropServices; 
//using System.Text; 
//using System.Collections.Generic; 

public class CSharpAPIsDemo 
{ 
private delegate bool WNDENUMPROC(IntPtr hWnd, int lParam); 
[DllImport("user32.dll")] 
private static extern bool EnumWindows(WNDENUMPROC lpEnumFunc, int lParam); 
//[DllImport("user32.dll")] 
//private static extern IntPtr FindWindowW(string lpClassName, string lpWindowName); 
[DllImport("user32.dll")] 
private static extern int GetWindowTextW(IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)]StringBuilder lpString, int nMaxCount); 
[DllImport("user32.dll")] 
private static extern int GetClassNameW(IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)]StringBuilder lpString, int nMaxCount); 

public struct WindowInfo 
{ 
public IntPtr hWnd; 
public string szWindowName; 
public string szClassName; 
} 

public WindowInfo[] GetAllDesktopWindows() 
{ 
List<WindowInfo> wndList = new List<WindowInfo>(); 

//enum all desktop windows 
EnumWindows(delegate(IntPtr hWnd, int lParam) 
{ 
WindowInfo wnd = new WindowInfo(); 
StringBuilder sb = new StringBuilder(256); 
//get hwnd 
wnd.hWnd = hWnd; 
//get window name 
GetWindowTextW(hWnd, sb, sb.Capacity); 
wnd.szWindowName = sb.ToString(); 
//get window class 
GetClassNameW(hWnd, sb, sb.Capacity); 
wnd.szClassName = sb.ToString(); 
//add it into list 
if (wnd.szWindowName.IndexOf("QQ2013") != -1)
{
    WindowInfo aa = wnd;
}
wndList.Add(wnd); 
return true; 
}, 0); 

return wndList.ToArray(); 
} 
}

    #endregion