In the past I have had requirements to “scrape” the text off of the windows of other applications. I tried many third party applications and none of them fit the bill except SnagIt from TechSmith.com. The hardest part of this feat was getting SnagIt configured correctly!
SnagIt enhances the functionalities
of the Print Screen key: it captures a screen shot then allows the
user to add annotations or to improve to the captured image with its image
editor. Actually, it can capture a rectangular shape anywhere on your desktop
and can capture the contents of a window, including the part not seen.
Using
SnagIt as a DDE Server
SnagIt is a fully functional Windows
Dynamic Data Exchange (DDE) server. You can use SnagIt’s DDE support to
incorporate SnagIt functionality into custom or commercial Windows programs
that support DDE. For example, you could write a Microsoft Excel macro
to print a portion of the screen using SnagIt. Some of the parameters used
are addressed in the TechSmith’s DDE Server guide.
Specifics
for my example
Install SnagIt either the normal
way by executing the setup application or programmatically. You can install
programmatically and silently with:
{PathToSetup}\snagit.exe /S /M={PathToSetup}\instvar.txt |
|
MAINDIR=C:\Program Files\TechSmith\SnagIt // or whatever directory you choose DESKTOP_LINK= START_AUTO= START_MINI= VIEW_README= START_NOW= START_NOW2= SHORTCUT_TYPE= |
|
REGEDIT4 [HKEY_CURRENT_USER\Software\TechSmith\SnagIt\6\Profiles\MyProfile]
[HKEY_LOCAL_MACHINE\Software\TechSmith\SnagIt\6]
|
|
First and foremost, your application
needs to know if and where SnagIt is installed on the workstation. You
must delve into the registry (programmatically, of course) and see where
it is installed. The standard location for TechSmith applications is
HKLM\Software\TechSmith.
Within that key should be SnagIt, and under that key should be the version.
So initially, the code would be:
try private reg reg = new registry(hkey_local_machine,"Software\TechSmith\SnagIt\6") _app.snagitlocation = reg.queryvalue("GlobalInstallPath") if not reg.error == 0 // SnagIt is not installed _app.snagitlocation := 'no snagit application' endif catch (exception e) _app.snagitlocation = 'no snagit application' endtry |
|
At this point, if you have a value
in the variable _app.snagitlocation besides
'no snagit application' then SnagIt is installed and it is version 6 and
the pointer to the application is located in the variable
_app.snagitlocation.
Setting
up SnagIt and make sure it is running
SnagIt can be set up with many profiles, whereas, based on which keys are pressed they will do whatever function is assigned to it. For this example, we are going to use a profile called MyProfile.
We are going to do four things in this segment:
if file(_app.snagitlocation) // The SnagIt program exists so lets check and reset the registry reg = new registry(hkey_current_user,"Software\TechSmith\SnagIt\6\Profiles\MyProfile") if reg.error == 0 private r,rv,regsetting,regtest,newregvalue,snagitprofile rv = "Software\TechSmith\SnagIt\6\Profiles" r = new registry(hkey_current_user,rv) regsetting = "ProfileList" regtest = r.queryvalue(regsetting) if not "MyProfile" $ alltrim(upper(regtest)) newregvalue = regtest + "MyProfile*" checksetreg(r,regsetting,newregvalue) endif // Now lets
check all of the profile parameters and set them if not correct
// Now lets
verify that the profile now exists
// Let's
see if SnagIt is already running
// This
is used for checking SnagIt setup in realtime, since it is not visible
// The SnagIt program does
NOT exist
|
|
[SnagIt] Row=7 // this is the form identifier row number Column=89 // this is the form identifier column number Width=4 // this is the form identifier width PrimaryWidth=14 // this is the default width primaryRow=8 // this is the default row number primaryColumn=53 // this is the default column number [CA12]
// this segment is for a form identified as CA12
|
|
The purpose of the F8Trigger() procedure is to scrape the text off of a predefined window and get text based on X, Y & Z coordinates.
I’ll try to guide you thru all
of its functions:
FUNCTION F8Trigger private snagtest,snagform,snagrow,snagcolumn,snagwidth,snagini,testsfile,snagi store "" to snagtest,snagform // Let's open the configuration
file and find out where to identify the form
// Let's
go back to the top of the scraped text and get the data we are looking
for
|
|