Capturing an Active Window (Visual C++ 5 and later)
Take the following steps to start a project and to add some code that will let you capture an active window.
1. |
Start a new project as follows: |
|
|
Run Microsoft Visual C++ 5.0, select the File >New menu option, and do the following: |
|
|
a. |
Click the Projects tab. |
|
b. |
Select MFC AppWizard (exe) as the project type |
|
c. |
In the Project name text box, specify ScrCap. |
|
d. |
In the Location text box, specify the path of the project. |
|
e. |
Click the OK button. |
2. |
In the Step 1 dialog box, do the following: |
|
|
a. |
Select Dialog based. |
|
b. |
Click the Next button. |
3. |
In the Step 2 of 4 dialog box, do the following: |
|
|
a. |
Ensure that 3D controls is selected. |
|
b. |
Select ActiveX controls. |
|
c. |
Click the Next button. |
4. |
In the Step 3 of 4 dialog box, do the following: |
|
|
a. |
For comments, ensure that Yes, Please is selected. |
|
b. |
For how to use the MFC library, select As a shared DLL. |
|
c. |
Click the Next button. |
5. |
In the Step 4 of 4 dialog box, just click Finish. Read New Project Information, and click OK. (The AppWizard creates the project files and opens the project.) |
|
6. |
Add #import and #include statements to your program so you can access the LEAD COM constants and classes: |
|
|
a. |
In the Project Workspace, click the FileView tab. |
|
b. |
Double-click the tutor files folder to open it. |
|
c. |
Double-click the Header Files folder to open it. |
|
d. |
Double-click the StdAfx.h file to edit it. |
|
e. |
Add the following lines to the end of the file near //{{AFX_INSERT_LOCATION}} (keep in mind, you may have to change the path to where the dll's reside): |
#import "c:\win98\system\ltrvr14n.dll" no_namespace, named_guids
#import "c:\win98\system\ltr14n.dll" no_namespace, named_guids
#import "c:\win98\system\ltrvw14n.ocx" no_namespace, named_guids
#import "c:\win98\system\ltrio14n.dll" no_namespace, named_guids
#import "c:\win98\system\ltrsc14n.dll" no_namespace, named_guids
7. |
Edit the ScrCapDlg.cpp file and insert at the top of the file after the #include statement: |
#include "leadraster.h"
8. |
Add the LEAD Raster View Control (14.5) to your project: |
|
|
a. |
In the Project Workspace, click the ResourceView tab. |
|
b. |
Double-click the ScrCap resources folder to open it. |
|
c. |
Double-click the Dialog folder to open it. |
|
d. |
Double-click IDD_SCRCAP_DIALOG to design the dialog box. |
|
e. |
Select the TODO... text control; then press the Delete key to delete it. |
|
f. |
From the main menu, select Project > Add To Project > Components and controls. |
|
g. |
Select Registered ActiveX controls. |
|
h. |
Double-click the LEAD Raster View Control (14.5) icon. (The Confirm Classes dialog box appears.) |
|
i. |
Ensure that CLEADRasterView, CLEADRaster and CPicture are checked. |
|
j. |
Click OK to complete the selection. Click OK to insert the component. |
|
k. |
Click the LEAD RasterView Control icon; then size and position the control as you want it to appear at run time. |
|
l. |
Use the right mouse button to edit the properties of the new LEAD RasterView Control. |
|
m. |
Change the ID to IDC_LEADRASTERVIEW1. |
9. |
Add a command button and set the ID and Caption properties as follows: |
|
ID |
Caption |
|
IDC_CAPWIN |
Capture Window |
10. |
Edit the ScrCapDlg.h file and change the definition of CScrCapDlg : CDialog by inserting the following lines after DECLARE_MESSAGE_MAP(): |
public:
ILEADRasterScr *m_pLEADRasterScr;
11. |
Do the following to add m_LEADRasterView1 to the ScrCapDlg class and link the variable to the LEAD RasterView control using dynamic data exchange: |
|
|
a. |
Press Ctrl-W. (The MFC ClassWizard dialog box appears.) |
|
b. |
Click the Member Variables tab. |
|
c. |
In the Class Name box, select CScrCapDlg. |
|
d. |
In the Control IDs list, select IDC_LEADRASTERVIEW1. |
|
e. |
Click the Add Variable... button. |
|
f. |
Specify m_LEADRasterView1 as the variable name, and Control as the category. |
|
g. |
Click OK to close the dialog box, and click OK to close the MFC ClassWizard. |
12. |
Edit the ScrCapDlg.cpp file and add the following code to the end of the OnInitDialog function (just before return TRUE): |
//Create the RasterScr object
CoCreateInstance(CLSID_LEADRasterScr, NULL, CLSCTX_ALL, IID_ILEADRasterScr, (void**)&m_pLEADRasterScr);
13. |
Press Ctrl-W to go to the MFC Class Wizard; then do the following: |
|
|
a. |
In the Class name combo box, select CScrCapDlg. |
|
b. |
In the Object IDs list box, select CScrCapDlg. |
|
c. |
In the Messages list box, select WM_DESTROY. |
|
d. |
Click the Add function button. Choose OK for the default function name (OnDestroy). |
|
e. |
Click the Edit Code button to start entering the code. |
|
f. |
Enter new code as follows (just before the CDialog::OnDestroy call): |
m_pLEADRasterScr->StopCapture ();
m_pLEADRasterScr->Release();
14. |
Back in MFC Class Wizard, do the following: |
|
|
a. |
Click the Message Maps tab. |
|
b. |
In the Class Name combo box, select CScrCapDlg. |
|
c. |
In the Object IDs list box, select IDC_CAPWIN. |
|
d. |
In the Messages list box, select BN_CLICKED. |
|
e. |
Click the Add function button. Choose OK for the default function name (OnCapwin). |
|
f. |
Click the Edit Code button and code the OnCapwin procedure as follows: |
void CScrCapDlg::OnCapwin()
{
/* set the hot key to be F10 */
m_pLEADRasterScr->PutCaptureHotKey (121);
m_pLEADRasterScr->PutCaptureDelay (3000);
m_pLEADRasterScr->CaptureActiveWindow ();
m_LEADRasterView1.GetRaster().SetBitmap(m_pLEADRasterScr->GetBitmap ());
}
15. |
On the main menu, select Build> Build ScrCap.exe to build the project. |
16. |
On the main menu, select Build> Execute ScrCap.exe to run the project. Click the Capture Window command button, select the window to capture, press F10 and wait for 3 seconds. |