110,538
社区成员
发帖
与我相关
我的任务
分享
public delegate bool EnumWindowsProcCallBack(int hwnd, int lParam);
[DllImport("user32.dll")]
private static extern int GetWindowText(int hWnd, StringBuilder title, int size);
[DllImport("user32.dll")]
private static extern bool IsWindowVisible(int hWnd);
[DllImport("user32.dll")]
public static extern int EnumWindows(EnumWindowsProcCallBack proc, int lParam);
[DllImport("user32.dll")]
public static extern int GetWindowThreadProcessId (int hwnd, ref int lpdwProcessId);
public void test()
{
EnumWindowsProcCallBack EnumWindowsProc = new EnumWindowsProcCallBack(myEnumWindowsProc);
EnumWindows(EnumWindowsProc, 0);
}
//call back function
public static bool myEnumWindowsProc(int hwnd, int lParam)
{ //下面这些可能有用的信息
int processId;
bool isVisible = IsWindowVisible(hWnd);
GetWindowThreadProcessId(hwnd, ref processId);//取进程ID
StringBuilder title = new StringBuilder(255);
GetWindowText(hWnd, title, 255);
//return false;//stop EnumWindows
return true;
}
Process[] processList = Process.GetProcessesByName("EXCEL");
IntPtr MainWindowIntPtr = processList[0].MainWindowHandle;
[DllImport("user32.dll",EntryPoint="FindWindowEx")]
private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);