Leadtools.ScreenCapture Send comments on this topic. | Back to Introduction - All Topics | Help Version 16.5.9.25
ScreenCaptureEngine Class
See Also  Members   Example 
Leadtools.ScreenCapture Namespace : ScreenCaptureEngine Class



The main class for the Screen Capture Engine.

Object Model




Syntax

Visual Basic (Declaration) 
Public Class ScreenCaptureEngine 
Visual Basic (Usage)Copy Code
Dim instance As ScreenCaptureEngine
C# 
public class ScreenCaptureEngine 
C++/CLI 
public ref class ScreenCaptureEngine 

Example

Defines screen capture structures, and class objects, captures an area of the screen, and then counts the number of resources in a EXE file

Visual BasicCopy Code
WithEvents scEngine As ScreenCaptureEngine
Public Sub ScreenCaptureEngineExample()
   ' Startup the ScreenCapture
   ScreenCaptureEngine.Startup()

   ' Define a ScreenCaptureEngine class object
   scEngine = New ScreenCaptureEngine()

   ' Define the Help Callback that will run whenever the Help button is pressed on the dialogs
   Dim helpCallbackObj As New ScreenCaptureHelpCallback(AddressOf HelpCallback)

   ' Define ScreenCaptureAreaOptions and fill it using dialog
   Dim scAreaOptions As ScreenCaptureAreaOptions
   scAreaOptions = ScreenCaptureAreaOptions.Empty

   ' Get the default options
   scAreaOptions = ScreenCaptureEngine.DefaultCaptureAreaOptions

   ' Open the dialog allowing the user to change the values
   ' NOTE: To fill the structure manually, you can write:
   ' Cursor drawCursor = Cursors.Cross;
   ' scAreaOptions.AreaType = ScreenCaptureAreaType.Rectangle;
   ' scAreaOptions.DrawCursor = drawCursor;
   ' scAreaOptions.DrawLineColor = Color.Red;
   ' scAreaOptions.DrawLineStyle = ScreenCaptureAreaLineStyle.Solid;
   ' scAreaOptions.EllipseHeight = 0;
   ' scAreaOptions.EllipseWidth = 0;
   ' scAreaOptions.FillBackgroundColor = Color.Black;
   ' scAreaOptions.FillForegroundColor = Color.White;
   ' scAreaOptions.FillPattern = ScreenCaptureAreaFillPattern.Solid;
   ' scAreaOptions.Flags = ScreenCaptureAreaFlags.ShowInfoWindow;
   ' scAreaOptions.InfoWindowBounds = new Rectangle(ScreenCaptureAreaOptions.LeftInfoWindowPosition, ScreenCaptureAreaOptions.TopInfoWindowPosition, ScreenCaptureAreaOptions.MediumInfoWindowSize, ScreenCaptureAreaOptions.MediumInfoWindowSize);
   ' scAreaOptions.TextBackgroundColor = Color.White;
   ' scAreaOptions.TextForegroundColor = Color.Black;
   ' scAreaOptions.Zoom = ScreenCaptureAreaZoom.Normal;
   scEngine.ShowCaptureAreaOptionsDialog(Nothing, ScreenCaptureDialogFlags.CaptureAreaOptionsContextHelp, scAreaOptions, True, helpCallbackObj)

   ' Define ScreenCaptureOptions and fill it using dialog
   Dim scOptions As ScreenCaptureOptions
   scOptions = ScreenCaptureOptions.Empty

   ' Set the ScreenCaptureHotKeyCallback, so that it gets called if the hotkey is set in the dialog
   Dim hotkeyCallbackObj As New ScreenCaptureHotkeyCallback(AddressOf HotKeyCallback)
   ScreenCaptureEngine.SetCaptureHotkeyCallback(hotkeyCallbackObj)

   ' Open the dialog allowing the user to change the values
   ' NOTE: To fill the structure manually, you can write:
   ' scOptions.CancelKey = Keys.Escape;
   ' scOptions.Count = 1;
   ' scOptions.Cursor = Cursors.Arrow;
   ' scOptions.Delay = 0;
   ' scOptions.Hotkey = Keys.F11;
   ' scOptions.Interval = 0;
   ' scOptions.OptimizedHotkey = true;
   ' scOptions.StatusCursor = Cursors.WaitCursor;
   scEngine.ShowCaptureOptionsDialog(Nothing, ScreenCaptureDialogFlags.SetCaptureOptionsContextHelp, scOptions, helpCallbackObj)

   ' Set the Engine's ScreenCaptureOptions
   scEngine.CaptureOptions = scOptions

   ' Define ScreenCaptureObjectOptions and fill it using dialog
   Dim scObjectOptions As ScreenCaptureObjectOptions
   scObjectOptions = ScreenCaptureObjectOptions.Empty

   ' Get the default Options
   scObjectOptions = ScreenCaptureEngine.DefaultCaptureObjectOptions

   ' Open the dialog allowing the user to change the values
   ' NOTE: To fill the structure manually, you can write:
   ' scObjectOptions.BorderWidth = 2;
   ' scObjectOptions.EnableKeyboard = true;
   ' scObjectOptions.Invert = false;
   ' scObjectOptions.SelectCursor = Cursors.Arrow;
   scEngine.ShowCaptureObjectOptionsDialog(Nothing, ScreenCaptureDialogFlags.CaptureObjectOptionsContextHelp, scObjectOptions, True, helpCallbackObj)

   ' Define ScreenCaptureInformation class object
   Dim scInformation As ScreenCaptureInformation = Nothing

   ' NOTE: After preparing the structures and classes,
   ' in this place you can insert any Capture method, such as:
   ' CaptureWindow, CaptureActiveWindow, CaptureActiveClient, CaptureWallpaper,
   ' CaptureFullScreen, CaptureMenuUnderCursor, CaptureWindowUnderCursor,
   ' CaptureSelectedObject, CaptureArea, CaptureMouseCursor

   ' We will Capture an Area of the screen
   Dim image As RasterImage
   image = scEngine.CaptureArea(scAreaOptions, scInformation)

   ' To get the number of resources in a EXE file
   Dim iconsCount As Integer
     iconsCount = scEngine.GetResourcesCount(LeadtoolsExamples.Common.ImagesPath.Path + "ExeWithResources.exe", ScreenCaptureResourceType.Icon)

     ' Finally, if the Capture is still active, then Stop it
     If (scEngine.IsCaptureActive) Then
         scEngine.StopCapture()
     End If

     ' clean up
     image.Dispose()

     ' Shutdown the ScreenCapture
     ScreenCaptureEngine.Shutdown()
 End Sub

 Public Function HotKeyCallback(ByVal key As Keys) As Boolean
     ' Here you can do anything with the pressed key
     ' we will just show a message box
     MessageBox.Show("You pressed the " + key.ToString() + "character.")

     Return True
 End Function

 Public Sub HelpCallback(ByVal helpType As ScreenCaptureHelpType, ByVal controlId As ScreenCaptureControlId)
     ' Show a MessageBox mentioning the name of the dialog that called the help,
     ' and which control ID was requested.
     Select Case (helpType)
         Case ScreenCaptureHelpType.CaptureAreaOptions
             MessageBox.Show("Capture Area Options Dialog Help Button" & Environment.NewLine & "Control Id: " & controlId.ToString() & ".")
         Case ScreenCaptureHelpType.CaptureFromExe
             MessageBox.Show("Capture From EXE Dialog Help Button" & Environment.NewLine & "Control Id: " & controlId.ToString() & ".")
         Case ScreenCaptureHelpType.CaptureObjectOptions
             MessageBox.Show("Capture Object Options Dialog Help Button" & Environment.NewLine & "Control Id: " & controlId.ToString() & ".")
         Case ScreenCaptureHelpType.SetCaptureOptions
             MessageBox.Show("Capture Options Dialog Help Button" & Environment.NewLine & "Control Id: " & controlId.ToString() & ".")
         Case Else
             ' will never reach here
     End Select
 End Sub

 Public Sub scEngine_CaptureInformation(ByVal sender As Object, ByVal e As ScreenCaptureInformationEventArgs) Handles scEngine.CaptureInformation

     ' Define codecs class object to save the image
     RasterCodecs.Startup()
     Dim codecs As New RasterCodecs()
     codecs.ThrowExceptionsOnInvalidImages = True

     ' Save the resulted Image
     codecs.Save(e.Image, LeadtoolsExamples.Common.ImagesPath.Path + "CapturedImage.bmp", RasterImageFormat.Bmp, 24)

     RasterCodecs.Shutdown()

     ' NOTE: e.Information is a ScreenCaptureInformation structure filled with information
     ' about the captured image, this information can be used here
     ' Display a MessageBox with the bounds of the capture area
     MessageBox.Show("Captured Area Bounds:" & Environment.NewLine & "Top:" & e.Information.Area.Top.ToString() & Environment.NewLine & "Left:" & e.Information.Area.Left.ToString() & Environment.NewLine & "Right:" + e.Information.Area.Right.ToString() & Environment.NewLine & "Bottom:" & e.Information.Area.Bottom.ToString())

     ' everything worked fine
     e.Cancel = False
 End Sub
C#Copy Code
public void ScreenCaptureEngineExample() 

   // Startup the ScreenCapture 
   ScreenCaptureEngine.Startup(); 
 
   // Define a ScreenCaptureEngine class object 
   ScreenCaptureEngine scEngine = new ScreenCaptureEngine(); 
 
   // Define an EventHandler for CaptureInformation 
   scEngine.CaptureInformation += new EventHandler<ScreenCaptureInformationEventArgs>(scEngine_CaptureInformation); 
 
   // Define the Help Callback that will run whenever the Help button is pressed on the dialogs 
   ScreenCaptureHelpCallback helpCallback = new ScreenCaptureHelpCallback(HelpCallback); 
 
   // Define ScreenCaptureAreaOptions and fill it using dialog 
   ScreenCaptureAreaOptions scAreaOptions = ScreenCaptureAreaOptions.Empty; 
   // Get the default options 
   scAreaOptions = ScreenCaptureEngine.DefaultCaptureAreaOptions; 
   // Open the dialog allowing the user to change the values 
   // NOTE: To fill the structure manually, you can write: 
   // Cursor drawCursor = Cursors.Cross; 
   // scAreaOptions.AreaType = ScreenCaptureAreaType.Rectangle; 
   // scAreaOptions.DrawCursor = drawCursor; 
   // scAreaOptions.DrawLineColor = Color.Red; 
   // scAreaOptions.DrawLineStyle = ScreenCaptureAreaLineStyle.Solid; 
   // scAreaOptions.EllipseHeight = 0; 
   // scAreaOptions.EllipseWidth = 0; 
   // scAreaOptions.FillBackgroundColor = Color.Black; 
   // scAreaOptions.FillForegroundColor = Color.White; 
   // scAreaOptions.FillPattern = ScreenCaptureAreaFillPattern.Solid; 
   // scAreaOptions.Flags = ScreenCaptureAreaFlags.ShowInfoWindow; 
   // scAreaOptions.InfoWindowBounds = new Rectangle(ScreenCaptureAreaOptions.LeftInfoWindowPosition, ScreenCaptureAreaOptions.TopInfoWindowPosition, ScreenCaptureAreaOptions.MediumInfoWindowSize, ScreenCaptureAreaOptions.MediumInfoWindowSize); 
   // scAreaOptions.TextBackgroundColor = Color.White; 
   // scAreaOptions.TextForegroundColor = Color.Black; 
   // scAreaOptions.Zoom = ScreenCaptureAreaZoom.Normal; 
   scEngine.ShowCaptureAreaOptionsDialog(null, ScreenCaptureDialogFlags.CaptureAreaOptionsContextHelp, scAreaOptions, true, helpCallback); 
 
   // Define ScreenCaptureOptions and fill it using dialog 
   ScreenCaptureOptions scOptions = ScreenCaptureOptions.Empty; 
   // Set the ScreenCaptureHotKeyCallback, so that it gets called if the hotkey is set in the dialog 
   ScreenCaptureHotkeyCallback hotkeyCallback = new ScreenCaptureHotkeyCallback(HotKeyCallback); 
   ScreenCaptureEngine.SetCaptureHotkeyCallback(hotkeyCallback); 
   // Open the dialog allowing the user to change the values 
   // NOTE: To fill the structure manually, you can write: 
   // scOptions.CancelKey = Keys.Escape; 
   // scOptions.Count = 1; 
   // scOptions.Cursor = Cursors.Arrow; 
   // scOptions.Delay = 0; 
   // scOptions.Hotkey = Keys.F11; 
   // scOptions.Interval = 0; 
   // scOptions.OptimizedHotkey = true; 
   // scOptions.StatusCursor = Cursors.WaitCursor; 
   scEngine.ShowCaptureOptionsDialog(null, ScreenCaptureDialogFlags.SetCaptureOptionsContextHelp, scOptions, helpCallback); 
   // Set the Engine's ScreenCaptureOptions 
   scEngine.CaptureOptions = scOptions; 
 
   // Define ScreenCaptureObjectOptions and fill it using dialog 
   ScreenCaptureObjectOptions scObjectOptions = ScreenCaptureObjectOptions.Empty; 
   // Get the default Options 
   scObjectOptions = ScreenCaptureEngine.DefaultCaptureObjectOptions; 
   // Open the dialog allowing the user to change the values 
   // NOTE: To fill the structure manually, you can write: 
   // scObjectOptions.BorderWidth = 2; 
   // scObjectOptions.EnableKeyboard = true; 
   // scObjectOptions.Invert = false; 
   // scObjectOptions.SelectCursor = Cursors.Arrow; 
   scEngine.ShowCaptureObjectOptionsDialog(null, ScreenCaptureDialogFlags.CaptureObjectOptionsContextHelp, scObjectOptions, true, helpCallback); 
 
   // Define ScreenCaptureInformation class object 
   ScreenCaptureInformation scInformation = null; 
 
   // NOTE: After preparing the structures and classes, 
   // in this place you can insert any Capture method, such as: 
   // CaptureWindow, CaptureActiveWindow, CaptureActiveClient, CaptureWallpaper, 
   // CaptureFullScreen, CaptureMenuUnderCursor, CaptureWindowUnderCursor, 
   // CaptureSelectedObject, CaptureArea, CaptureMouseCursor 
 
   // We will Capture an Area of the screen 
   RasterImage image = scEngine.CaptureArea(scAreaOptions, scInformation); 
 
   // To get the number of resources in a EXE file 
   int iconsCount = scEngine.GetResourcesCount(LeadtoolsExamples.Common.ImagesPath.Path + "ExeWithResources.exe", ScreenCaptureResourceType.Icon); 
 
   // Finally, if the Capture is still active, then Stop it 
   if (scEngine.IsCaptureActive) 
      scEngine.StopCapture(); 
 
   // clean up 
   image.Dispose(); 
 
   // Shutdown the ScreenCapture 
   ScreenCaptureEngine.Shutdown(); 

 
bool HotKeyCallback(Keys key) 

   // Here you can do anything with the pressed key 
   // we will just show a message box 
   MessageBox.Show("You pressed the " + key.ToString() + "character."); 
 
   return true; 

 
void HelpCallback(ScreenCaptureHelpType helpType, ScreenCaptureControlId controlId) 

   // Show a MessageBox mentioning the name of the dialog that called the help, 
   // and which control ID was requested. 
   switch(helpType) 
   { 
      case ScreenCaptureHelpType.CaptureAreaOptions: 
         MessageBox.Show("Capture Area Options Dialog Help Button\n" +  
            "Control Id: " + controlId.ToString() + "."); 
         break; 
      case ScreenCaptureHelpType.CaptureFromExe: 
         MessageBox.Show("Capture From EXE Dialog Help Button\n" + 
            "Control Id: " + controlId.ToString() + "."); 
         break; 
      case ScreenCaptureHelpType.CaptureObjectOptions: 
         MessageBox.Show("Capture Object Options Dialog Help Button\n" + 
            "Control Id: " + controlId.ToString() + "."); 
         break; 
      case ScreenCaptureHelpType.SetCaptureOptions: 
         MessageBox.Show("Capture Options Dialog Help Button\n" + 
            "Control Id: " + controlId.ToString() + "."); 
         break; 
      default: 
         // will never reach here 
         break; 
   } 

 
void scEngine_CaptureInformation(object sender, ScreenCaptureInformationEventArgs e) 

   // Make sure that the image was captured successfully 
   Debug.Assert(e.Image != null); 
 
   // Define codecs class object to save the image 
   RasterCodecs.Startup(); 
   RasterCodecs codecs = new RasterCodecs(); 
   codecs.ThrowExceptionsOnInvalidImages = true; 
 
   // Save the resulted Image 
   codecs.Save(e.Image, LeadtoolsExamples.Common.ImagesPath.Path + "CapturedImage.bmp", RasterImageFormat.Bmp, 24); 
 
   RasterCodecs.Shutdown(); 
 
   // NOTE: e.Information is a ScreenCaptureInformation structure filled with information 
   // about the captured image, this information can be used here 
   // Display a MessageBox with the bounds of the capture area 
   MessageBox.Show("Captured Area Bounds:\n" + 
      "Top:" + e.Information.Area.Top.ToString() + "\n" + 
      "Left:" + e.Information.Area.Left.ToString() + "\n" + 
      "Right:" + e.Information.Area.Right.ToString() + "\n" + 
      "Bottom:" + e.Information.Area.Bottom.ToString()); 
 
   // everything worked fine 
   e.Cancel = false; 
}

Inheritance Hierarchy

System.Object
   Leadtools.ScreenCapture.ScreenCaptureEngine

Requirements

Target Platforms: Microsoft .NET Framework 2.0, Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also