fakeWindows
Hey! You should read C# 4.0 in a Nutshell: The Definitive Reference.
Copies entire screenbuffer to a memorybuffer, then draws the buffer to a window form which has ontop property.
Hence user has a ‘fake’ Windows showing, an image that captures all their input without giving any responce.
A screenshot would be silly.
Source code (DrawingBoard.cs)
-
using System;
-
using System.Drawing;
-
using System.Windows.Forms;
-
using System.Runtime.InteropServices;
-
using System.Threading;
-
using System.Net;
-
using System.Diagnostics;
-
using System.IO;
-
-
namespace FakeWindows
-
{
-
public partial class DrawingBoard : Form
-
{
-
public DrawingBoard()
-
{
-
InitializeComponent();
-
}
-
-
[DllImport("user32.dll", SetLastError = false)]
-
static extern IntPtr GetDesktopWindow();
-
-
[DllImport("user32.dll")]
-
static extern IntPtr GetWindowDC(IntPtr hWnd);
-
-
[DllImport("gdi32.dll", SetLastError = true)]
-
static extern IntPtr CreateCompatibleDC(IntPtr hdc);
-
-
[DllImport("gdi32.dll")]
-
static extern IntPtr CreateCompatibleBitmap(IntPtr hdc, int nWidth, int nHeight);
-
-
public const int SRCCOPY = 13369376;
-
[DllImport("gdi32.dll")]
-
public static extern bool BitBlt(IntPtr hdcDest, int xDest, int yDest, int wDest, int hDest, IntPtr hdcSource, int xSrc, int ySrc, int RasterOp);
-
-
public const int SM_CXSCREEN = 0;
-
public const int SM_CYSCREEN = 1;
-
[DllImport("user32.dll")]
-
public static extern int GetSystemMetrics(int abc);
-
-
[DllImport("gdi32.dll", EntryPoint = "DeleteDC")]
-
public static extern IntPtr DeleteDC(IntPtr hDc);
-
-
[DllImport("gdi32.dll", EntryPoint = "DeleteObject")]
-
public static extern IntPtr DeleteObject(IntPtr hDc);
-
-
[DllImport("user32.dll", EntryPoint = "ReleaseDC")]
-
public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDc);
-
-
[DllImport("gdi32.dll", EntryPoint = "SelectObject")]
-
public static extern IntPtr SelectObject(IntPtr hdc, IntPtr bmp);
-
-
Bitmap bmp;
-
private void DrawingBoard_Load(object sender, EventArgs e)
-
{
-
// gets handle for the desktop window (whole screen)
-
IntPtr hwnd = GetDesktopWindow();
-
if (hwnd == IntPtr.Zero) { return; }
-
-
// get device context
-
IntPtr hdc = GetWindowDC(hwnd);
-
if (hdc == IntPtr.Zero) { return; }
-
-
// create a new dc for us to use
-
IntPtr hmemdc = CreateCompatibleDC(hdc);
-
if (hmemdc == IntPtr.Zero) { return; }
-
-
// get screen resolution
-
int cx = GetSystemMetrics(SM_CXSCREEN);
-
int cy = GetSystemMetrics(SM_CYSCREEN);
-
-
// create a bitmap to draw on
-
IntPtr hbitmap = CreateCompatibleBitmap(hdc, cx, cy);
-
if (hbitmap == IntPtr.Zero) { return; }
-
-
IntPtr hold = SelectObject(hmemdc, hbitmap);
-
-
// copy all data from desktop window’s dc to our new dc
-
bool bitted = BitBlt(hmemdc, 0, 0, cx, cy, hdc, 0, 0, SRCCOPY);
-
-
// clean up & store the bitmap
-
SelectObject(hmemdc, hold);
-
DeleteDC(hmemdc);
-
ReleaseDC(hwnd, hdc);
-
-
bmp = Image.FromHbitmap(hbitmap);
-
DeleteObject(hbitmap);
-
-
// cover the whole screen
-
this.WindowState = FormWindowState.Maximized;
-
this.Refresh();
-
}
-
-
int x = 0;
-
private void timerPaint_Tick(object sender, EventArgs e)
-
{
-
// make sure our window is on top & in focus (so we capture all user input)
-
this.BringToFront();
-
this.Focus();
-
-
if (x == 100)
-
{ // only re-paint every 100 ms (we don’t want to flicker)
-
this.Refresh();
-
x = 0;
-
} x++;
-
}
-
-
private void DrawingBoard_Paint(object sender, PaintEventArgs e)
-
{
-
// draw the ‘fake’ windows onto the window
-
this.BackgroundImage = bmp;
-
}
-
-
private void DrawingBoard_FormClosing(object sender, FormClosingEventArgs e)
-
{
-
// e.Cancel = false will deny user to close the program
-
e.Cancel = false;
-
}
-
}
-
}
Source code (DrawingBoard.Designer.cs)
-
namespace FakeWindows
-
{
-
partial class DrawingBoard
-
{
-
private System.ComponentModel.IContainer components = null;
-
-
protected override void Dispose(bool disposing)
-
{
-
if (disposing && (components != null)) { components.Dispose(); }
-
base.Dispose(disposing);
-
}
-
-
private void InitializeComponent()
-
{
-
this.SuspendLayout();
-
-
// timerPaint
-
this.timerPaint.Enabled = true;
-
this.timerPaint.Interval = 1;
-
-
// DrawingBoard
-
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
-
this.Name = "DrawingBoard";
-
this.ShowIcon = false;
-
this.ShowInTaskbar = false;
-
this.TopMost = true;
-
this.WindowState = System.Windows.Forms.FormWindowState.Minimized; //minimized on startup to wait for maximize after screen has been copied
-
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.DrawingBoard_FormClosing);
-
this.ResumeLayout(false);
-
}
-
-
private System.Windows.Forms.Timer timerPaint;
-
}
-
}
Leave a Reply