欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Windows 操作进程 API

程序员文章站 2022-07-05 12:58:46
...
Windows 操作进程 API
/// <summary>
/// 查找某个窗口  
/// </summary>
/// <param name="lpClassName"></param>
/// <param name="lpWindowName"></param>
/// <returns></returns>
[DllImport("user32.dll", EntryPoint = "FindWindow")]
public extern static IntPtr FindWindow(string lpClassName, string lpWindowName);
/// <summary>
/// 显示某个窗口
/// </summary>
/// <param name="hwnd"></param>
/// <param name="nCmdShow"></param>
/// <returns></returns>
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true)]
public static extern int ShowWindow(IntPtr hwnd, int nCmdShow);
/// <summary>
/// 进程间传递数据
/// </summary>
/// <param name="hWnd"></param>
/// <param name="msg"></param>
/// <param name="wParam"></param>
/// <param name="lParam"></param>
/// <returns></returns>
[DllImport("User32.dll", EntryPoint = "SendMessage")]
public static extern int SendMessage(IntPtr hWnd, int msg, uint wParam, uint lParam);
/// <summary>
/// 进程间传递数据
/// </summary>
/// <param name="hWnd"></param>
/// <param name="msg"></param>
/// <param name="wParam"></param>
/// <param name="lParam"></param>
/// <returns></returns>
[DllImport("User32.dll", EntryPoint = "SendMessage")]
public static extern int SendMessage(IntPtr hWnd, int msg, int wParam, ref ProcessData lParam);
/// <summary>
/// 设置某个窗口置前
/// </summary>
/// <param name="hWnd"></param>
/// <returns></returns>
[DllImport("User32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);
例程
Process[] processes = Process.GetProcessesByName(exe);
if (processes.Length > 0)
{
    IntPtr ihand = Ge.FindWindow(null, "历史数据"); 210520");//HistoryDataView
    if (ihand != IntPtr.Zero)
    {
        Ge.ShowWindow(ihand, 1);//显示
        Ge.SetForegroundWindow(ihand);
    }
}

上一篇: 网络爬虫

下一篇: Windows创建进程