Click here to Skip to main content
Click here to Skip to main content
Go to top

Capture all of the forms of a .net Desktop application

, 20 Nov 2005
Rate this:
Please Sign up or sign in to vote.
This Application helps you to save a pring screen of all of the forms in another .net application

Introduction

Capturing all of the form (of a .NET desktop application) which may be useful in creating a documentation and online help. (instead of open all forms and print-screen manually). Disadvantages of this application:
1- It is not working in a silent mode: It opens all of the forms of the application which we need to be captured. And doesn’t save the images without showing the forms.
2- If the controls in the form created programmatically during the run time. These controls will not be captured in the saved image.

Application Methodology:

This solution contains two project: the dll (out core application) and a windows forms program (test project) This project mainly depends on System.Reflection to collect the images of the other application’s forms.

There are main 4 regions in the DLL :

1- Invoking APIs:

a. DeleteDC : The DeleteDC function deletes the specified device context (DC).

b. GetForegroundWindow : returns a handle to the foreground window (the window with which the user is currently

c. ReleaseDC : function releases a device context (DC), freeing it for use by other applications.

d. DeleteObject : function deletes a logical pen, brush, font, bitmap, region, or palette, freeing all system resources associated with the object. After the object is deleted, the specified handle is no longer valid.

e. CreateCompatibleDC : function creates a memory device context (DC) compatible with the specified device.

f. GetWindowDC : function retrieves the device context (DC) for the entire window, including title bar, menus, and scroll bars. A window device context permits painting anywhere in a window, because the origin of the device context is the upper-left corner of the window instead of the client area.

g. SelectObject : selects an object into the specified device context (DC). The new object replaces the previous object of the same type.

h. CreateCompatibleBitmap : creates a bitmap compatible with the device that is associated with the specified device context.

2- GrabWindow : Used capturing the current active window.

3- CreateInstance : Used to instiate an instance of the form using reflection.

4- ProcessingForms : Used to loop through the forms and capture them one by one after creating instance of each one.

What is Reflection?


All .NET compilers produce metadata about the types defined in the modules they produce. This metadata is packaged along with the module (modules in turn are packaged together in assemblies), and can be accessed by a mechanism called reflection. The System.Reflection namespace contains classes that can be used to interrogate the types for a module/assembly. With System.Reflection you will be able to find out information about objects, the application details (assemblies), its metadata at run-time.
This allows application to collect information about itself and also manipulate on itself. It can be used effectively to find all the types in an assembly and/or dynamically invoke methods in an assembly. This includes information about the type, properties, methods and events of an object and to invoke the methods of object Invoke method can be used too. With reflection we can dynamically create an instance of a type, bind the type to an existing object, or get the type from an existing object and invoke its methods or access its fields and properties. If Attributes (C#) are used in application, then with help of reflection we can access these attributes. It can be even used to emit Intermediate Language code dynamically so that the generated code can be executed directly.

Assembly Class

can be used to get the information and manipulate the assembly. This class allows us to define and load assemblies, load modules that are listed in the assembly manifest, and locate a type from this assembly and create an instance of it. Assembly.GetType or Assembly.GetTypes are the two methods that can be used to get the Type object from assemblies that have not been loaded. To these method name of the Type(s) is passed as the parameter. Type.GetType is used similarly as mentioned above only distinction is that here the assemblies are loaded.

ConstructorInfo Class

is used for the reflection of a constructor, and used to fetch the information about constructor also constructor can be invoked. Constructor information like name, parameters, access modifiers, and various implementation details (such as abstract or virtual) can be obtained. Class Objects are created when constructor of a ConstructorInfo is invoked this returns either the GetConstructors or GetConstructor method of a Type object.

Usage

This software is released into the public domain. You are free to use it in any way you like. If you modify it or extend it, please to consider posting new code here for everyone to share. This software is provided "as is" with no expressed or implied warranty. I accept no liability for any damage or loss of business that this software may cause.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

No Biography provided

Comments and Discussions

 
GeneralBest solution PinmemberPANKAJ Z SINGH25-May-09 1:03 
GeneralNew CopyFromScreen API in .NET 2.0 PinmemberJaroslaw Kowalski20-Nov-05 21:18 
Using .NET 2.0 things get much easier because of the new CopyFromScreen() API.
 
            Rectangle r = form.RectangleToScreen(form.ClientRectangle);
 
            using (Bitmap bmp = new Bitmap(r.Width, r.Height))
            {
                using (Graphics gfx = Graphics.FromImage(bmp))
                {
                    gfx.CopyFromScreen(r.Left, r.Top, 0, 0, bmp.Size);
                }
                bmp.Save("c:\\test.png", ImageFormat.Png);
            }
 

 
Jaroslaw Kowalski
http://blog.jkowalski.net/
GeneralRe: New CopyFromScreen API in .NET 2.0 PinmemberMohamed Elzahaby21-Nov-05 10:17 
AnswerRe: New CopyFromScreen API in .NET 2.0 Pinmemberbittercoder11-Jan-07 12:58 
GeneralRe: New CopyFromScreen API in .NET 2.0 PinmemberMohamed Elzahaby23-Jan-07 23:33 

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 | Mobile
Web03 | 2.8.140905.1 | Last Updated 20 Nov 2005
Article Copyright 2005 by Mohamed Elzahaby
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid