Click here to Skip to main content
15,891,847 members
Articles / Programming Languages / C#
Article

Capture all of the forms of a .net Desktop application

Rate me:
Please Sign up or sign in to vote.
2.64/5 (7 votes)
20 Nov 20054 min read 35.4K   481   14   5
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


Written By
Egypt Egypt
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralBest solution Pin
PANKAJ Z SINGH25-May-09 1:03
PANKAJ Z SINGH25-May-09 1:03 
GeneralNew CopyFromScreen API in .NET 2.0 Pin
Jaroslaw Kowalski20-Nov-05 21:18
Jaroslaw Kowalski20-Nov-05 21:18 
GeneralRe: New CopyFromScreen API in .NET 2.0 Pin
Mohamed Elzahaby21-Nov-05 10:17
Mohamed Elzahaby21-Nov-05 10:17 
AnswerRe: New CopyFromScreen API in .NET 2.0 Pin
bittercoder11-Jan-07 12:58
bittercoder11-Jan-07 12:58 
GeneralRe: New CopyFromScreen API in .NET 2.0 Pin
Mohamed Elzahaby23-Jan-07 23:33
Mohamed Elzahaby23-Jan-07 23:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

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