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.
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.
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.
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.
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.