Windows Scripting
  Home arrow Windows Scripting arrow Page 2 - 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 - GDI’s Role in Screen Capturing


    (Page 2 of 5 )

    On the whole, capturing the screen requires two crucial techniques: one is to obtain the handler of the window in which your picture lies (i.e. making clear what to capture). The other is to persist the captured image. This is the strong point of GDI+.

    As for the first technique, we can resort to the SetCapture() function to track the mouse moving opertion. During the movement of the mouse, the SetCapture() function can obtain the handler of the window that the mouse points to. Moreover, we can also use the WindowFromPoint() function to find the corresponding window's handler.

    Readers who are familiar with SnagIT know that when capturing some window there is usually a red rectangle around the target window to remind users of the selected window. This functionality is more complex than the former. Next, I’ll show you how to draw a red rectangle using GDI related techniques.

    A very fundamental concept in GDI is the device context (DC), which is what is owned by each window. Suppose the DC of a window is retrieved. Users can render at any part of the window. However, in a typical screen capture application, the target window that users select is uncertain. Therefore, it is not that easy for developers to obtain the DC of the window at the location of the mouse cursor. In fact, the key to this lies in the GetDC() function. The signature is given below:

    HDC GetDC(HWND hWnd);

    The hWnd parameter corresponds to the handler of the window that’s related to the current DC object. Note that when hWnd is null, the GetDC() functionreturns the handler of the device context of the screen. This means that developers can draw anything at any position on the screen.

    The purpose of drawing is to remind users of the currently-selected window. So when drawing, we have to make sure we don't destroy the original content. In such a case, we can set the render mode of the window to RS_NOTXORPEN. First, this makes the paint brush color XOR computed with the screen color, and then NOT computed with the screen color. The same pixel will stay unaltered after being computed via RS_NOTXORPEN twice. In this way, we can draw in the RS_NOTXORPEN node twice, because the window will stay unchanged.

    Author's Note: all the above requirements are rather difficult to accomplish via GDI+.

    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 5 hosted by Hostway
    Stay green...Green IT