Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Security Blackout Window (In C#)

0.00/5 (No votes)
18 Dec 2014 1  
This is an alternative for Security Blackout Window

Introduction

This is a port of Richard MacCutchan's Security Blackout Window to C#.

The sources are on Github.

Background

I did this as I wanted to see if it would work.

Using the Code

There are two methods that show the blackout window:

public static void Blackout(IntPtr hWnd, Action action);

public static T Blackout<T>(IntPtr hParentWnd, Func<T> func);

The second version (the generic one) is for doing something like:

BlackoutWindow.Blackout(SomeHandle, () => {
    return MessageBox.Show("A Test", "A Test", MessageBoxButtons.YesNo);
});

Points of Interest

I was having the <Sarcasm> greatest </Sarcasm> time getting one of the structures (the WNDCLASSEX one) to marshal correctly in the RegisterClassEx method (damn those AccessViolationExceptions!) I finally ended up using an IntPtr as the argument to the method and using the Marshal class to marshal the structure to memory, which worked.

P/Invoke is useful, but can be a pain in the posterior sometimes.

History

  • V 1.0 - 2014-12-19 - Initial version
  • V 1.1 - 2014-12-19 - Added WPF Example

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here