| Text Capture Library COM Server Quick Tutorial - Visual C++ Sample |
Download the source code for this article: VCSample.zip More samples...
SUMMARY
The following section illustrates how you can create an MFC project and import Text Capture Library as a COM server and capture text from mouse pointed window(ie. Explore of "My Computer").
|
1. |
With Microsoft Developer Studio, start a new "MFC AppWizard (exe)" project named "TcServerSampleApp." |
|
2. |
In step 1 of the MFC AppWizard, choose "Dialog Based" for the application type and then click Finish. |
| The New Project Information dialog box appears and indicates that the Classes to be created include: | |
| Application: CTcServerSampleApp in TcServerSample.h and TcServerSample.cpp Dialog: CTcServerSampleDlg in TcServerSampleDlg.h and TcServerSampleDlg.cpp | |
|
Click OK to create the project. | |
| 3. | The Dialog box "IDD_TCSERVERSAMPLE_DIALOG" opens in the Visual Studio design/edit area. Modify it according to the instructions in the next two steps. |
| 4. | Remove the Label control (IDC_STATIC) and the Cancel button (IDCANCEL). |
| 5. | Change the name of the OK button to "IDC_GETTEXT_BUTTON" and the caption to "Capture It!." Close the dialog box design form. |
| 6. | Click ClassWizard on the View menu (or press CTRL+W). |
| 7. | Select the Message Maps tab. Select
IDC_GETTEXT_BUTTONin
the Object Ids list box and select "BN_CLICKED" in the Messages list box.
Click Add Function and accept the function name "OnGetTextButton". Click OK to close
the ClassWizard. NOTE: This step adds a declaration for the function member "OnGetTextButton();" to the header file named TcServerSampleDlg.h. This step also adds an empty skeleton message handler function named CTcServerSampleDlg ::OnGetTextButton() to the file named TcServerSampleDlg.cpp. |
| 8. | Add the following code at the head of TcServerSampleDlg |
|
|
|
| 9. | Add a public member variable to the class
CTcServerSampleDlg, varialble type is TextCaptureLib::ITextCapturePtr, vairalble name is
m_pTextCapture:
public: |
| 10. | Add the following code to the CTcServerSampleDlg::OnInitDialog() so that it appears as shown below: |
| 11. |
// NOTE: Make sure to initialize COM before trying to create the Text capture COM library object. |
| 12. | Add the following code to the CTcServerSampleDlg::OnGetTextButton() so that it appears as shown below: |
|
void CTcServerSampleDlg::OnGetTextButton() |
|
| 13. | Add windows message handler WM_CLOSE to the class CTcServerSampleDlg, select "WM_CLOSE" in the Messages list box. Click Add Function and accept the function name "OnClose". Click OK to close the ClassWizard. |
| Add the following code to the CTcServerSampleDlg::OnClose() so that it appears as shown below: | |
|
| |
| 14. |
Build and run the project. RESULTS: When you click the "Capture It!" button in the dialog box, a message window will popup. If you clicked "OK", 3 seconds after close this message box, the mouse pointed windows will be captured by Text Capture Library and the result will be displayed. |