private void btn_Execute_Click(object sender, EventArgs e) { if (dgv_Actions.SelectedRows.Count <= 0) { MessageBox.Show("No action is selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (dgv_LastApplications.SelectedRows.Count <= 0) { MessageBox.Show("No application is selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } selectedPasteAction = dgv_Actions.SelectedRows[0].DataBoundItem as PasteAction; Classes.Application selectedApplication = dgv_LastApplications.SelectedRows[0].DataBoundItem as Classes.Application; if (selectedApplication.WindowHandle == IntPtr.Zero) { MessageBox.Show("There is something wrong with the selected application", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } selectedPasteAction.Paste(selectedApplication.WindowHandle, selectedApplication.LastActiveWindowMode); }
private void timer_ActiveWindow_Tick(object sender, EventArgs e) { IntPtr handle = WindowsHelper.GetForegroundWindow(); // Get the process ID of the current active windows handle if (handle == null) { return; } // Return if no handle is found if (handle == Global.ThisWindowsHandle) { return; } // Return if the handle is the paster application handle if (handle == Global.LastActiveWindowHandle) { return; } // Return if the handle is the same as the last handle Global.LastActiveWindowHandle = handle; // Set the last active windows handle // Check if the application already exists Classes.Application existingApplication = null; foreach (Classes.Application appl in Global.LastApplications) { if (appl.WindowHandle == handle) { existingApplication = appl; } } // Re-order if applicable if (existingApplication != null) { Global.LastApplications.Remove(existingApplication); Global.LastApplications.Insert(0, existingApplication); return; } // Return if the application title is one of the paster application titles string title = WindowsHelper.GetWindowLabel(handle); if (Global.ExcludedTitles.Contains(title)) { return; } if (string.IsNullOrEmpty(title)) { return; } // Return if the title is empty // Add the new application Classes.Application app = new Classes.Application(); app.WindowHandle = handle; app.WindowTitle = WindowsHelper.GetWindowLabel(app.WindowHandle); app.WindowIcon = WindowsHelper.GetAppIcon(handle); // Remove the last application if it is 5 or more applications in the list if (Global.LastApplications.Count >= 5) { Global.LastApplications.RemoveAt(Global.LastApplications.Count - 1); } Global.LastApplications.Insert(0, app); }