本文介绍了获取所有正在运行的窗口表单应用程序的进程ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个分配,其中有3个窗口窗体应用程序,并且所有应用程序都处于运行模式.屏幕上的第一个应用程序处于活动状态,其他两个应用程序被最小化.我在first(active)应用程序中有一个包含列表框的表单.此列表框包含其他两个应用程序的名称.
任务是:如果我双击列表框中的任何名称(表示第二个或第三个窗口表单应用程序的名称),则该特定的窗口表单应用程序应将其状态从最小化状态切换为活动状态.意味着窗口窗体应用程序现在应该出现在屏幕上.
我想为此,我需要其他两个(第二个和第三个窗口窗体应用程序)的进程ID.如果是这样,那我该怎么做.如果没有,请给我建议其他解决方案.
请帮助

I have an assignment in which I have 3 window form applications and all in running mode. First application is active on screen and other two are minimized. i have a form in first(active) application which contains a listbox. This listbox contains names of other two applications.
The task is : if I double click on any name(means name of second or third window form application) in the listbox, that particular window form application should switch its state from minimized state to active. Means that window form application should now appear on the screen.
i think for this I need to have process ids of the other two(second and third window form applications).if it is so then how do i do that. if not then please suggest me some other solution.
Please help

推荐答案

[DllImport("user32.dll")]
public static extern IntPtr FindWindow(String sClassName, String sAppName);
[DllImport("user32")]
private const int SW_SHOWNORMAL    = 1;
private const int SW_SHOWMINIMIZED = 2;
private const int SW_SHOWMAXIMIZED = 3;
private static extern int ShowWindow(int hwnd, int nCmdShow);
private void butMakeNotePadFullScreen_Click(object sender, EventArgs e)
    {
    IntPtr hWnd = FindWindow(null, "Untitled - Notepad");
    ShowWindow((int) hWnd, SW_SHOWMAXIMIZED);
    }


using System.Diagnostics;

Process[] processlist = Process.GetProcesses();

foreach(Process theprocess in processlist){
// u can access each process name // theprocess.ProcessName;
//process id// theprocess.Id;

//and an external window can maximized using

[DllImport("user32.dll")]
      private static extern bool IsIconic(IntPtr hWnd);
      [DllImport("user32.dll")]
      private static extern int ShowWindow(IntPtr hWnd, int nCmdShow);
      [DllImport("user32.dll")]
      private static extern int SetForegroundWindow (IntPtr hWnd);
      private const int SW_RESTORE = 9;
      private void ShowPID(int pId)///give your selected processid here
      {
          IntPtr hWnd = System.Diagnostics.Process.GetProcessById(pId).MainWindowHandle;
          if (!hWnd.Equals(IntPtr.Zero))
          {
              if (IsIconic(hWnd))
              {
                  ShowWindow(hWnd, SW_RESTORE);
              }
              SetForegroundWindow(hWnd);
          }
      }



这篇关于获取所有正在运行的窗口表单应用程序的进程ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-28 11:46
查看更多