Click here to Skip to main content
15,299,255 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using PRINTDLG library for an old windows application, that has to print some files. I configured it in a way that it pick up the default printer and print the document without showing any dialog box. But the problem is when there is no printer and the default printer is set to save to file it shows a popup to save the file and the application minimises, that should not be happen. SO I want to diable the print to file functionality. I tried to set the flag to disable print to file but it is not working.. Anybody know the solution or a way to disable the system popup. Here is the sample code:

What I have tried:


            memset(&pd, 0, sizeof(pd));
            pd.lStructSize = sizeof(pd);
            // Disable print to file flag
            if (!PrintDlg(&pd))
                MessageBox(NULL, _T("No printer found"), _T("Printer Error!"), MB_OK);

                DOCINFO di;
                memset(&di, 0, sizeof(di));
                di.cbSize = sizeof(di);
                StartDoc(pd.hDC, &di);

                // Drawing code begin
                RECT rc;
       = 100;
                rc.left = 100;
                rc.bottom = 300;
                rc.right = 300;

                HBRUSH greenBrush = CreateSolidBrush(RGB(0, 255, 0));
                FillRect(pd.hDC, &rc, greenBrush);
                // Drawing code end

Updated 17-Dec-21 10:25am
Richard MacCutchan 17-Dec-21 7:55am
You should check the contents of the PRINTDLG structure on return from the PrintDlg call, to see what device was selected.

1 solution

The standard system dialogs allow one to use hook procedures so it would seem like you could utilize a hook procedure and potentially adjust some items from the dialog ie., remove them from consideration. According to the docs : PRINTDLGA (commdlg.h) | Microsoft Docs[^] the print dialog has two possible hooks - one for printing and one for setup. That is where I would investigate.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900