Printing Documents Programmatically
If you want to print a document programmatically you can try using the ShellExecute windows API function. The ShellExecute function tries to print the document using the application that is assigned to the specified file type in the system registry. If an application is assigned to the file type and it supports the “print” or “printto” feature from the command line you can print the document easily.
The following example demonstrates how to print a bitmap programmatically in C++:
SHELLEXECUTEINFO sei;
// Initialixe structure
ZeroMemory(&sei, sizeof(SHELLEXECUTEINFO));
sei.cbSize = sizeof(SHELLEXECUTEINFO );
sei.lpFile = _T("C:\\Test\\picture.bmp");
sei.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI |
SEE_MASK_FLAG_DDEWAIT;
sei.lpVerb = TEXT("printto");
sei.nShow = SW_HIDE;
sei.lpParameters = _T("\"Black Ice Color\""); // Printer name
sei.hProcess = hProcess;
if(!ShellExecuteEx(&sei))
{
// Error occurred. See GetLastError
DWORD dwError = GetLastError();
return ;
}