c# 中调用windows api函数
//原函数定义
BOOL WINAPI EnumChildWindows(
_In_opt_ HWND hWndParent,
_In_ WNDENUMPROC lpEnumFunc,
_In_ LPARAM lParam
);
//C#定义
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Unicode, CallingConvention = CallingConvention.StdCall)]
//BOOL WINAPI EnumChildWindows( _In_opt_ HWND hWndParent, _In_ WNDENUMPROC lpEnumFunc, _In_ LPARAM lParam);
public static extern int EnumChildWindows(IntPtr hWndParent, EnumWindowsCallBack lpfn, int lParam);
//HWND WINAPI GetParent( _In_ HWND hWnd);
public extern static IntPtr GetParent(IntPtr hWnd);
一开始认为该函数只返回第一级child节点。处理函数如下:
//c#调用
public void ReadAllWnd()
{
foreach (WindowBase item in WindowsOpt.Instance.Windows)