Click here to Skip to main content
6,822,123 members and growing! (17,821 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » Mobile Development » General     Intermediate License: A Public Domain dedication

A Screen Capture Tool for Windows Mobile 5

By Kai Sevelin

A simple screen capture tool for Pocket PC.
C# (C#2.0), .NETCF, .NET, GDI+, Dev
Posted:13 Jun 2008
Views:17,080
Bookmarked:34 times
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
10 votes for this article.
Popularity: 4.06 Rating: 4.06 out of 5
1 vote, 10.0%
1

2
1 vote, 10.0%
3
3 votes, 30.0%
4
5 votes, 50.0%
5

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

About the Author

Kai Sevelin


Member
Currently employed at Know it, Stockholm, Sweden working with mobile solutions.
Occupation: Software Developer (Senior)
Company: Know It
Location: Sweden Sweden

Other popular Mobile Development articles:

  • Writing Your Own GPS Applications: Part 2
    In part two of the series, the author of "GPS.NET" teaches developers how to write GPS applications suitable for the real world by mastering GPS precision concepts. Source code includes a working NMEA interpreter and sample high-precision application in C# and VB.NET.
  • Writing Your Own GPS Applications: Part I
    What is it that GPS applications need to be good enough to use for in-car navigation? Also, how does the process of interpreting GPS data actually work? In this three-part series, I will cover both topics and give you the skills you need to write a commercial-grade GPS application.
  • Learn How to Find GPS Location on Any SmartPhone, and Then Make it Relevant
    A step by step tutorial for getting GPS from any SmartPhone, even without GPS built in, and then making location useful.
  • Windows Mobile, iPhone, Android - Marketplace Comparison
    Detailed comparison between Windows Mobile Marketplace, Apple's iPhone AppStore and Android Market from developer point of view.
  • iPhone UI in Windows Mobile
    It's an interface that works with transparency effects. As a sample I used an interface just like the iPhone one. In this tutorial I am explaining how simple is working with transparency on Windows Mobile.
Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 13 of 13 (Total in Forum: 13) (Refresh)FirstPrevNext
GeneralSimple. I like it. Pinmemberjp2code12:45 21 Aug '09  
GeneralPlease add that Visual Studio 2008 is required... PinmemberDestiny7779:41 28 Jul '09  
GeneralRe: Please add that Visual Studio 2008 is required... Pinmemberjp2code12:52 21 Aug '09  
Generalvery useful PinmembereRRaTuM13:17 26 Jun '09  
GeneralCode in VB .Net PinmemberNirmitk269:48 4 Feb '09  
GeneralRe: Code in VB .Net Pinmemberjp2code12:55 21 Aug '09  
GeneralMy vote of 1 Pinmemberkhansameer23:55 5 Dec '08  
QuestionRegion capture feature??? Pinmembermaaxobelix23:54 15 Sep '08  
AnswerRe: Region capture feature??? PinmemberKai Sevelin3:56 25 Nov '08  
QuestionHow can i capture hidden window with window handle? Pinmembersangyoon9315:39 10 Jul '08  
AnswerRe: How can i capture hidden window with window handle? PinmemberKai Sevelin3:57 25 Nov '08  
GeneralRe: How can i capture hidden window with window handle? PinmemberJoao Paulo Figueira6:57 7 Dec '08  
AnswerRe: How can i capture hidden window with window handle? Pinmemberjp2code13:00 21 Aug '09  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

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

PermaLink | Privacy | Terms of Use
Last Updated: 13 Jun 2008
Editor: Sean Ewington
Copyright 2008 by Kai Sevelin
Everything else Copyright © CodeProject, 1999-2010
Web21 | Advertise on the Code Project