|
Want to handle where fax files are saved, what they are named, or to
automatically send a fax? The TApdFaxDriverInterface component is what
you need.
First, a little background on the
Async Professional
Fax printer Driver. This printer driver works like most other printer
drivers, it takes the canvas of the printer object and converts it into
something the printer can understand. In our case, it converts it into
an APF file.
When a document is sent to the printer driver, it looks for an
ApdFaxDriverInterface component. If an ApdFaxDriverInterface component
is created prior to the start of the print job, that component will
receive the printer messages. If the component is not present, an
application can be spawned that contains that component.
For 32-bit printer drivers (Microsoft Windows NT/2K/XP) the location
and name of the application to spawn is stored in the Registry. If a
valid entry is in the Registry, that application is spawned when a
document is printed. If no valid entry is found, the APF is saved as C:\DEFAULT.APF.
This spawning feature is not completely reliable under the 16-bit
printer driver environment due to the way Windows implements 16-bit
printer drivers. For this reason, it is best to have the component
created prior to the print job in 16-bit environments (which includes
Windows 95/98/ME). We will discuss this in just a bit.
The Printer Controller application you write is the front-end for the
fax printer driver, which can provide some amazing flexibility and
functionality to your faxing operations. The hook into the driver is the
ApdFaxDriverInterface component. This component only has 2 properties
and 2 events of note. We will look at these events in the sequence in
which they are generated as we create a small example.
- Create a new project
- Drop an ApdFaxDriverInterface component on the form
- Drop an ApdComPort and an ApdSendFax component on the form and set
their properties for a normal send-fax operation.
- Drop an ApdFaxStatus component on the form so you can see what is
happening.
- Define an ApdFaxDriverInterface.OnDocStart event through the
Object Inspector and add the following:
procedure TForm1.ApdFaxDriverInterfaceDocStart(Sender : TObject);
begin
ApdFaxDriverInterface1.FileName := 'C:\FAXFILES\OUTFAX.APF';
end;
Define an ApdFaxDriverInterface.OnDocEnd event through the Object
Inspector and add the following:
procedure TForm1.ApdFaxDriverInterfaceDocEnd(Sender : TObject);
begin
ApdSendFax1.FaxFile := ApdFaxDriverInterface1.FileName;
ApdSendFax1.PhoneNumber := '260 7151';
ApdSendFax1.StartTransmit;
end;
Now for the explanations of what we just did. When the printer driver
starts the conversion process, the OnDocStart event fires and we set the
path and file name of the resulting APF file. Once the printer driver is
done converting and saving the file, the OnDocEnd event fires and we fax
the file from the event handler for this event.
That is all there is for the Printer Controller application itself.
Now we can install this application as the front-end for the printer
driver for Windows NT. The Registry keys are predefined in the
ApFaxCC.PAS unit, so you will have to include that file in your unit’s
uses clause. To install the front-end, create a method as shown below.
This method can be called in your install application, or as a result of
a menu or button click in your distributed application. As an
alternative, you can make the changes manually by editing the Registry.
32-bit printer driver (Windows NT/2K/XP):
procedure TForm1.InstallPrinterDriverFrontEnd;
var
Reg : TRegistry;
begin
Reg := TRegistry.Create;
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
Reg.OpenKey(RegKey,True);
Reg.WriteString(IniKey, {Front-end path and file name});
finally
Reg.Free;
end;
end;
As we mentioned earlier, the application spawning mechanism is not
completely reliable in Windows 95/98/ME. For these operating systems,
the recommended approach is to have the application running in the
background so that it can intercept the print jobs. More than likely you
will want your fax application running minimized, hidden, or on the icon
tray on the taskbar. The ApdFaxDriverInterface component will be able to
intercept all print jobs and your fax application can process the job in
any way you want.
The SendFax example project can be modified by dropping an
ApdFaxDriverInterface component on it and using the code from the
Printer Controller application previously mentioned. The only other
changes you could make are to start the application minimized or hidden,
then in the OnDocStart event to restore/show the application, if
desired. |