CPrintDialog default printer.
-
I don't have a physical printer, so I cannot test (Am I wrong here?) I'm trying to print something (a bitmap) using MFC. I set my default printer to "Microsoft Print To PDF" in Windows 10 settings. I have a skeleton code like this : The GetDefaults() fails. Am I missing something ? Obviously, other print commands in other software work (VS, Word, Chrome... )
{
CPrintDialog dlg(FALSE);if (!dlg.GetDefaults()) { AfxMessageBox(\_T("You have no default printer!")); } else { // attach to the DC we were given CDC dc; dc.Attach(dlg.m\_pd.hDC); //.... }
}
CI/CD = Continuous Impediment/Continuous Despair
-
I don't have a physical printer, so I cannot test (Am I wrong here?) I'm trying to print something (a bitmap) using MFC. I set my default printer to "Microsoft Print To PDF" in Windows 10 settings. I have a skeleton code like this : The GetDefaults() fails. Am I missing something ? Obviously, other print commands in other software work (VS, Word, Chrome... )
{
CPrintDialog dlg(FALSE);if (!dlg.GetDefaults()) { AfxMessageBox(\_T("You have no default printer!")); } else { // attach to the DC we were given CDC dc; dc.Attach(dlg.m\_pd.hDC); //.... }
}
CI/CD = Continuous Impediment/Continuous Despair
You don't need the CPrintDialog if you already know the printer name. Just use something like
HANDLE printerHandle = nullptr;
TCHAR name[] = _T("Microsoft Print To PDF");
if (!::OpenPrinter(name, &printerHandle, nullptr))
{
// handle the error
...
} -
You don't need the CPrintDialog if you already know the printer name. Just use something like
HANDLE printerHandle = nullptr;
TCHAR name[] = _T("Microsoft Print To PDF");
if (!::OpenPrinter(name, &printerHandle, nullptr))
{
// handle the error
...
}the problem is not the device name, but GetDefaults not returning the default printer. Obviously, it should work for any device.
CI/CD = Continuous Impediment/Continuous Despair
-
the problem is not the device name, but GetDefaults not returning the default printer. Obviously, it should work for any device.
CI/CD = Continuous Impediment/Continuous Despair
Max, The default constructor is in the documentation[^]:
CPrintDialog(
BOOL bPrintSetupOnly,
DWORD dwFlags = PD_ALLPAGES | PD_USEDEVMODECOPIES | PD_NOPAGENUMS | PD_HIDEPRINTTOFILE | PD_NOSELECTION,
CWnd* pParentWnd = NULL);The default constructor does not contain PD_RETURNDEFAULT. You will need to use the PD_RETURNDEFAULT flag[^] to get the CPrintDialog class to simply return the default printer. In fact by using this flag the DoModal(); function won't even open a window.
CPrintDialog dlg(FALSE,PD\_RETURNDEFAULT,NULL); dlg.DoModal(); LPDEVMODE lpdev = dlg.GetDevMode(); MessageBox(lpdev->dmDeviceName,0,0);
Windows 10 makes decisions for the novice users. So Windows 10 will sometimes decide which printer to use and override the user choice. To disable this programmatically you could set the HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\LegacyDefaultPrinterMode to TRUE. Best Wishes, -David Delaune
-
Max, The default constructor is in the documentation[^]:
CPrintDialog(
BOOL bPrintSetupOnly,
DWORD dwFlags = PD_ALLPAGES | PD_USEDEVMODECOPIES | PD_NOPAGENUMS | PD_HIDEPRINTTOFILE | PD_NOSELECTION,
CWnd* pParentWnd = NULL);The default constructor does not contain PD_RETURNDEFAULT. You will need to use the PD_RETURNDEFAULT flag[^] to get the CPrintDialog class to simply return the default printer. In fact by using this flag the DoModal(); function won't even open a window.
CPrintDialog dlg(FALSE,PD\_RETURNDEFAULT,NULL); dlg.DoModal(); LPDEVMODE lpdev = dlg.GetDevMode(); MessageBox(lpdev->dmDeviceName,0,0);
Windows 10 makes decisions for the novice users. So Windows 10 will sometimes decide which printer to use and override the user choice. To disable this programmatically you could set the HKCU\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Windows\LegacyDefaultPrinterMode to TRUE. Best Wishes, -David Delaune
lol, thanks. I should really pickup this technical skill of RTFM.
CI/CD = Continuous Impediment/Continuous Despair
-
lol, thanks. I should really pickup this technical skill of RTFM.
CI/CD = Continuous Impediment/Continuous Despair