-
October 3rd, 2011, 12:54 AM
#1
Snapshot of any window in foreground? Similar to Task Switcher
Title is self explainatory.
Here is the code:
Code:
public Bitmap CaptureWindow(IntPtr hWnd)
{
Rectangle rctForm = Rectangle.Empty;
IntPtr test = GetWindowDC(hWnd);
Graphics grfx = Graphics.FromHdc(test);
using (grfx)
{
RectangleF test2 = grfx.VisibleClipBounds;
rctForm = Rectangle.Round(grfx.VisibleClipBounds);
}
Bitmap pImage = new Bitmap(rctForm.Width, rctForm.Height);
Graphics graphics = Graphics.FromImage(pImage);
IntPtr hDC = graphics.GetHdc();
//paint control onto graphics using provided options
try
{
PrintWindow(hWnd, hDC, (uint)0);
}
finally
{
graphics.ReleaseHdc(hDC);
}
return pImage;
}
Now... It works for most of the windows but not all. Example: http://snpr.cm/ozRClN.jpg
Non working: http://snpr.cm/HU2QuR.jpg. Its a Delphi program but i guess it doesnt matter. Same happens to few others.
The function is called in on Load event of my Form containing PictureBox
Code:
pictureBox1.Image = CaptureWindow(okienko);
'okienko' is a handle to that window.
I already tested out few solutions using gdi32.dll and user32.dll functions but without luck.
Facts:
1.What i have already discovered is different property of 'Graphics grfx = Graphics.FromHdc(test);'
2.Working thumbnails has "IsVisibleClipEmpty" property set to false, while blank ones are true values.
Screenshot: http://snpr.cm/vGytAV.jpg
3.Function returns in this line each time it crashes:
Code:
rctForm = Rectangle.Round(grfx.VisibleClipBounds);
Im also curious how did they manage to do it in win7(alt-tab task switcher)? Do you have any clues mighty gurus? What could possibly set the IsVisibleClipEmpty property to true if i can get the handle to the window and see the content with my own eyes? Why is it blind for some windows and then miraculously cured the other second on?
Last edited by qwqwqw12; October 3rd, 2011 at 08:39 AM.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|