R
Rajat Tandon
Hello there,
I am relatively new to the newsgroups and C#. I have never been disappointed
with the groups and always got the prompt replies to my queries.This is yet
another strange issue, I am facing. Please please help me to solve this as
soon as possible.
So here we go ...
I am not able to take the screen shot of the windows form based "Smart
Client" application at run time.This is urgently required for making the
presentation .
Till now I have tried 4 methods...
--------------------------------
1) Using IrfanView software
2) Using Snag-it
3) Using Camtasia_Capture&menumaker
4) Using the program which is given below...
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Reflection;
using Microsoft.Win32 ;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components;
private System.Windows.Forms.Button button1;
int i;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
i=0;
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern bool BitBlt
(
IntPtr hdcDest, // handle to destination DC
int nXDest, // x-coord of destination upper-left corner
int nYDest, // y-coord of destination upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
IntPtr hdcSrc, // handle to source DC
int nXSrc, // x-coordinate of source upper-left corner
int nYSrc, // y-coordinate of source upper-left corner
System.Int32 dwRop // raster operation code
);
private void Capture_Screen(string filename)
{
Graphics g1 = this.CreateGraphics();
Image MyImage = new Bitmap(this.ClientRectangle.Width,
this.ClientRectangle.Height, g1);
MyImage = new Bitmap(this.ClientRectangle.Width,
this.ClientRectangle.Height, g1);
Graphics g2 = Graphics.FromImage(MyImage);
IntPtr dc1 = g1.GetHdc();
IntPtr dc2 = g2.GetHdc();
BitBlt(dc2, 0, 0, this.ClientRectangle.Width,
this.ClientRectangle.Height, dc1, 0, 0, 13369376);
g1.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);
MyImage.Save(@"d:\rajat\screen_captures\" + filename + ".jpg"
,System.Drawing.Imaging.ImageFormat.Jpeg);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// button1
//
this.button1.Location = new System.Drawing.Point(80, 32);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(232, 101);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
this.Hide();
}
private void Connecticon_Click(object sender, System.EventArgs e)
{
}
private void timer1_Tick(object sender, System.EventArgs e)
{
string filename;
try
{
i=i+1;
filename= "img" + i.ToString() ;
Capture_Screen(filename);
}
catch(Exception exx)
{
MessageBox.Show(exx.Message.ToString());
this.Dispose();
Application.Exit();
}
}
private void button1_Click(object sender, System.EventArgs e)
{
}
}
}
Problem Description
----------------------
These programs are taking the screenshots of the wallpaper behind the
windows application along with the mouse cursor .So it is apparent that
mouse is clicking on the particular points of screen where menus or button
exist in my application but doesn't take the screen shot of form. Isn't it
strange? Also these programs are taking the snapshot of other windows based
application.
I am able to take the snapshot of my application (which is not visible to
above programs) using "PrintScreen" and pasting it in the paint.Also I am
able to take the snapshots of some of the forms of application (using above
4 programs), which have a label to display the message and some background
image setup at runtime.
Let me tell you that my windows application uses the skins which can be
changed dynamically using XML and there are few background images setup at
runtime for the forms. I think that the problem is because of some property
of the application or windows form.
I believe that I have described the problem well enough to understand. Now
the ball is in your court. Please help me..........
Regards,
Rajat Tandon.
A DotNet Learner.
I am relatively new to the newsgroups and C#. I have never been disappointed
with the groups and always got the prompt replies to my queries.This is yet
another strange issue, I am facing. Please please help me to solve this as
soon as possible.
So here we go ...
I am not able to take the screen shot of the windows form based "Smart
Client" application at run time.This is urgently required for making the
presentation .
Till now I have tried 4 methods...
--------------------------------
1) Using IrfanView software
2) Using Snag-it
3) Using Camtasia_Capture&menumaker
4) Using the program which is given below...
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Reflection;
using Microsoft.Win32 ;
using System.Runtime.InteropServices;
namespace WindowsApplication1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Timer timer1;
private System.ComponentModel.IContainer components;
private System.Windows.Forms.Button button1;
int i;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
i=0;
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern bool BitBlt
(
IntPtr hdcDest, // handle to destination DC
int nXDest, // x-coord of destination upper-left corner
int nYDest, // y-coord of destination upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
IntPtr hdcSrc, // handle to source DC
int nXSrc, // x-coordinate of source upper-left corner
int nYSrc, // y-coordinate of source upper-left corner
System.Int32 dwRop // raster operation code
);
private void Capture_Screen(string filename)
{
Graphics g1 = this.CreateGraphics();
Image MyImage = new Bitmap(this.ClientRectangle.Width,
this.ClientRectangle.Height, g1);
MyImage = new Bitmap(this.ClientRectangle.Width,
this.ClientRectangle.Height, g1);
Graphics g2 = Graphics.FromImage(MyImage);
IntPtr dc1 = g1.GetHdc();
IntPtr dc2 = g2.GetHdc();
BitBlt(dc2, 0, 0, this.ClientRectangle.Width,
this.ClientRectangle.Height, dc1, 0, 0, 13369376);
g1.ReleaseHdc(dc1);
g2.ReleaseHdc(dc2);
MyImage.Save(@"d:\rajat\screen_captures\" + filename + ".jpg"
,System.Drawing.Imaging.ImageFormat.Jpeg);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// timer1
//
this.timer1.Enabled = true;
this.timer1.Interval = 1000;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// button1
//
this.button1.Location = new System.Drawing.Point(80, 32);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(232, 101);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
this.Hide();
}
private void Connecticon_Click(object sender, System.EventArgs e)
{
}
private void timer1_Tick(object sender, System.EventArgs e)
{
string filename;
try
{
i=i+1;
filename= "img" + i.ToString() ;
Capture_Screen(filename);
}
catch(Exception exx)
{
MessageBox.Show(exx.Message.ToString());
this.Dispose();
Application.Exit();
}
}
private void button1_Click(object sender, System.EventArgs e)
{
}
}
}
Problem Description
----------------------
These programs are taking the screenshots of the wallpaper behind the
windows application along with the mouse cursor .So it is apparent that
mouse is clicking on the particular points of screen where menus or button
exist in my application but doesn't take the screen shot of form. Isn't it
strange? Also these programs are taking the snapshot of other windows based
application.
I am able to take the snapshot of my application (which is not visible to
above programs) using "PrintScreen" and pasting it in the paint.Also I am
able to take the snapshots of some of the forms of application (using above
4 programs), which have a label to display the message and some background
image setup at runtime.
Let me tell you that my windows application uses the skins which can be
changed dynamically using XML and there are few background images setup at
runtime for the forms. I think that the problem is because of some property
of the application or windows form.
I believe that I have described the problem well enough to understand. Now
the ball is in your court. Please help me..........
Regards,
Rajat Tandon.
A DotNet Learner.