65.9K
CodeProject is changing. Read more.
Home

Security Blackout Window (In C#)

emptyStarIconemptyStarIconemptyStarIconemptyStarIconemptyStarIcon

0/5 (0 vote)

Dec 19, 2014

CPOL
viewsIcon

16281

downloadIcon

150

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