I created the SCapture class to allow us capture still images from the screen. The SCapture class uses some Api methods to implement the capture. The main reason I used the Api functions such as BitBlt to build the bitmap image because the .Net way of capturing an image does not capture transparent image as transparent; check it here.
Class shared methods:
FullScreen - Captures the full screen (all monitors in a single image).
DisplayMonitor- Captures a display monitor.
ActiveWindow – Captures the active window.
Window– Captures a window specified by the handle or a point (overloaded).
Control– Captures a control of a window specified by a handle or a point (overloaded).
ScreenRectangle– Captures a rectangle image from the screen.
All methods can capture images that include the cursor. New
Using the code:
vb Code:
Private Sub ControlButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ControlButton.Click
Try
'Capture the image of this button including the cursor.
Dim img As Image = SCapture.Control(Control.MousePosition, True)
The code seems to work nicely. However FullScreen only captures the left screen of my two screens (i have dual monitors - a common trend these days). It should capture all screens - or at least have a parameter allowing to select all screens.
The code seems to work nicely. However FullScreen only captures the left screen of my two screens (i have dual monitors - a common trend these days). It should capture all screens - or at least have a parameter allowing to select all screens.
I updated the class so it will capture all monitors in a single image by using the FullScreen method and added a method DisplayMonitor that will capture the image of a particular monitor.
Last edited by VBDT; Sep 27th, 2007 at 02:03 AM.
Rating is a way of saying thank you. Don't forget to rate always!
Hi!
I Have done some (useful) addons to the SCapture Class.
And made some Changes.
See attached Code.
It is a bit Quick and dirty, have no time......
Hi Peter Kriegel, nice job. I specially like the dragging thing. The SCapture class spouse to be the base class so you can add some other methods to it. Although I like what you have done with the class, I have some comments about changes that you made to the SCapture class.
Firs of all I say that the Window method changes are not correct. It is true that a window is a control but the “Control” method with a point argument will not always capture a window. For example if the point is in a button area which is in its turn on a form than the WindowFromPoint Api method will return the handle of the button not the form that it is on. Thus it will capture the button not the form.
Second, I would remove all the Optional keywords from the methods' arguments since Visual Studio's Code Analyser suggests to change them to none optional. Now, this is just a warning and it is left to the developer to decide. I prefer the arguments to be none optional so that the developer can specify the argument value by forcing them to not make mistakes.
Third, use the Return key word instead of assigning the return value of the Window method to the method. I guess this is a VB6 stile. In VB.Net always use the Return key word.
So far I just noticed these three things but over all it is a great job. If I have a time, than I will take a look on the dragging thing.
Last edited by VBDT; Jul 31st, 2008 at 12:30 PM.
Rating is a way of saying thank you. Don't forget to rate always!
Hi Arman Ghazanchyan !
First i like to thank you for your kind feed back!
Originally Posted by VBDT
Firts of all I say that the Window method changes are not correct. It is true that a window is a control but the “Control” method with a point argument will not always capture a window. For example if the point is in a button area which is in its turn on a form than the WindowFromPoint Api method will return the handle of the button not the form that it is on. Thus it will capture the button not the form.
Yes You are right i lost it in the code-fight...
You can get the Mainwindowhandel from a Controlhandel by using API GetAncestor(ControlHandel,GA_ROOTOWNER) where GA_ROOTOWNER = 3
Originally Posted by VBDT
Second, I would remove all the Optional keywords from the methods' arguments since Visual Studio's Code Analyser suggests to change them to none optional. Now, this is just a warning and it is left to the developer to decide. I prefer the arguments to be none optional so that the developer can specify the argument value by forcing them to not make mistakes.
Ok! its really a developer taste.... but i desided me to VB because its less code writing against C#.
I think it is OK to make Optional Parameters when you have one optional Parameter.
So there is an overload unnecessary and you have default values that you can save to declare into your class.
I saved my Time, writing so much overloads get bored and the user of the class has comfort but......its really a developer taste
Originally Posted by VBDT
Third, use the Return key word instead of assigning the return value of the Window method to the method. I guess this is a VB6 stile. In VB.Net always use the Return key word.
.
I think it is even a developer taste! When you use return, the function is leaved immediately. If you assign the value to the Function (variable) so you can do something after that and leave the Function by Exit Function or the end of the function. For me its a bit more flowcontrol.
Originally Posted by VBDT
So far I just noticed these three things but over all it is a great job. If I have a time, than I will take a look on the dragging thing.
What a bummer!
I thought the ClipperTool is the favorite... Its is cleaner designed, and do the Layer trick like Hudini
The Dragtool is very quick and dirty coded and i'm new on so much event handling stuff, it is translated from VB6 Code and is to much API32 burden.
Hi Arman Ghazanchyan !
First i like to thank you for your kind feed back!
Yes You are right i lost it in the code-fight...
You can get the Mainwindowhandel from a Controlhandel by using API GetAncestor(ControlHandel,GA_ROOTOWNER) where GA_ROOTOWNER = 3
Ok! its really a developer taste.... but i desided me to VB because its less code writing against C#.
I think it is OK to make Optional Parameters when you have one optional Parameter.
So there is an overload unnecessary and you have default values that you can save to declare into your class.
I saved my Time, writing so much overloads get bored and the user of the class has comfort but......its really a developer taste
I think it is even a developer taste! When you use return, the function is leaved immediately. If you assign the value to the Function (variable) so you can do something after that and leave the Function by Exit Function or the end of the function. For me its a bit more flowcontrol.
What a bummer!
I thought the ClipperTool is the favorite... Its is cleaner designed, and do the Layer trick like Hudini
The Dragtool is very quick and dirty coded and i'm new on so much event handling stuff, it is translated from VB6 Code and is to much API32 burden.
Hmm, I don’t know how did I hurt your feelings but if I did than my apologies.
And yes, you are right; we can use the GetAncestor Api method to get the parent window in the chain. Thanks for that!
Last edited by VBDT; Jul 31st, 2008 at 10:04 PM.
Rating is a way of saying thank you. Don't forget to rate always!
Hmm, I don’t know how did I hurt your feelings but if I did than my apologies.
No ! You didn't hurt me !
One of my faforite is to discuss over Programming technics.(therfor i am Fire and Flame)
Please think on it, english is not my mother toungue, and it comes to misunderstandings some times, thats why i am using the Smilies so much to prevent for. (I dont write these replys, i develop them ...)
Last edited by Pamkkkkk; Aug 2nd, 2008 at 11:20 AM.
The SCapture class uses some Api methods to implement the capture. The main reason I used the Api functions such as BitBlt to build the bitmap image because the .Net way of capturing an image does not capture transparent image as transparent; check it here.
In some cases you can use a supposed bug as a feature.
(its not a bug its a feature )
I have to say, thank you for this sample, it's exactly what I was looking for, all other examples out there only gave you the first monitor instead of full screen like yours.
I have to say, thank you for this sample, it's exactly what I was looking for, all other examples out there only gave you the first monitor instead of full screen like yours.
Good Job!
Thanks, I am glad you liked it
Rating is a way of saying thank you. Don't forget to rate always!