Capturing an Active Window (Visual Basic 5 and later)
Take the following steps to start a project and to add some code that captures the active window and displays the image.
1. |
Start Visual Basic, select the Standard EXE, and click "Open". |
2. |
Add the LEAD Raster View Control to your project. |
|
On the Project pull-down menu, use the Components option, and select the LEAD Raster View Control(14.5). |
3. |
Select the LEAD Raster View; then add the control to your main form. Size and position the control as you want it to appear at run time. |
4. |
Add the LEAD Raster Screen Capture Object to your project. |
|
On the Project pull-down menu, use the References option, and select the LEAD Raster Screen Capture Object (14.5). |
5. |
Add the following declaration to the General section at the top of the main form's code window. |
Dim WithEvents LEADRasterScr1 As LEADRasterScr
6. |
Code the Form_Load procedure as follows: |
Private Sub Form_Load()
Set LEADRasterScr1 = New LEADRasterScr
End Sub
7. |
Add a command button and name it as follows: |
|
|
Name |
Caption |
|
CapWin |
Capture Window |
8. |
Code the CapWin_Click procedure as follows: |
Private Sub CapWin_Click()
'set the hot key to F10
LEADRasterScr1.CaptureHotKey = 121
LEADRasterScr1.CaptureDelay = 3000
LEADRasterScr1.CaptureActiveWindow
LEADRasterView1.Raster.Bitmap = LEADRasterScr1.Bitmap
End Sub
9. |
Code the Form_Unload procedure as follows: |
Private Sub Form_Unload(Cancel As Integer)
LEADRasterScr1.StopCapture
End Sub
10. |
Run your program to test it. Click the "Capture Window" button, select the window you wish to capture then press F10 and wait for 3 seconds. |
11. |
Save the project to use as a starting point for other tasks in this tutorial. |
12. |
To set the hot key to Alt + F10, substitute the following two lines for |
LEADRasterScr1.CaptureHotKey = 121:
LEADRasterScr1.CaptureHotKey = vbKeyF10
LEADRasterScr1.CaptureHotKeyModifiers = SCR_MOD_ALT
' To use Control + F10, set the CaptureHotKeyModifiers to SCR_MOD_CONTROL
' To use Shift + F10, set the CaptureHotKeyModifiers to SCR_MOD_SHIFT