下面是代码:
HRESULT DisplayPrintPropertySheet(HWND hWnd)
{
HRESULT hResult;
PRINTDLGEX pdx = {0};
LPPRINTPAGERANGE pPageRanges = NULL;
DWORD dwBytesWritten = 0L;
// Allocate an array of PRINTPAGERANGE structures.
pPageRanges = (LPPRINTPAGERANGE) GlobalAlloc(GPTR, 10 * sizeof(PRINTPAGERANGE));
if (!pPageRanges)
return E_OUTOFMEMORY;
// Initialize the PRINTDLGEX structure.
pdx.lStructSize = sizeof(PRINTDLGEX);
pdx.hwndOwner = hWnd;
pdx.hDevMode = NULL;
pdx.hDevNames = NULL;
pdx.hDC = NULL;
pdx.Flags = PD_RETURNDC | PD_COLLATE;
pdx.Flags2 = 0;
pdx.ExclusionFlags = 0;
pdx.nPageRanges = 0;
pdx.nMaxPageRanges = 10;
pdx.lpPageRanges = pPageRanges;
pdx.nMinPage = 1;
pdx.nMaxPage = 1000;
pdx.nCopies = 1;
pdx.hInstance = 0;
pdx.lpPrintTemplateName = NULL;
pdx.lpCallback = NULL;
pdx.nPropertyPages = 0;
pdx.lphPropertyPages = NULL;
pdx.nStartPage = START_PAGE_GENERAL;
pdx.dwResultAction = 0;
// Invoke the Print property sheet.
hResult = PrintDlgEx(&pdx);
if ((hResult == S_OK) && pdx.dwResultAction == PD_RESULT_PRINT)
{ //2976 // 3876 //210 //273
cout << "HORZRES: " << GetDeviceCaps(pdx.hDC,PHYSICALWIDTH)/GetDeviceCaps(pdx.hDC,LOGPIXELSX) << endl;
cout << "VERTRES : " <<GetDeviceCaps(pdx.hDC,PHYSICALHEIGHT)/GetDeviceCaps(pdx.hDC,LOGPIXELSY) << endl;
DOCINFO di = {0};
di.cbSize = sizeof(DOCINFO);
di.lpszDocName = _T("Scribble Printout");
di.lpszOutput = (LPTSTR) NULL;
di.lpszDatatype = "RAW";
di.fwType = 0;
StartDoc(pdx.hDC, &di);
StartPage(pdx.hDC);``
etMapMode(pdx.hDC, MM_HIENGLISH);
RECT rc;
rc.top = -1000;
rc.left = 500;
rc.right = 8000;
rc.bottom = -11000;
DrawText(pdx.hDC,"Legal Action Was Threatened",-1,&rc,DT_WORDBREAK);
EndPage(pdx.hDC);
EndDoc(pdx.hDC);
}
if (pdx.hDevMode != NULL)
GlobalFree(pdx.hDevMode);
if (pdx.hDevNames != NULL)
GlobalFree(pdx.hDevNames);
if (pdx.lpPageRanges != NULL)
GlobalFree(pPageRanges);
if (pdx.hDC != NULL)
DeleteDC(pdx.hDC);
return hResult;
}
问题似乎与DrawText有关。
这是通过.xps显示的内容: