呼び出し元のフォームをXPのシャットダウン時っぽくグレースケールで表示する


1. 呼び出し元フォームをグレースケールにする

    [Windows XP Grayscale Shutdown Effect in Windows Forms](http://www.codeproject.com/KB/dialog/windowsshutdowneffect.aspx)
1. ディスプレイ全体をグレースケールにする

    [A modal dialog that fades the background to gray-scale imitating the XP shutdown screen](http://www.codeproject.com/Articles/13187/A-modal-dialog-that-fades-the-background-to-gray-s)

---
1のサンプルをCEで動くように修正したソース。
Windows Embeddedでもたぶん動作可能（グレースケールの作成に時間がかかる）

```csharp
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace WindShutdownEffectCe
{
    public partial class Form1 : Form
    {
        [DllImport("coredll.dll", SetLastError = true)]
        public static extern IntPtr GetDC(IntPtr hWnd);

        [DllImport("coredll.dll")]
        public static extern IntPtr ReleaseDC(IntPtr hWnd, IntPtr hDC);

        [DllImport("coredll.dll")]
        public static extern IntPtr BitBlt(IntPtr hDestDC, int x, int y, int nWidth, int nHeight, IntPtr hSrcDC, int xSrc, int ySrc, int dwRop);

        public Form1()
        {
            InitializeComponent();
        }

        private Bitmap GetFormImage(Form frm)
        {
            Graphics g = frm.CreateGraphics();
            Size s = frm.Size;
            Bitmap formImage = new Bitmap(s.Width, s.Height);
            Graphics mg = Graphics.FromImage(formImage);

            IntPtr dc1 = g.GetHdc();
            IntPtr dc2 = mg.GetHdc();
            BitBlt(dc2, 0, 0, frm.ClientRectangle.Width, frm.ClientRectangle.Height, dc1, 0, 0, 13369376);
            g.ReleaseHdc(dc1);
            mg.ReleaseHdc(dc2);
            return formImage;
        }

        public static Bitmap MakeGrayscale(Bitmap original)
        {
            //make an empty bitmap the same size as original
            Bitmap newBitmap = new Bitmap(original.Width, original.Height);
            for (int i = 0; i < original.Width; i++)
            {
                for (int j = 0; j < original.Height; j++)
                {
                    //get the pixel from the original image
                    Color originalColor = original.GetPixel(i, j);
                    //create the grayscale version of the pixel
                    int grayScale = (int)((originalColor.R * .3) + (originalColor.G * .59)
                        + (originalColor.B * .11));
                    //create the color object
                    Color newColor = Color.FromArgb(grayScale, grayScale, grayScale);
                    //set the new image's pixel to the grayscale version
                    newBitmap.SetPixel(i, j, newColor);
                }
            }
            return newBitmap;
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            panel1.Image = MakeGrayscale(GetFormImage(this));
            panel1.Visible = true;
            panel1.Dock = DockStyle.Fill;

            if (DialogResult.Yes == MessageBox.Show("Do you want to Exit", 
                                    "Exit Windows", MessageBoxButtons.YesNo))
                 Application.Exit();

            else
            {
                panel1.Image = null;
                panel1.Visible = false;
            }
        }
    }
}
```