Windows CE 6.0에서는 따로 화면 캡쳐를 지원하지 않습니다. 프로그래밍 문서를 작성하거나, 사용설명서를 만들 때 캡쳐 화면이 필요하여, 다음과 같은 캡쳐 코드를 넣었습니다.

using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Imaging;

namespace NameSpace {
    public class Copy {

        enum RasterOperation : uint { SRC_COPY = 0x00CC0020 }

        [DllImport("coredll.dll")]
        static extern int BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, RasterOperation rasterOperation);

        [DllImport("coredll.dll")]
        private static extern IntPtr GetDC(IntPtr hwnd);

        [DllImport("coredll.dll")]
        private static extern int ReleaseDC(IntPtr hwnd, IntPtr hdc);

        public static void CopyThere() {
            Rectangle bounds = Screen.PrimaryScreen.Bounds;
            IntPtr hdc = GetDC(IntPtr.Zero);
            Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height, PixelFormat.Format16bppRgb565);
            using (Graphics graphics = Graphics.FromImage(bitmap)) {
                IntPtr dstHdc = graphics.GetHdc();
                BitBlt(dstHdc, 0, 0, bounds.Width, bounds.Height, hdc, 0, 0,
                RasterOperation.SRC_COPY);
                graphics.ReleaseHdc(dstHdc);
            }
            string time = DateTime.Now.ToString("yyyyMMddHHmmss");
            bitmap.Save(time + "screenshot.jpg", ImageFormat.Jpeg);
            ReleaseDC(IntPtr.Zero, hdc);
        }

        internal static void SetCopy(Form form) {
            form.KeyPreview = true;
            form.KeyDown += new System.Windows.Forms.KeyEventHandler(Copy.Form_KeyDown);
        }

        internal static void Form_KeyDown(object sender, KeyEventArgs e) {
            if (e.KeyCode == Keys.F23) { //여기에 캡쳐를 하기 위한 물리 키 값를 넣으면 됩니다.
                Copy.CopyThere();
            }
        }
    }
}

위의 클래스를 구현한 후, 캡쳐 기능이 필요한 Windows Form에서 CopyThere(this) 메소드를 넣고, 실제 실행 중 지정한 키를 누르면 가장 상위 디렉토리에 스크린샷 사진이 저장됩니다.

+ Recent posts