[Questo è documentazione preliminare e soggetto a cambiare].
Questo argomento descrive l'esempio di codice che visualizza una finestra delle proprietà Print , in modo che un utente può selezionare le opzioni per la stampa di un documento. Il codice di esempio prima alloca e Inizializza una struttura PRINTDLGEX , quindi chiama la funzione PrintDlgEx per visualizzare la finestra delle proprietà.
Il codice di esempio imposta il flag PD_RETURNDC nel membro Flags della struttura PRINTDLG . Questo fa sì che la funzione PrintDlgEx restituire un handle di contesto di periferica per la stampante selezionata nel membro hDC . È possibile utilizzare l'handle in funzioni quali DrawText che eseguono il rendering output viene inviato alla stampante.
In input, il codice di esempio imposta i membri hDevMode e hDevNames su NULL. Se la funzione restituisce S_OK, questi membri restituiscono maniglie a DEVNAMES e DEVMODE strutture contenenti input dell'utente e informazioni sulla stampante. È possibile utilizzare queste informazioni per preparare l'output da inviare alla stampante selezionata.
Dopo l'operazione di stampa è stata completata, il codice di esempio libera il buffer DEVMODE e DEVNAMES e chiamate il DeleteDC funzione per eliminare il contesto di periferica.
HRESULT DisplayPrintPropertySheet (
HWND hWnd / / finestra che possiede la finestra delle proprietà
)
{
HRESULT hResult;
LPPRINTDLGEX pPDX = NULL;
LPPRINTPAGERANGE pPageRanges = NULL;
/ / Allocare la struttura PRINTDLGEX.
pPDX = GlobalAlloc (LPPRINTDLGEX) (GPTR, sizeof(PRINTDLGEX));
Se (! pPDX)
return E_OUTOFMEMORY;
/ / Allocare una matrice di strutture PRINTPAGERANGE.
pPageRanges = GlobalAlloc (LPPRINTPAGERANGE) (GPTR, 10 * sizeof(PRINTPAGERANGE));
Se (! pPageRanges)
return E_OUTOFMEMORY;
/ / Inizializza la struttura PRINTDLGEX.
pPDX-gt; 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;
/ / Richiamare la finestra delle proprietà Print.
hResult = PrintDlgEx(pPDX);
Se ((hResult = = S_OK) & &
pPDX - > dwResultAction = = PD_RESULT_PRINT) {
/ / L'utente fa clic sul pulsante Stampa, così
/ / utilizza la DC e altre informazioni restituite nei / / PRINTDLGEX struttura per stampare il documento
}
Se (pPDX - > hDC! = NULL) DeleteDC (pPDX - > hDC);
Se (pPDX - > hDevMode! = NULL) GlobalFree (pPDX - > hDevMode);
Se (pPDX - > hDevNames! = NULL) GlobalFree (pPDX - > hDevNames);
restituire hResult;
}
Rimedio: Inserire il CD-ROM CD di MSDN Library.