Capture control as image when running in background

A

aledrjones

Hi

I've got a c# application that will often run in the background as it
is used to monitor connections to a host.

An activex control displays the communication between the app and the
host. When the host disconnects the app, I want to take a screen shot
of the active x control.

Two methods I've tried have worked, one using key commands to trigger a
print screen on the form, and another uses BitBlt to grab a specific
rectangle of the form. However both have the drawbacks that they do
not work properly when the application is not in the foreground. The
first method captures the active window, the second captures the right
area but whatever windows that are in front of the app will obscure it.

First method
example:http://www.cornetdesign.com/2005/04/screen-print-capture-in-c-using_08.html

Second method example:
http://groups.google.co.uk/group/mi...c#+control+save+image&rnum=2#cfc5cc70953c86b2

Any ideas? I've had a look here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnnetcomp/html/scibf.asp
but it looks very complicated.

Cheers
Al
 
G

Guest

Hi Al,

As you are talking about an ActiveX control, I assume that it is an
unmanaged control.
You can expose a Public property of the control called pic which will return
a bitmap image
of the DC (If VC++ is used) or Image (If VB6 is used). Now, when a condition
occurs you read
the pic property & assign it to a picture. If you are using a .Net
component, you can grab e.graphics
of the component DC & return as a bitmap.

Hope this helps.
 
A

aledrjones

Thanks for the reply Radhakrishna.

The control doesn't seem to have a pic property. The closest thing to
what you're saying I have is the CreateGraphics method. I'm using C#
..NET.

Could you give an example please?

Does this method create the bitmap correctly regardless if the control
is in the foreground?

Thanks again

Aled
 
A

aledrjones

Just to update. I've used the following code to grab the screen which
works well.
Graphics g = this.CreateGraphics();
Size s = this.Size;
Image myImg = new Bitmap(s.Width, s.Height, g);
Graphics g2 = Graphics.FromImage(myImg);

IntPtr dc1 = g.GetHdc();
IntPtr dc2 = g2.GetHdc();

BitBlt(dc2, 0, 0, this.ClientRectangle.Width,
this.ClientRectangle.Height, dc1, 0, 0, SRCCOPY);
g.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);

myImg.Save(aFilename +
".jpg",System.Drawing.Imaging.ImageFormat.Jpeg);

However, it still doesn't get round the background procress problem.
If any window is in front of it, it grabs an app sized grab of that
instead.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top