I have been developing a service application that uses your AutoPrint controls. When I attempt to convert an HTM file to a TIFF file, it hangs. I used your VB.Net auto print sample program as a guide.
Answer:
If you want to print a HTM/HTML file, the AutoPrint calls Internet Explorer with command line arguments. These arguments tell the Internet Explorer to print the HTM/HTML file. In this case explorer pops up a printing dialog before printing. The AutoPrint automatically closes this printing dialog and then the printing starts.
If you create a service, the service usually is not allowed to interact with the
desktop. In this case the AutoPrint can not close the Printing dialog because that won't be visible. The AutoPrint waits for the displaying of the printing dialog, so it will wait indefinatly.
There is a solution for this problem.
The RTK contains the source code of the AutoPrint.dll.
You should modify some source codes:
Check the BOOL CBiAutoPrint::PrintHTMLDocument(LPCSTR pPrinterName, LPCSTR pFileName) function in the BiAutoPrintClass.cpp. There is a while statement, that waits for the dislplaying of the priting dialog:
do
{
HWND hwnd = FindWindow(NULL, _T("Print"));
if (hwnd && IsWindowVisible(hwnd))
{
::SendMessage(hwnd, WM_COMMAND, IDOK, 0);
break;
}
Sleep(100);
}
while (TRUE);
If the dialog is visible the AutoPrint closes it.
You should replace with it:
BOOL bClosed = FALSE;
do
{
HWND hwnd = FindWindow(NULL, _T("Print"));
if (!hwnd && bClosed)
break;
if (hwnd)
{
::SendMessage(hwnd, WM_COMMAND, IDOK, 0);
bClosed = TRUE;
}
Sleep(100);
}
while (TRUE);
In this case the AutoPrint won't wait for the displaying of the printing
dialog.
