FrmCover: Uncover with keypress.

FrmCover: Copy active window title, before covering.
This commit is contained in:
2019-05-23 08:31:43 +02:00
parent 2a8e876c60
commit dcb9c65267
2 changed files with 45 additions and 2 deletions

View File

@@ -1,5 +1,6 @@
using System; using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text;
namespace VAR.Toolbox.Code.Windows namespace VAR.Toolbox.Code.Windows
{ {
@@ -154,11 +155,37 @@ namespace VAR.Toolbox.Code.Windows
[DllImport("user32.dll")] [DllImport("user32.dll")]
public static extern IntPtr GetDesktopWindow(); public static extern IntPtr GetDesktopWindow();
[DllImport("user32.dll")] [DllImport("user32.dll")]
public static extern IntPtr GetWindowDC(IntPtr hWnd); public static extern IntPtr GetWindowDC(IntPtr hWnd);
[DllImport("user32.dll")] [DllImport("user32.dll")]
public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC); public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC);
[DllImport("user32.dll")] [DllImport("user32.dll")]
public static extern IntPtr GetWindowRect(IntPtr hWnd, ref RECT rect); public static extern IntPtr GetWindowRect(IntPtr hWnd, ref RECT rect);
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool SetForegroundWindow(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
public static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);
public static string GetActiveWindowTitle()
{
const int nChars = 256;
StringBuilder Buff = new StringBuilder(nChars);
IntPtr handle = GetForegroundWindow();
if (GetWindowText(handle, Buff, nChars) > 0)
{
return Buff.ToString();
}
return null;
}
} }
} }

View File

@@ -2,6 +2,7 @@
using System.Drawing; using System.Drawing;
using System.Windows.Forms; using System.Windows.Forms;
using VAR.Toolbox.Code; using VAR.Toolbox.Code;
using VAR.Toolbox.Code.Windows;
namespace VAR.Toolbox.UI namespace VAR.Toolbox.UI
{ {
@@ -12,8 +13,8 @@ namespace VAR.Toolbox.UI
private Random rnd = new Random(); private Random rnd = new Random();
private Timer _timer = new Timer(); private Timer _timer = new Timer();
private UInt32 _mouseX = 0; private uint _mouseX = 0;
private UInt32 _mouseY = 0; private uint _mouseY = 0;
#endregion Declarations #endregion Declarations
@@ -23,12 +24,15 @@ namespace VAR.Toolbox.UI
{ {
Mouse.GetPosition(out _mouseX, out _mouseY); Mouse.GetPosition(out _mouseX, out _mouseY);
Text = User32.GetActiveWindowTitle();
TopMost = true; TopMost = true;
FormBorderStyle = FormBorderStyle.None; FormBorderStyle = FormBorderStyle.None;
BackColor = Color.Black; BackColor = Color.Black;
Load += FrmCover_Load; Load += FrmCover_Load;
Click += FrmCover_Click; Click += FrmCover_Click;
KeyPress += FrmCover_KeyPress;
_timer.Interval = 1000; _timer.Interval = 1000;
_timer.Enabled = true; _timer.Enabled = true;
@@ -48,6 +52,7 @@ namespace VAR.Toolbox.UI
Height = r.Height; Height = r.Height;
Cursor.Hide(); Cursor.Hide();
_timer.Start(); _timer.Start();
User32.SetForegroundWindow(Handle);
} }
#endregion Form life cycle #endregion Form life cycle
@@ -64,8 +69,19 @@ namespace VAR.Toolbox.UI
Close(); Close();
} }
private void FrmCover_KeyPress(object sender, KeyPressEventArgs e)
{
Cursor.Show();
_timer.Stop();
_timer.Enabled = false;
Mouse.SetPosition(_mouseX, _mouseY);
Close();
}
private void timer_Tick(object sender, EventArgs e) private void timer_Tick(object sender, EventArgs e)
{ {
User32.SetForegroundWindow(Handle);
try try
{ {
Mouse.Move( Mouse.Move(