CPrintDialog Creation Failing in Service Mode of an Application

前端 未结 1 1876
自闭症患者
自闭症患者 2021-01-25 17:57

I have an application that prints the report automatically. I am using CPrintDialog to get the Printer DC.

void CMyClass::PrintReport()
{
    CDC dc;
    CPrintD         


        
1条回答
  •  滥情空心
    2021-01-25 18:10

    the CPrintDialog creation is failing when I run the application as a Windows Service.

    You cannot display dialogs (or any type of user interface) in a Windows Service. So CPrintDialog is never going to work.

    But you don't need to create a dialog to get a printer device context, assuming that you already know which printer you want to print to. And since you're running as a non-interactive service, you must already know this, because there's no way that the user can choose a printer.

    To do so, just call CreateDC directly, specifying "WINSPOOL" as the device and the name of the printer. You can obtain the name of the desired printer by enumerating the installed printers using the EnumPrinters function. This is all conveniently documented in a how-to article: Retrieve a Printer Device Context.

    0 讨论(0)
提交回复
热议问题