EaseFilter Demo Project
UserPasswordForm.cs
Go to the documentation of this file.
1 //
3 // (C) Copyright 2011 EaseFilter Technologies Inc.
4 // All Rights Reserved
5 //
6 // This software is part of a licensed software product and may
7 // only be used or copied in accordance with the terms of that license.
8 //
10 
11 using System;
12 using System.Collections.Generic;
13 using System.ComponentModel;
14 using System.Data;
15 using System.Drawing;
16 using System.Linq;
17 using System.Text;
18 using System.Windows.Forms;
19 using System.Runtime.InteropServices;
20 using System.Diagnostics;
21 
23 
24 namespace SecureAgent
25 {
26  public partial class UserPasswordForm : Form
27  {
28  [DllImport("user32.dll")]
29  static extern bool SetForegroundWindow(IntPtr hWnd);
30 
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;
38 
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);
42 
43  void ActivateApp(string processName)
44  {
45  Process[] p = Process.GetProcessesByName(processName);
46 
47  // Activate the first application we find with this name
48  if (p.Count() > 0)
49  SetForegroundWindow(p[0].MainWindowHandle);
50  }
51 
52  public string userPassword = string.Empty;
53  private DateTime currentTime = DateTime.Now;
54  private delegate void FormDlgt();
55 
56  public UserPasswordForm(string userName, string processName, string fileName)
57  {
58  StartPosition = FormStartPosition.CenterScreen;
59  InitializeComponent();
60 
61  label_FileName.Text = "File Name: " + fileName;
62  label_ProcessName.Text = "Process Name: " + processName;
63  label_UserName.Text = "User Name: " + userName;
64 
65  System.Timers.Timer closeFormTimer = new System.Timers.Timer();
66  closeFormTimer.Interval = 100; //millisecond
67  closeFormTimer.Start();
68  closeFormTimer.Enabled = true;
69  closeFormTimer.Elapsed += new System.Timers.ElapsedEventHandler(CloseFormTimer_Elapsed);
70 
71  Process p = Process.GetCurrentProcess();
72 
73  // Activate the first application we find with this name
74  //if (null != p)
75  // SetForegroundWindow(p.MainWindowHandle);
76  // SetForegroundWindow(this.Handle);
77  }
78 
79  private void UserPasswordForm_Load(object sender, EventArgs e)
80  {
81  // SetWindowPos(this.Handle, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS);
82  SetForegroundWindow(this.Handle);
83  }
84 
85  private void button_Ok_Click(object sender, EventArgs e)
86  {
87  userPassword = textBox_Password.Text;
88  this.Close();
89  }
90 
91  private void CloseFormTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
92  {
93  //ShowForm();
94 
95  if ((DateTime.Now - currentTime).TotalSeconds > GlobalConfig.ConnectionTimeOut)
96  {
97  //there are no one input the password.
98  ClosePasswordForm();
99  }
100 
101  }
102 
103  private void ShowForm()
104  {
105  if (this.InvokeRequired)
106  {
107  this.Invoke(new FormDlgt(ShowForm), new Object[] { });
108  }
109  else
110  {
111 
112  this.WindowState = FormWindowState.Normal;
113  this.Activate();
114  this.BringToFront();
115  this.Focus();
116  this.TopMost = true;
117 
118  //SetForegroundWindow(this.Handle);
119 
120  this.ShowDialog();
121  }
122  }
123 
124  private void ClosePasswordForm()
125  {
126  if (this.InvokeRequired)
127  {
128  this.Invoke(new FormDlgt(ClosePasswordForm), new Object[] {});
129  }
130  else
131  {
132  this.Close();
133  }
134  }
135 
136  private void button_Cancel_Click(object sender, EventArgs e)
137  {
138  this.Close();
139  }
140 
141 
142  }
143 }
WCHAR * userName
Definition: FilterAPI.h:604
UserPasswordForm(string userName, string processName, string fileName)
WCHAR * processName
Definition: FilterAPI.h:596
static bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags)

Social Network


Services Overview

Architect, implement and test file system filter drivers for a wide range of functionality. We can offer several levels of assistance to meet your specific.

Contact Us

You are welcome to contact us for salse or partnership.

Sales: sales@easefilter.com
Support: support@easefilter.com
Info: info@easefilter.com