I'm new to API calls & using Visual C++, I have tried using this code (see
below) from the MSDN website, but get compile errors right at the first
line:
: error C2065: 'LPPRINTDLGEX' : undeclared identifier
: error C2146: syntax error : missing ';' before identifier 'pPDX'
: error C2065: 'pPDX' : undeclared identifier
we are using VFP 6.0 and using the older PrintDLG API call but are getting
an intermittent problem (which is happening more & more as more of our users
are using Window XP) where selecting a printer doesn't work. With Win9X we
just used to run in a loop in VFP to get the user to select the printer
again and it would normally be OK. I'm trying to use 'PPRINTDLGEX' instead
to see if this solves the problem. Is this the best group to post this
question even?! Please help!!! Grant.
HRESULT DisplayPrintPropertySheet(
HWND hWnd // Window that owns the property sheet
)
{
HRESULT hResult;
LPPRINTDLGEX pPDX = NULL;
LPPRINTPAGERANGE pPageRanges = NULL;
// Allocate the PRINTDLGEX structure.
pPDX = (LPPRINTDLGEX)GlobalAlloc(GPTR, sizeof(PRINTDLGEX));
if (!pPDX)
return E_OUTOFMEMORY;
// Allocate an array of PRINTPAGERANGE structures.
pPageRanges = (LPPRINTPAGERANGE) GlobalAlloc(GPTR,
10 * sizeof(PRINTPAGERANGE));
if (!pPageRanges)
return E_OUTOFMEMORY;
// Initialize the PRINTDLGEX structure.
pPDX->lStructSize = sizeof(PRINTDLGEX);
pPDX->hwndOwner = hWnd;
pPDX->hDevMode = NULL;
pPDX->hDevNames = NULL;
pPDX->hDC = NULL;
pPDX->Flags = PD_RETURNDC | PD_COLLATE;
pPDX->Flags2 = 0;
pPDX->ExclusionFlags = 0;
pPDX->nPageRanges = 0;
pPDX->nMaxPageRanges = 10;
pPDX->lpPageRanges = pPageRanges;
pPDX->nMinPage = 1;
pPDX->nMaxPage = 1000;
pPDX->nCopies = 1;
pPDX->hInstance = 0;
pPDX->lpPrintTemplateName = NULL;
pPDX->lpCallback = NULL;
pPDX->nPropertyPages = 0;
pPDX->lphPropertyPages = NULL;
pPDX->nStartPage = START_PAGE_GENERAL;
pPDX->dwResultAction = 0;
// Invoke the Print property sheet.
hResult = PrintDlgEx(pPDX);
if ( (hResult == S_OK) &&
pPDX->dwResultAction == PD_RESULT_PRINT) {
// User clicked the Print button, so
// use the DC and other information returned in the
// PRINTDLGEX structure to print the document
}
if (pPDX->hDC != NULL)
DeleteDC(pPDX->hDC);
if (pPDX->hDevMode != NULL)
GlobalFree(pPDX->hDevMode);
if (pPDX->hDevNames != NULL)
GlobalFree(pPDX->hDevNames);
return hResult;
}