private void SparTaskMenuKill(object sender, EventArgs e) { System.Windows.Forms.MenuItem item = (System.Windows.Forms.MenuItem)sender; System.Windows.Forms.Button b = (System.Windows.Forms.Button)item.Tag; ArrayList Item = (ArrayList)b.Tag; try { uint pid = 0; WinAPI.GetWindowThreadProcessId((IntPtr)Item[1], out pid); System.Diagnostics.Process proc = System.Diagnostics.Process.GetProcessById((int)pid); //Gets the process by ID. proc.Kill(); } catch { Console.Beep(); } }
private void SparTaskAddProgram_(object sender, EventArgs e) { System.Windows.Forms.ToolStripMenuItem item = (System.Windows.Forms.ToolStripMenuItem)sender; ArrayList Item = (ArrayList)item.Tag; try { Icon IEIcon = System.Drawing.Icon.ExtractAssociatedIcon(WinAPI.GetProcessPath((IntPtr)Item[1])); System.Windows.Forms.Button SparTaskButton = new System.Windows.Forms.Button(); SparTaskButtonTbl.Add(SparTaskButton); Image im = IEIcon.ToBitmap(); SparTaskButton.Name = "TaskBarButton." + (string)Item[0]; SparTaskButton.BackColor = System.Drawing.Color.FromArgb(50, 50, 50); SparTaskButton.Image = im; SparTaskButton.Tag = Item; uint pid = 0; WinAPI.GetWindowThreadProcessId((IntPtr)Item[1], out pid); System.Diagnostics.Process proc = System.Diagnostics.Process.GetProcessById((int)pid); proc.EnableRaisingEvents = true; proc.Exited += (sender2, event2) => this.SparTaskHookRemoveButton(sender2, event2, SparTaskButton); SparTaskButton.Location = new System.Drawing.Point(0, 0); SparTaskButton.Margin = new System.Windows.Forms.Padding(0); SparTaskButton.Size = new System.Drawing.Size(40, 40); SparTaskButton.TabIndex = 0; SparTaskButton.FlatStyle = FlatStyle.Flat; SparTaskButton.FlatAppearance.BorderSize = 0; System.Windows.Forms.ToolTip tt = new System.Windows.Forms.ToolTip(); tt.SetToolTip(SparTaskButton, (string)Item[0]); SparTaskButton.MouseUp += this.SparTaskSwitchTo; SparTaskButton.MouseDown += SparTaskBar_MouseDown; SparTaskBar.Controls.Add(SparTaskButton); } catch (Exception ex) { Console.WriteLine(ex.Message.ToString()); Console.WriteLine("Error in: " + ((string)Item[0])); } }
public static ArrayList GetActiveTasks() { ArrayList returned = new ArrayList(); ArrayList SparTaskAppsNames = new ArrayList(); ArrayList SparTaskAppshWnd = new ArrayList(); ArrayList SparTaskButtohProc = new ArrayList(); ArrayList SparTaskButtonInfoTbl = new ArrayList(); WinAPI.EnumDelegate filter = delegate(IntPtr hWnd, int lParam) { ArrayList ITEM = new ArrayList(); StringBuilder strbTitle = new StringBuilder(255); int nLength = WinAPI.GetWindowText(hWnd, strbTitle, strbTitle.Capacity + 1); string strTitle = strbTitle.ToString(); long Style = (long)WinAPI.GetWindowLong(hWnd, (-16)); long ExStyle = (long)WinAPI.GetWindowLong(hWnd, (-20)); if (WinAPI.IsWindowVisible(hWnd) && string.IsNullOrEmpty(strTitle) == false && (ExStyle & 0x00000080L) == 0) { ITEM.Add(strTitle); ITEM.Add(hWnd); uint pid = 0; WinAPI.GetWindowThreadProcessId(hWnd, out pid); System.Diagnostics.Process proc = System.Diagnostics.Process.GetProcessById((int)pid); ITEM.Add(proc); SparTaskButtohProc.Add(proc.ProcessName); SparTaskButtonInfoTbl.Add(ITEM); } return(true); }; returned.Add(SparTaskButtonInfoTbl); returned.Add(SparTaskButtohProc); if (WinAPI.EnumDesktopWindows(IntPtr.Zero, filter, IntPtr.Zero)) { } return(returned); }