C#任务栏任务上下文菜单访问

时间:2018-08-02 16:46:26

标签: c# rest process taskbar

我试图使用C#应用程序启动可执行文件,然后访问其上下文菜单。它将在“通知”区域中任务栏的右下角打开。如果右键单击它,将显示两个选项:“设置”和“退出”。如何以编程方式访问该菜单系统? enter image description here

我知道它有两个可用的REST命令。那些是“ Hide”和“ ShowComp”,但我不知道如何在C#中访问这些命令。在VB中是 REST.WebRequest(“ http://localhost:8099/Hide”)和REST.WebRequest(“ http://localhost:8099/ShowComp”)。 任何帮助将不胜感激。 下面是我尝试过的当前代码。

public Form1()
{
  InitializeComponent();
}

[DllImport("User32.dll")]
static extern bool ShowWindow(IntPtr hWnd, uint nCmdShow);

[DllImport("User32.dll")]
private static extern bool SetForegroundWindow(IntPtr hWnd);

private void ListTask()
{
   Process[] processes = Process.GetProcesses();

   foreach (Process process in processes)
   {
      if(process.ProcessName == "GO.Automation")
      listBox1.Items.Add(process.ProcessName + " " + process.Id.ToString());
   }
}

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{           
  Process p = new Process();
  string name = listBox1.SelectedItem.ToString();
  string IDs = name.Substring(name.IndexOf(" "), name.Length - name.IndexOf(" "));
   Int32 ID = Convert.ToInt32(IDs);
   p = Process.GetProcessById(ID);
   const uint SWP_SHOWWINDOW = 1;
   ShowWindow(p.MainWindowHandle, SWP_SHOWWINDOW);
   SetForegroundWindow(p.MainWindowHandle);
 }

 private void Form1_Load(object sender, EventArgs e)
 {
   ListTask();
 }

 Process proc = new Process();

 private void Start_Click(object sender, EventArgs e)
 {
   //Process.Start("C:\\Users\\mmiller\\Desktop\\ESD Offset\\GO.Automation.exe");
   //Process proc = new Process();
   proc.StartInfo.FileName = "C:\\Users\\mmiller\\Desktop\\ESD Offset\\GO.Automation.exe";
   proc.Start();
 }

 private void Show_Click(object sender, EventArgs e)
 {            
   //proc.BeginOutputReadLine();
   ShowWindow(proc.MainWindowHandle, 3);           
 }

0 个答案:

没有答案