fork download
  1. // Created by David W.M. Sattler 2014
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Diagnostics;
  8. using System.ComponentModel;
  9. using System.Windows.Forms;
  10. using System.IO;
  11. using System.Drawing;
  12. using System.Runtime.InteropServices;
  13.  
  14. namespace MDC.TaskBar_Misc
  15. {
  16. public class ProgramWatcher
  17. {
  18. [DllImport("user32.dll")]
  19. private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);
  20.  
  21. static BackgroundWorker bg = new BackgroundWorker();
  22. public static List<string> openProcesses = new List<string>();
  23. static List<int> openId = new List<int>();
  24.  
  25. public static bool isRunning(string progName, bool isId, int id)
  26. {
  27. foreach (Process pro in Process.GetProcesses("."))
  28. {
  29. if (pro.MainWindowTitle == "")
  30. continue;
  31.  
  32. if (isId)
  33. {
  34. if (pro.Id == id)
  35. return true;
  36. }
  37. else
  38. {
  39. if (pro.ProcessName == progName)
  40. return true;
  41. }
  42. }
  43.  
  44. foreach (Process pro in Process.GetProcessesByName(progName))
  45. if (pro.MainWindowHandle != (IntPtr)0)
  46. return true;
  47.  
  48. return false;
  49. }
  50.  
  51. public static void StartProgram(string path)
  52. {
  53. foreach (Process pro in Process.GetProcesses("."))
  54. {
  55. if (pro.MainWindowTitle != "")
  56. {
  57. if (pro.ProcessName == Path.GetFileNameWithoutExtension(path))
  58. {
  59. SetWindowPos(pro.MainWindowHandle, (IntPtr)0, 0, 0, 0, 0, (short)0x2 | (short)1 | (int)0x0040);
  60. return;
  61. }
  62. }
  63. }
  64.  
  65. Process p = Process.Start(path);
  66.  
  67. try
  68. {
  69. if (p.ProcessName != null)
  70. if (!openProcesses.Contains(p.ProcessName))
  71. {
  72. openProcesses.Add(p.ProcessName);
  73. openId.Add(p.Id);
  74. }
  75. }
  76. catch { }
  77. }
  78.  
  79. public static void InitProgramWatch()
  80. {
  81. bg.DoWork += new DoWorkEventHandler(bg_DoWork);
  82. bg.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bg_RunWorkerCompleted);
  83. bg.RunWorkerAsync();
  84. }
  85.  
  86. private static void bg_DoWork(object sender, DoWorkEventArgs e)
  87. {
  88. for (int i = 0; i < 5; i++)
  89. {
  90. System.Threading.Thread.Sleep(100);
  91. }
  92.  
  93. if (Application.OpenForms["MDC_TaskBar"] == null)
  94. return;
  95.  
  96. foreach (Panel p in Application.OpenForms["MDC_TaskBar"].Controls.OfType<Panel>())
  97. {
  98. foreach (Panel w in p.Controls.OfType<Panel>())
  99. {
  100. Application.OpenForms["MDC_TaskBar"].Invoke(new MethodInvoker(() =>
  101. {
  102. try
  103. {
  104. openApps.dynamicTT.SetToolTip(w, Process.GetProcessById(int.Parse(w.Name)).MainWindowTitle);
  105. }
  106. catch { }
  107. }));
  108. }
  109. }
  110.  
  111. List<string> remove = new List<string>();
  112. List<int> imove = new List<int>();
  113. bool showMMP = false;
  114.  
  115. foreach (Process proc in Process.GetProcesses("."))
  116. if (proc.MainWindowTitle != "" && !excluded.Contains(proc.ProcessName))
  117. {
  118. if (proc.MainWindowTitle.Contains("Metro Media Player"))
  119. showMMP = true;
  120. if (!openId.Contains(proc.Id))
  121. {
  122. openApps.AddApp(proc);
  123. openProcesses.Add(proc.ProcessName);
  124. openId.Add(proc.Id);
  125. }
  126. else
  127. openApps.AddWindow(proc);
  128. }
  129.  
  130. MMP_Controller.ShowHide(showMMP);
  131.  
  132. for (int i = 0; i < openProcesses.Count; i++)
  133. {
  134. if (!isRunning(openProcesses[i], false, -1))
  135. {
  136. foreach (Panel p in Application.OpenForms["MDC_TaskBar"].Controls.OfType<Panel>())
  137. {
  138. if (p.Name == "MMP_Next" || p.Name == "MMP_Previos" || p.Name == "MMP_PausePlay")
  139. continue;
  140. if (p.Name != openProcesses[i])
  141. continue;
  142. else
  143. {
  144. Application.OpenForms["MDC_TaskBar"].Invoke(new MethodInvoker(() => { p.Dispose(); }));
  145. remove.Add(openProcesses[i]);
  146. imove.Add(openId[i]);
  147. openApps.Reposition();
  148. }
  149. }
  150. }
  151. else if (!isRunning(openProcesses[i], true, openId[i]))
  152. {
  153. openApps.RemoveWindow(openProcesses[i]);
  154. remove.Add(openProcesses[i]);
  155. imove.Add(openId[i]);
  156. }
  157. }
  158.  
  159. foreach (string p in remove)
  160. openProcesses.Remove(p);
  161. foreach (int i in imove)
  162. openId.Remove(i);
  163. }
  164.  
  165. static string[] excluded = new string[] { "explorer" };
  166.  
  167. private static void bg_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
  168. {
  169. bg.RunWorkerAsync();
  170. }
  171. }
  172. }
  173.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cs(6,24): error CS0234: The type or namespace name `Tasks' does not exist in the namespace `System.Threading'. Are you missing an assembly reference?
prog.cs(9,14): error CS0234: The type or namespace name `Windows' does not exist in the namespace `System'. Are you missing an assembly reference?
Compilation failed: 2 error(s), 0 warnings
stdout
Standard output is empty