12 using System.Collections.Generic;
13 using System.ComponentModel;
18 using System.Windows.Forms;
19 using System.Runtime.InteropServices;
28 [DllImport(
"user32.dll")]
29 static extern bool SetForegroundWindow(IntPtr hWnd);
31 static readonly IntPtr HWND_TOPMOST =
new IntPtr(-1);
32 static readonly IntPtr HWND_NOTOPMOST =
new IntPtr(-2);
33 static readonly IntPtr HWND_TOP =
new IntPtr(0);
34 static readonly IntPtr HWND_BOTTOM =
new IntPtr(1);
35 const UInt32 SWP_NOSIZE = 0x0001;
36 const UInt32 SWP_NOMOVE = 0x0002;
37 const UInt32 TOPMOST_FLAGS = SWP_NOMOVE | SWP_NOSIZE;
39 [DllImport(
"user32.dll")]
40 [
return: MarshalAs(UnmanagedType.Bool)]
41 public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter,
int X,
int Y,
int cx,
int cy, uint uFlags);
45 Process[] p = Process.GetProcessesByName(processName);
49 SetForegroundWindow(p[0].MainWindowHandle);
53 private DateTime currentTime = DateTime.Now;
54 private delegate
void FormDlgt();
58 StartPosition = FormStartPosition.CenterScreen;
59 InitializeComponent();
61 label_FileName.Text =
"File Name: " + fileName;
62 label_ProcessName.Text =
"Process Name: " +
processName;
63 label_UserName.Text =
"User Name: " +
userName;
65 System.Timers.Timer closeFormTimer =
new System.Timers.Timer();
66 closeFormTimer.Interval = 100;
67 closeFormTimer.Start();
68 closeFormTimer.Enabled =
true;
69 closeFormTimer.Elapsed +=
new System.Timers.ElapsedEventHandler(CloseFormTimer_Elapsed);
71 Process p = Process.GetCurrentProcess();
79 private void UserPasswordForm_Load(
object sender, EventArgs e)
82 SetForegroundWindow(this.Handle);
85 private void button_Ok_Click(
object sender, EventArgs e)
87 userPassword = textBox_Password.Text;
91 private void CloseFormTimer_Elapsed(
object sender,
System.Timers.ElapsedEventArgs e)
103 private void ShowForm()
105 if (this.InvokeRequired)
107 this.Invoke(
new FormDlgt(ShowForm),
new Object[] { });
112 this.WindowState = FormWindowState.Normal;
124 private void ClosePasswordForm()
126 if (this.InvokeRequired)
128 this.Invoke(
new FormDlgt(ClosePasswordForm),
new Object[] {});
136 private void button_Cancel_Click(
object sender, EventArgs e)
static uint ConnectionTimeOut