問題:我需要PrintDlgEx為我的專案作業,但選項或引數的組合對我不起作用。它提供E_INVALIDARG了任何選項組合,就像我從 Microsoft 示例或其他在線示例中復制的那樣。
PRINTDLGEX用PRINTDLG和替換(并僅從 中洗掉選項組PrintDlgEx)可以正常作業。PrintDlgPRINTDLGEX
不幸PrintDlgEx的是,我需要,因為我真的需要Apply按鈕來更改列印機或屬性表而不列印,以進行設計和預覽。
請幫我找出為什么我無法顯示對話框。
代碼:雖然我簡化了部分,比如成功回傳時應該發生的事情,或者設定DEVMODEand DEVNAMES,但我完全嘗試了這個函式,結果相同:無效引數。
#include <QDebug>
#include <QWindow>
#include <windows.h>
void showPrintDialog()
{
// Simplifying the setup: real code passes in a QWidget *
QWidget *caller = this;
// Not returning a value or doing any work. I just want the dialog to pop up for now
// Create the standard windows print dialog
PRINTDLGEX printDialog;
memset(&printDialog, 0, sizeof(PRINTDLGEX));
printDialog.lStructSize = sizeof(PRINTDLGEX);
printDialog.Flags = PD_RETURNDC | // Return a printer device context. Without this, HDC may be undefined
PD_USEDEVMODECOPIESANDCOLLATE |
PD_NOSELECTION | // Don't allow selecting individual document pages to print
PD_NOPAGENUMS | // Disables some boxes
PD_NOCURRENTPAGE | // Disables some boxes
PD_NONETWORKBUTTON | // Don't allow networking (but it show "Find printer") so what does this do ?
PD_HIDEPRINTTOFILE; // Don't allow print to file
// Only on PRINTDLGEX
// Theis block copied from https://learn.microsoft.com/en-us/windows/win32/dlgbox/using-common-dialog-boxes?redirectedfrom=MSDN
// I have tried multiple combinations of options, including none, I really don't want any of them
printDialog.nStartPage = START_PAGE_GENERAL;
printDialog.nPageRanges = 1;
printDialog.nMaxPageRanges = 10;
LPPRINTPAGERANGE pageRange = (LPPRINTPAGERANGE) GlobalAlloc(GPTR, 10 * sizeof(PRINTPAGERANGE));
printDialog.lpPageRanges = pageRange;
printDialog.lpPageRanges[0].nFromPage = 1;
printDialog.lpPageRanges[0].nToPage = 1;
printDialog.Flags2 = 0;
printDialog.ExclusionFlags = 0;
printDialog.dwResultAction = 0; // This will tell me if PRINT
// Rest of options are also on PRINTDLG
printDialog.nMinPage = 1;
printDialog.nMaxPage = 10;
// The only options I really need
printDialog.nCopies = 1;
printDialog.hDevMode = Q_NULLPTR; // which will be better once this works
printDialog.hDevNames = Q_NULLPTR; // which will be better once this works
printDialog.hwndOwner = reinterpret_cast<HWND>(caller->windowHandle()->winId());
// Calling...
int result = PrintDlgEx(&printDialog);
qDebug() << (result == E_INVALIDARG ? "Invalid Argument\n" : "Success\n");
// It always is E_INVALIDARG
// Cleanup
if (printDialog.hDevMode)
GlobalFree(printDialog.hDevMode);
if (printDialog.hDevNames)
GlobalFree(printDialog.hDevNames);
if (printDialog.hDC)
DeleteDC(printDialog.hDC);
}
平臺: Windows 10,最新更新;
Qt 版本:5.12.7 或更高版本(因為在 VM 中我有 5.15.1)
我在 Qt 中運行的事實應該是無關緊要的,因為這都是 WIN API,超出了 c 版本(11)
uj5u.com熱心網友回復:
如果我洗掉PD_NONETWORKBUTTON標志,我可以讓你的例子作業。
請注意,雖然它是為PRINTDLGA結構記錄的,但它沒有在PRINTDLGEXA中列出
注意:我確實得到了與該標志相同的錯誤。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/512752.html
