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  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
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 / 1
    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


     

    WINDOWS SCRIPTING ARTICLES

    - 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...
    - Modifying XML Files in WSH
    - Reading XML Files in WSH
    - Visual Basic 2005 XML Programming Using XML ...
    - Creating an XML Document in WSH
    - Introducing Two-Way Data Binding using Silve...
    - Silverlight 2.0 Application Development with...
    - Burning Multisession CDs with IMAPI2 in WSH
    - Creating a Silverlight 2.0 Application that ...
    - Burning CDs with the IMAPI2 Control
    - Burning CDs in Windows XP with WSH

     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     




    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT