Hi umesh,
Windows CE doesn't support those functions. Here is the code that you need to make a button take a picture of the screen. Windows CE also does not use letters for drive names, 'C:\' will not work. Where do you want to put the image once you have taken it?
Mark
Code:
//--------------------------------------------------------------
// Press F1 to get help about using script.
// To access an object that is not located in the current class, start the call with Globals.
// When using events and timers be cautious not to generate memoryleaks,
// please see the help for more information.
//---------------------------------------------------------------
namespace Neo.ApplicationFramework.Generated
{
using System.Windows.Forms;
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using Neo.ApplicationFramework.Tools;
using Neo.ApplicationFramework.Common.Graphics.Logic;
using Neo.ApplicationFramework.Controls;
using Neo.ApplicationFramework.Interfaces;
public partial class Screen1
{
// imports the GDI BitBlt function that enables the background of the window
// to be captured
[DllImport("coredll.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
);
[DllImport("coredll.dll")]
public extern static System.IntPtr GetDC(System.IntPtr hWnd);
[DllImport("coredll.dll")]
public extern static int ReleaseDC(System.IntPtr hWnd, System.IntPtr hDC); //modified to include hWnd
void Button1_Click(System.Object sender, System.EventArgs e)
{
CaptureForm();
}
private void CaptureForm ()
{
// Get the handle of the form's device context and create compatible
// graphics and bitmap objects
//
System.IntPtr srcDC = GetDC (IntPtr.Zero);
System.Drawing.Bitmap bm = new System.Drawing.Bitmap (this.Width, this.Height);
System.Drawing.Graphics graphics = System.Drawing.Graphics.FromImage (bm);
// Get the handle to the graphics object's device context.
//
System.IntPtr bmDC = graphics.GetHdc ();
// Copy the form to the bitmap
//
BitBlt (bmDC, 0, 0, bm.Width, bm.Height, srcDC, 0, 0, 0x00CC0020 /*SRCCOPY*/);
// Release native resources
//
ReleaseDC (IntPtr.Zero, srcDC);
graphics.ReleaseHdc (bmDC);
graphics.Dispose ();
// Save the bitmap in jpeg format.
//Directory where you want the image. In this case
//it will be saved to the external memory card.
string directory = @"\Storage Card2";
string datePatt = @"M_d_yyyy hh_mm_ss tt";
string dateNow = DateTime.Now.ToString(datePatt);
string filename = String.Format (@"{0}\Snap {1}.jpg", directory, dateNow);
try
{
bm.Save (filename, System.Drawing.Imaging.ImageFormat.Jpeg);
}
catch (Exception x)
{
System.Diagnostics.Debug.WriteLine (x);
}
}
}
}