I am using GDI to write a document printing program or my application, but StartDoc is not succeeding. What could be wrong.
The relevant codes are shown below:
case IDM_FILE_PRINT:
{
pd.lStructSize = sizeof(PRINTDLG);
pd.hwndOwner = hWnd;
pd.hDevMode = NULL;
pd.hDevNames = NULL;
pd.hDC = NULL;
pd.Flags = PD_ALLPAGES | PD_COLLATE | PD_RETURNDC | PD_PAGENUMS | PD_CURRENTPAGE | PD_NOSELECTION;
pd.nFromPage = 0xFFFF;
pd.nToPage = 0xFFFF;
pd.nMinPage = 1;
pd.nMaxPage = 0xFFFF;
pd.nCopies = 1;
pd.hInstance = 0;
pd.lCustData = 0L;
pd.lpfnPrintHook = NULL;
pd.lpfnSetupHook = NULL;
pd.lpPrintTemplateName = NULL;
pd.lpSetupTemplateName = NULL;
pd.hPrintTemplate = NULL;
pd.hSetupTemplate = NULL;
if (!PrintDlg(&pd))
{
string ststJobName = utf8_encode(wstJobName);
pair<wstring, wstring> err = GetAppErrMessage(ststJobName);
XMessageBox(hWnd, err.first.c_str(), err.second.c_str(), MB_OK);
break;
}
b bUserAbort = false;
tuple Tuple = GetAppDocumentSize(hWnd, pd.hDC, printData.m_iPaperWidth, printData.m_iPaperHeight, eResultActionType);
printData.m_dOneMMX = get<0>(Tuple);
printData.m_dOneMMY = get<1>(Tuple);
printData.m_iOffsetX = get<2>(Tuple);
printData.m_iOffsetY = get<3>(Tuple);
printData.m_hWnd = hWnd;
printData.m_iTerm = iResultTerm;
printData.m_eWriteType = eWriteType;
printData.m_eResultActionType = eResultActionType;
printData.m_eResultSheetActionType = eResultSheetActionType;
printData.m_eBroadSheetActionType = eBroadSheetActionType;
printData.m_pbUserAbort = &bUserAbort;
printData.m_hDlgPrint = hDlgPrint;
printData.m_pPd = &pd;
printData.m_hDlgPrint = CreateDialog(hInst, MAKEINTRESOURCE(IDD_PRINT_ABORT), hWnd, PrintDlgProc);
ShowWindow(printData.m_hDlgPrint, SW_SHOW);
SetAbortProc(printData.m_pPd->hDC, (ABORTPROC)AbortProc);
if (LoadUserBroadSheetType(eBroadSheetType))
{
printData.m_pvClassResult = &vClassResult;
printData.m_eBroadSheetType = eBroadSheetType;
printData.m_stJobName = vPrintJobName[static_cast<int>(PrintJobName::PJN_BROADSHEET)];
_beginthread(PrintBroadSheet, 0, static_cast<void*>(&printData));
}
void PrintBroadSheet(void* pData)
{
PrintData* pPrintData = reinterpret_cast<PrintData*>(pData);
PrintBroadSheet(pPrintData->m_hWnd,*(pPrintData->m_pvClassResult), pPrintData->m_iTerm, pPrintData->m_eWriteType, pPrintData->m_eResultActionType, pPrintData->m_eBroadSheetActionType, pPrintData->m_eBroadSheetType, pPrintData->m_pbUserAbort, pPrintData->m_hDlgPrint, pPrintData->m_stJobName, *(pPrintData->m_pPd), pPrintData->m_dOneMMX, pPrintData->m_dOneMMY, pPrintData->m_iOffsetX, pPrintData->m_iOffsetY, pPrintData->m_iPaperWidth, pPrintData->m_iPaperHeight);
_endthread();
}
struct PrintData
{
HWND m_hWnd{};
std::vector<classresult> *m_pvClassResult{};
ClassResult *m_pclassResult{};
int m_iTerm{};
WriteType m_eWriteType = WriteType::WT_PRINTER;
ResultActionType m_eResultActionType = ResultActionType::RAT_VIEW_BROADSHEET;
ResultSheetActionType m_eResultSheetActionType = ResultSheetActionType::RSAT_VIEW_TERMINAL_RESULTSHEET;
BroadSheetActionType m_eBroadSheetActionType = BroadSheetActionType::BAT_VIEW_TERMINAL_BROADSHEET;
ResultsType m_eResultsType = ResultsType::RST_SHOW_PREVIOUS;
BroadSheetTypes m_eBroadSheetType = BroadSheetTypes::BST_SHOW_DETAILS;
bool *m_pbUserAbort{};
HWND m_hDlgPrint{};
PRINTDLG* m_pPd{};
std::string m_stJobName;
}
INT PrintBroadSheet(HWND hWnd,std::vector<ClassResult>& vClassResult, int iTerm, WriteType eWriteType, ResultActionType eResultActionType, BroadSheetActionType eBroadSheetActionType, BroadSheetTypes eBroadSheetType, bool *pbUserAbort, HWND hDlgPrint, std::string stJobName, PRINTDLG &pd,double dOneMMX, double dOneMMY, int iOffsetX, int iOffsetY, int iPageWidth, int iPageHeight)
{
bool bSuccess = true;
std::wstring wstJobName = utf8_decode(stJobName);
static DOCINFO di;
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = wstJobName.c_str();
di.fwType = 0;
di.lpszDatatype = nullptr;
di.lpszOutput = nullptr;
if (StartDoc(pd.hDC, &di) > 0)
{
}
else
{
bSuccess = false;
}
if (bSuccess)
{
EndDoc(pd.hDC);
}
if(!*pbUserAbort)
{
DestroyWindow(hDlgPrint);
}
DeleteDC(pd.hDC);
return bSuccess && !*pbUserAbort;
}<small></small>
What I have tried:
I have been googling all day but has not gotten an result yet.