using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.Drawing; namespace MBoxNewDesktop { using System.Runtime.InteropServices; using System.Windows.Forms; using System.Drawing; using System.Threading; using System.Diagnostics; class ShowSystemModalMBOX { internal sealed class Native { // Fields public const int DESKTOP_SWITCHDESKTOP = 0x100; public const int GENERIC_ALL = 0x10000000; [return: MarshalAs(UnmanagedType.Bool)] [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool CloseDesktop(IntPtr desktop); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern IntPtr CreateDesktop([MarshalAs(UnmanagedType.VBByRefStr)] ref string desktop, [MarshalAs(UnmanagedType.VBByRefStr)] ref string device, IntPtr devmode, int flags, int desiredAccess, IntPtr lpsa); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern IntPtr GetThreadDesktop(int threadId); [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern IntPtr OpenInputDesktop(int flags, [MarshalAs(UnmanagedType.Bool)] bool inherit, int desiredAccess); [return: MarshalAs(UnmanagedType.Bool)] [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool SetThreadDesktop(IntPtr desktop); [return: MarshalAs(UnmanagedType.Bool)] [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)] public static extern bool SwitchDesktop(IntPtr desktop); } public void Show() { this.LockSystemAndShow(new Form(), delegate (){ MessageBox.Show("Nachricht mit Vista Effekt", "Beschreibung", MessageBoxButtons.YesNoCancel); }); } public delegate void EmptyHandler(); private bool LockSystemAndShow(Form window, EmptyHandler method) { Control owner = window; Screen screen = owner == null ? Screen.PrimaryScreen : Screen.FromControl(owner); Bitmap image = new Bitmap(screen.Bounds.Width, screen.Bounds.Height); using (Graphics graphics = Graphics.FromImage(image)) { IntPtr ptr4 = IntPtr.Zero; Rectangle bounds = screen.Bounds; graphics.CopyFromScreen(0, 0, 0, 0, bounds.Size); using (Brush brush = new SolidBrush(Color.FromArgb(0xc0, Color.Black))) { graphics.FillRectangle(brush, screen.Bounds); } if (owner != null) { Form form = owner.FindForm(); graphics.CopyFromScreen(form.Location, form.Location, form.Size); using (Brush brush2 = new SolidBrush(Color.FromArgb(0x80, Color.Black))) { bounds = new Rectangle(form.Location, form.Size); graphics.FillRectangle(brush2, bounds); } } IntPtr threadDesktop = Native.GetThreadDesktop(Thread.CurrentThread.ManagedThreadId); IntPtr newThreadDesktop = Native.OpenInputDesktop(0, false, 0x100); string device = null; string avar = "Desktop" + Guid.NewGuid().ToString(); IntPtr ptr = Native.CreateDesktop(ref avar, ref device, ptr4, 0, 0x10000000, ptr4); Native.SetThreadDesktop(ptr); Native.SwitchDesktop(ptr); Thread thread = new Thread(new ParameterizedThreadStart(this.ShowBackgroundThreadMethod)); thread.Start(new LockSystemParameters(ptr, image, method)); thread.Join(); Native.SwitchDesktop(newThreadDesktop); Native.SetThreadDesktop(threadDesktop); Native.CloseDesktop(ptr); return false; } } private class LockSystemParameters { public Bitmap Background; public IntPtr DesktopPointer; public EmptyHandler Method; public LockSystemParameters(IntPtr desktopPtr, Bitmap background, EmptyHandler method) { this.Background = background; this.DesktopPointer = desktopPtr; this.Method = method; } } private void ShowBackgroundThreadMethod(object aparams) { LockSystemParameters parameters = (LockSystemParameters)aparams; Native.SetThreadDesktop(parameters.DesktopPointer); using (Form form = new BackgroundForm(parameters.Background)) { form.Show(); parameters.Method.DynamicInvoke(null); // STARTE DEN FensterDarstellung form.BackgroundImage = null; Application.DoEvents(); Thread.Sleep(250); } } public class BackgroundForm : Form { // Fields private Bitmap background; // Methods public BackgroundForm(Bitmap background) { this.BackColor = Color.Black; this.FormBorderStyle = FormBorderStyle.None; this.Location = Point.Empty; this.Size = Screen.PrimaryScreen.Bounds.Size; this.StartPosition = FormStartPosition.Manual; this.Visible = true; this.background = background; } protected override void OnShown(EventArgs e) { this.BackgroundImage = this.background; this.DoubleBuffered = true; base.OnShown(e); } } static void Main(string[] args) { ShowSystemModalMBOX p = new ShowSystemModalMBOX(); p.Show(); } } }