Click here to Skip to main content
11,631,992 members (68,859 online)
Click here to Skip to main content

A Screen Capture Tool for Windows Mobile 5

, 13 Jun 2008 Public Domain 34.7K 299 37
Rate this:
Please Sign up or sign in to vote.
A simple screen capture tool for Pocket PC.

Introduction

I (as many others) have been frustrated with the lack of a print screen button on the Pocket PC. So when my colleagues trial version of a screen capture utility expired I decided to create one myself.

After Googling around I found clues but no complete solution so I thought a nice first step would be to write a CodeProject article.

Shards of the (compact)code is derived from the net, but it has been remade, repackaged and recoded and is not easily traced to any single web page. So no credits to others at this time...

Using the Code

The application sends up a messagebox and then waits for the hardware button to be pressed (on the picture above it's the key marked in green). Hardware-keys depend on the device, so you'll have to figure out which button it is on your device if you deploy it to a real Pocket PC.

When the user presses the right button, a bmp-file called capture.jpg is saved under the root, another messagebox is presented, and the application ends. Simple as that.

The application uses the hardware button component to listen to button clicks. The main capture happens here though:

    public class Capturer
    {
        // Declarations
        [DllImport("coredll.dll")]
        public static extern int BitBlt(IntPtr hdcDest, int nXDest, int nYDest,
            int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop);
        
        [DllImport("coredll.dll")]
        private static extern IntPtr GetDC(IntPtr hwnd);
        
        const int SRCCOPY = 0x00CC0020;


        public static void Snapshot(string fileName, Rectangle rectangle)
        {
            //Use a zeropointer to get hold of the screen context
            IntPtr deviceContext = GetDC(IntPtr.Zero);
            
            
            using(Bitmap capture = new Bitmap(rectangle.Width, rectangle.Height))
            //Get screen context
            using (Graphics deviceGraphics = Graphics.FromHdc(deviceContext))
            //Get graphics from bitmap
            using (Graphics captureGraphics = Graphics.FromImage(capture))
            {
                // Blit the image data
                BitBlt(captureGraphics.GetHdc(), 0, 0,
                    rectangle.Width, rectangle.Height, deviceGraphics.GetHdc(),
                    rectangle.Left, rectangle.Top, SRCCOPY);

                //Save to disk
                capture.Save(fileName, System.Drawing.Imaging.ImageFormat.Bmp);
            }
        }
    }

The code gets hold of the screen device context by using GetDC with a zero pointer and then bitblts into a bitmap which is saved at a hardcoded location (the root directory).

History

2008-06-12: First version released.

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication

Share

About the Author

Kai Sevelin
Software Developer (Senior) Know It
Sweden Sweden
Currently employed at Know it, Stockholm, Sweden working with mobile solutions.

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 5 Pin
rakinrk31-Dec-10 19:28
memberrakinrk31-Dec-10 19:28 
GeneralSimple. I like it. Pin
jp2code21-Aug-09 11:45
memberjp2code21-Aug-09 11:45 
GeneralPlease add that Visual Studio 2008 is required... Pin
Destiny77728-Jul-09 8:41
memberDestiny77728-Jul-09 8:41 
GeneralRe: Please add that Visual Studio 2008 is required... Pin
jp2code21-Aug-09 11:52
memberjp2code21-Aug-09 11:52 
Generalvery useful Pin
eRRaTuM26-Jun-09 12:17
membereRRaTuM26-Jun-09 12:17 
GeneralCode in VB .Net Pin
Nirmitk264-Feb-09 8:48
memberNirmitk264-Feb-09 8:48 
GeneralRe: Code in VB .Net Pin
jp2code21-Aug-09 11:55
memberjp2code21-Aug-09 11:55 
GeneralMy vote of 1 Pin
khansameer5-Dec-08 22:55
memberkhansameer5-Dec-08 22:55 
QuestionRegion capture feature??? Pin
maaxobelix15-Sep-08 22:54
membermaaxobelix15-Sep-08 22:54 
AnswerRe: Region capture feature??? Pin
Kai Sevelin25-Nov-08 2:56
memberKai Sevelin25-Nov-08 2:56 
QuestionHow can i capture hidden window with window handle? Pin
sangyoon9310-Jul-08 14:39
membersangyoon9310-Jul-08 14:39 
AnswerRe: How can i capture hidden window with window handle? Pin
Kai Sevelin25-Nov-08 2:57
memberKai Sevelin25-Nov-08 2:57 
GeneralRe: How can i capture hidden window with window handle? Pin
Joao Paulo Figueira7-Dec-08 5:57
memberJoao Paulo Figueira7-Dec-08 5:57 
AnswerRe: How can i capture hidden window with window handle? Pin
jp2code21-Aug-09 12:00
memberjp2code21-Aug-09 12:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150728.1 | Last Updated 13 Jun 2008
Article Copyright 2008 by Kai Sevelin
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid