public RasterImage ShowCaptureFromExeDialog(string fileName,Color transparentColor,ScreenCaptureResourceType resourceType,ScreenCaptureFromExeDialogType dialogType,ScreenCaptureDialogFlags flags,ScreenCaptureInformation captureInformation,ScreenCaptureHelpCallback helpCallback)
fileName
A string containing the name of the exe (or dll) from which the resource will be captured.
transparentColor
A color to be used in place of the transparent color of an Icon or Cursor.
resourceType
Type of resource to be captured. For possible values refer to ScreenCaptureResourceType.
dialogType
Type of dialog to be displayed. For possible values refer to ScreenCaptureFromExeDialogType.
flags
Flags that determine the options dialog. For possible values refer to ScreenCaptureDialogFlags.
captureInformation
A ScreenCaptureInformation class object to be filled with information regarding the source for the captured image. Pass NULL if you are not interested in extra information about the capture.
helpCallback
A delegate method that will handle the event.
A Leadtools.RasterImage that represents the captured image.
using Leadtools;using Leadtools.Codecs;using Leadtools.ScreenCapture;public void ScreenCaptureEngineExample(){// Startup the ScreenCaptureScreenCaptureEngine.Startup();// Define a ScreenCaptureEngine class objectScreenCaptureEngine scEngine = new ScreenCaptureEngine();// Define an EventHandler for CaptureInformationscEngine.CaptureInformation += new EventHandler<ScreenCaptureInformationEventArgs>(scEngine_CaptureInformation);// Define the Help Callback that will run whenever the Help button is pressed on the dialogsScreenCaptureHelpCallback helpCallback = new ScreenCaptureHelpCallback(HelpCallback);// Define ScreenCaptureAreaOptions and fill it using dialogScreenCaptureAreaOptions scAreaOptions = ScreenCaptureAreaOptions.Empty;// Get the default optionsscAreaOptions = 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 dialogScreenCaptureOptions scOptions = ScreenCaptureOptions.Empty;// Set the ScreenCaptureHotKeyCallback, so that it gets called if the hotkey is set in the dialogScreenCaptureHotkeyCallback 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 ScreenCaptureOptionsscEngine.CaptureOptions = scOptions;// Define ScreenCaptureObjectOptions and fill it using dialogScreenCaptureObjectOptions scObjectOptions = ScreenCaptureObjectOptions.Empty;// Get the default OptionsscObjectOptions = 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 objectScreenCaptureInformation 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 screenRasterImage image = scEngine.CaptureArea(scAreaOptions, scInformation);// To get the number of resources in a EXE fileint iconsCount = scEngine.GetResourcesCount(Path.Combine(LEAD_VARS.ImagesDir, "ExeWithResources.exe"), ScreenCaptureResourceType.Icon);// Finally, if the Capture is still active, then Stop itif (scEngine.IsCaptureActive)scEngine.StopCapture();// clean upimage.Dispose();// Shutdown the ScreenCaptureScreenCaptureEngine.Shutdown();}bool HotKeyCallback(Keys key){// Here you can do anything with the pressed key// we will just show a message boxMessageBox.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 herebreak;}}void scEngine_CaptureInformation(object sender, ScreenCaptureInformationEventArgs e){// Make sure that the image was captured successfullyDebug.Assert(e.Image != null);// Define codecs class object to save the imageRasterCodecs codecs = new RasterCodecs();codecs.ThrowExceptionsOnInvalidImages = true;// Save the resulted Imagecodecs.Save(e.Image, Path.Combine(LEAD_VARS.ImagesDir, "Out_CapturedImage.bmp"), RasterImageFormat.Bmp, 24);// 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 areaMessageBox.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 finee.Cancel = false;}static class LEAD_VARS{public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images";}