Guest User

Untitled

a guest
Oct 17th, 2012
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3. using System.Windows.Forms;
  4. using System.Runtime.InteropServices;
  5. using System.Diagnostics;
  6.  
  7. namespace BringToFront
  8. {
  9. public partial class Form1 : Form
  10. {
  11. [DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
  12. public static extern IntPtr FindWindow(String className, String windowName);
  13.  
  14. [DllImport("USER32.DLL")]
  15. public static extern bool SetForegroundWindow(IntPtr hWnd);
  16.  
  17. public Form1()
  18. {
  19. InitializeComponent();
  20. }
  21.  
  22. private void button1_Click(object sender, EventArgs e)
  23. {
  24. try
  25. {
  26. bringToFront(comboBox1.SelectedItem.ToString());
  27. }
  28. catch
  29. {
  30. MessageBox.Show("Please choose a Process Name");
  31. }
  32. }
  33.  
  34. public static void bringToFront(string title)
  35. {
  36. IntPtr handle = FindWindow(null, title);
  37. if (handle == IntPtr.Zero)
  38. {
  39. return;
  40. }
  41. SetForegroundWindow(handle);
  42. }
  43.  
  44. private void timer1_Tick(object sender, EventArgs e)
  45. {
  46. if (checkBox1.Checked)
  47. {
  48. bringToFront(comboBox1.SelectedItem.ToString());
  49. }
  50. }
  51.  
  52. private void comboBox1_Click(object sender, EventArgs e)
  53. {
  54. comboBox1.Items.Clear();
  55. Process[] process = Process.GetProcesses();
  56. foreach (Process processes in process)
  57. {
  58. if (!String.IsNullOrEmpty(processes.MainWindowTitle))
  59. comboBox1.Items.Add(processes.ProcessName);
  60. }
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment