C#中已经获取了父窗口句柄如何枚举到子窗口的句柄。 15
publicdelegateboolCallBack(inthwnd,intlParam);publicdelegateboolEnumWindowsProc(inthW...
public delegate bool CallBack(int hwnd, int lParam);
public delegate bool EnumWindowsProc(int hWnd, int lParam);
[DllImport("User32.dll", EntryPoint = "FindWindow", SetLastError = false)]
public static extern int FindWindow(string lpClassName, string lpWindowName);
//[DllImport("user32.dll")]
//[return: MarshalAs(UnmanagedType.Bool)]
//public static extern bool Enumchildwindows(IntPtr hwndParent, EnumWindowsProc lpEnumFunc, IntPtr lParam);
[DllImport("user32.dll")]
public static extern int GetWindowText(int hWnd, StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")]
public static extern int EnumThreadWindows(int dwThreadId, CallBack lpfn, int lParam);
[DllImport("user32.dll")]
public static extern int EnumWindows(CallBack lpfn, int lParam);
[DllImport("user32.dll")]
public static extern int EnumChildWindows(int hWndParent, CallBack lpfn, int lParam);
在网上找到这些之后就不知道怎么写了,真心的求C#的Demo 麻烦大神多给些注释 特别是参数。。。鸟语不好。只知道用EnumChildWindows 求个示范。。。。 展开
public delegate bool EnumWindowsProc(int hWnd, int lParam);
[DllImport("User32.dll", EntryPoint = "FindWindow", SetLastError = false)]
public static extern int FindWindow(string lpClassName, string lpWindowName);
//[DllImport("user32.dll")]
//[return: MarshalAs(UnmanagedType.Bool)]
//public static extern bool Enumchildwindows(IntPtr hwndParent, EnumWindowsProc lpEnumFunc, IntPtr lParam);
[DllImport("user32.dll")]
public static extern int GetWindowText(int hWnd, StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")]
public static extern int EnumThreadWindows(int dwThreadId, CallBack lpfn, int lParam);
[DllImport("user32.dll")]
public static extern int EnumWindows(CallBack lpfn, int lParam);
[DllImport("user32.dll")]
public static extern int EnumChildWindows(int hWndParent, CallBack lpfn, int lParam);
在网上找到这些之后就不知道怎么写了,真心的求C#的Demo 麻烦大神多给些注释 特别是参数。。。鸟语不好。只知道用EnumChildWindows 求个示范。。。。 展开
1个回答
展开全部
List<string> list = new List<string>();
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool EnumChildWindows(IntPtr hwndParent, EnumWindowsProc lpEnumFunc, IntPtr lParam);
[DllImport("user32.dll")]
public static extern int GetWindowText(int hWnd, IntPtr lpString, int nMaxCount);
private void toolStripButton5_Click(object sender, EventArgs e)
{
list.Clear();
EnumChildWindows(this.Handle, this.EnumWindowsMethod, IntPtr.Zero);
//这里得到了所有的子窗口list.Count;
}
private bool EnumWindowsMethod(int hWnd, int lParam)
{
IntPtr lpString = Marshal.AllocHGlobal(200);
GetWindowText(hWnd, lpString, 200);
var text = Marshal.PtrToStringAnsi(lpString);
if (!string.IsNullOrWhiteSpace(text))
list.Add(text);
return true;
}
追问
谢谢啊,我先试试,有问题再追问你哈。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询