Windows Scripting
  Home arrow Windows Scripting arrow Page 4 - Screen Capturing via GDI+ and GDI
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Screen Capturing via GDI+ and GDI
By: Xianzhong Zhu
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-08-06

    Table of Contents:
  • Screen Capturing via GDI+ and GDI
  • GDI’s Role in Screen Capturing
  • Developing a Screen Capture Application
  • Persisting the Captured Images via GDI
  • Adding a Reference to GDI and Visualizing the Result

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Screen Capturing via GDI+ and GDI - Persisting the Captured Images via GDI


    (Page 4 of 5 )

    As soon as the user starts the application and presses the left button of the mouse in the dialog, the capturing begins. After the captured target is properly selected and the left button of the mouse is released, the image of the target window will be persisted automatically into the system clipboard. However, persisting the corresponding image to the hard disk is more important. Apparently, if we take the GDI path, we need to be quite familiar with the structures of various bitmaps. This leads to so much trouble. On the other hand, with GDI+, everything becomes so convenient and natural. Let’s take a look at how to save the captured image into a .bmp file.

    So far, the capturing application has gotten the handler of the bitmap in relation to the captured window. Now, we are to save the handler of the bitmap as the expected bitmap file. All in all, this will be performed with the help of the Bitmap class in GDI+. This is shown below:

    void CScreenCaptureDlg::OnLButtonUp(UINT nFlags, CPoint point)

    {

    //……omitted (see the download source code)

    if(GetSaveFileName(&ofn))

    {

    CLSID pngClsid;

    Bitmap bmp(hBitmap,NULL);

    //get the encode mode of the BMP file

    GetEncoderClsid(L"image/bmp",&pngClsid);//helper function

    CString tmp(ofn.lpstrFile);

    CStringW filename((LPCSTR)tmp);

    //store the captured picture on the screen

    bmp.Save(filename,&pngClsid);

    }

    ReleaseCapture();

    MessageBox("The content on the screen has been successfully saved into a disk file!");

    // restore the original state of the demo applicaion’s window

    ShowWindow(SW_NORMAL);

    CDialog::OnLButtonUp(nFlags, point);

    }

    Please notice that we construct another helper function, called GetEncoderClsid, which is responbile for retrieving the CLSID info of the encoder of the image file in the specified format. To cut a long story short, we will no longer dwell on itfor detailed coding you can refer to the source code at the end of the article.

    More Windows Scripting Articles
    More By Xianzhong Zhu


       · All the comments and some message boxes seem to be garbled, or else in some foreign...
     

    WINDOWS SCRIPTING ARTICLES

    - More Windows Scripting Workarounds from Nilpo
    - Overloading Methods and More in VBScript
    - Improving MFC for Windows Vista
    - Regular Expressions in VBScript
    - Working with Dates in WMI
    - Completing Calendars with VBScript Date Func...
    - Building Calendars with VBScript Date Functi...
    - Working With Dates and Times in VBScript
    - Designing WCF DataContract Classes Using the...
    - Understanding Dates and Times in VBScript
    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek