Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
prnsetup.c
Package: shell.rar [view]
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 263k
Category:
Windows Kernel
Development Platform:
Visual C++
- /*++
- Copyright (c) 1990-1995, Microsoft Corporation All rights reserved.
- Module Name:
- prnsetup.c
- Abstract:
- This module implements the Win32 print dialogs.
- Revision History:
- --*/
- //
- // Includes Files.
- //
- #include <windows.h>
- #include <port1632.h>
- #include <winspool.h>
- #include <commctrl.h>
- #include <tchar.h>
- #include "privcomd.h"
- #include "prnsetup.h"
- #ifndef WINNT
- STATIC HCURSOR HourGlass(BOOL bOn)
- {
- return ( SetCursor( LoadCursor(NULL, bOn ? IDC_WAIT : IDC_ARROW) ) );
- }
- #endif
- #ifdef UNICODE
- ////////////////////////////////////////////////////////////////////////////
- //
- // PrintDlgA
- //
- // ANSI entry point for PrintDlg when this code is built UNICODE.
- //
- ////////////////////////////////////////////////////////////////////////////
- BOOL WINAPI PrintDlgA(
- LPPRINTDLGA pPDA)
- {
- PRINTINFO PI;
- BOOL bResult = FALSE;
- ZeroMemory(&PI, sizeof(PRINTINFO));
- if (bResult = ThunkPrintDlg(&PI, pPDA))
- {
- ThunkPrintDlgA2W(&PI);
- if (bResult = PrintDlgX(&PI))
- {
- ThunkPrintDlgW2A(&PI);
- }
- }
- FreeThunkPrintDlg(&PI);
- return (bResult);
- }
- #else
- ////////////////////////////////////////////////////////////////////////////
- //
- // PrintDlgW
- //
- // Stub UNICODE function for PrintDlg when this code is built ANSI.
- //
- ////////////////////////////////////////////////////////////////////////////
- BOOL WINAPI PrintDlgW(
- LPPRINTDLGW pPDW)
- {
- SetLastErrorEx(SLE_WARNING, ERROR_CALL_NOT_IMPLEMENTED);
- return (FALSE);
- }
- #endif
- ////////////////////////////////////////////////////////////////////////////
- //
- // PrintDlg
- //
- // The PrintDlg function displays a Print dialog box or a Print Setup
- // dialog box. The Print dialog box enables the user to specify the
- // properties of a particular print job. The Print Setup dialog box
- // allows the user to select additional job properties and to configure
- // the printer.
- //
- ////////////////////////////////////////////////////////////////////////////
- BOOL WINAPI PrintDlg(
- LPPRINTDLG pPD)
- {
- PRINTINFO PI;
- ZeroMemory(&PI, sizeof(PRINTINFO));
- PI.pPD = pPD;
- PI.ApiType = COMDLG_WIDE;
- return ( PrintDlgX(&PI) );
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // PrintDlgX
- //
- // Worker routine for the PrintDlg api.
- //
- ////////////////////////////////////////////////////////////////////////////
- BOOL PrintDlgX(
- PPRINTINFO pPI)
- {
- LPPRINTDLG pPD = pPI->pPD;
- LPPAGESETUPDLG pPSD;
- BOOL nResult = -1; // <0==error, 0==CANCEL, >0==OK
- LPDEVMODE pDM = NULL;
- LPDEVMODE pDevMode = NULL;
- LPDEVNAMES pDN = NULL;
- DWORD dwFlags; // old copy
- WORD nCopies, nFromPage, nToPage; // old copy
- HGLOBAL hDevNames, hDevMode; // old copy
- LONG cbNeeded;
- #ifndef WINNT
- LPCTSTR pDN_Device = NULL;
- TCHAR szDev[2];
- #endif
- if (!pPD)
- {
- StoreExtendedError(CDERR_INITIALIZATION);
- return (FALSE);
- }
- if (pPD->lStructSize != sizeof(PRINTDLG))
- {
- StoreExtendedError(CDERR_STRUCTSIZE);
- return (FALSE);
- }
- if (pPD->hwndOwner && !IsWindow(pPD->hwndOwner))
- {
- StoreExtendedError(CDERR_DIALOGFAILURE);
- return (FALSE);
- }
- //
- // Get the process version of the app for later use.
- //
- pPI->ProcessVersion = GetProcessVersion(0);
- #ifdef UNICODE
- //
- // Check if we need to use ExtDeviceMode. We use this
- // mode only if a 16 bit app is calling us with a NULL
- // devmode.
- //
- if ((pPD->Flags & CD_WOWAPP) && !pPD->hDevMode)
- {
- pPI->bUseExtDeviceMode = TRUE;
- }
- else
- {
- pPI->bUseExtDeviceMode = FALSE;
- }
- #endif
- #ifndef WINNT
- //
- // This should NOT be in NT. The device name cannot be longer than
- // 32 characters, so it may be truncated. If we look for it in the
- // registry and it's supposed to be larger than 32 characters, then
- // we won't find it and we'll fail.
- //
- // LATER: It probably shouldn't be in WIN95 either, but I'll leave
- // it for now.
- //
- if (pPD->hDevMode)
- {
- if (!(pDM = GlobalLock(pPD->hDevMode)))
- {
- StoreExtendedError(CDERR_MEMLOCKFAILURE);
- goto PrintDlgX_DisplayWarning;
- }
- }
- if (pPD->hDevNames)
- {
- if (!(pDN = GlobalLock(pPD->hDevNames)))
- {
- if (pDM)
- {
- GlobalUnlock(pPD->hDevMode);
- }
- StoreExtendedError(CDERR_MEMLOCKFAILURE);
- goto PrintDlgX_DisplayWarning;
- }
- else
- {
- if (pDN->wDeviceOffset)
- {
- pDN_Device = (LPCTSTR)pDN + pDN->wDeviceOffset;
- }
- }
- }
- if (pDM && pDM->dmDeviceName[0])
- {
- GetProfileString(szTextDevices, pDM->dmDeviceName, szTextNull, szDev, 2);
- if (!szDev[0])
- {
- GlobalUnlock(pPD->hDevMode);
- if (pDN)
- {
- GlobalUnlock(pPD->hDevNames);
- }
- StoreExtendedError(PDERR_PRINTERNOTFOUND);
- goto PrintDlgX_DisplayWarning;
- }
- }
- if (pDN_Device && pDN_Device[0])
- {
- GetProfileString(szTextDevices, pDN_Device, szTextNull, szDev, 2);
- if (!szDev[0])
- {
- if (pDM)
- {
- GlobalUnlock(pPD->hDevMode);
- }
- GlobalUnlock(pPD->hDevNames);
- StoreExtendedError(PDERR_PRINTERNOTFOUND);
- goto PrintDlgX_DisplayWarning;
- }
- }
- #if 0 // If this check is performed, MFC 3.0 (in VC++ 2.0) fails.
- if ( pDM &&
- pDM->dmDeviceName[0] &&
- pDN_Device &&
- pDN_Device[0] &&
- lstrcmp(pDM->dmDeviceName, pDN_Device) )
- {
- GlobalUnlock(pPD->hDevMode);
- GlobalUnlock(pPD->hDevNames);
- StoreExtendedError(PDERR_DNDMMISMATCH);
- goto PrintDlgX_DisplayWarning;
- }
- #endif
- if (pDM)
- {
- GlobalUnlock(pPD->hDevMode);
- }
- if (pDN)
- {
- GlobalUnlock(pPD->hDevNames);
- }
- #endif
- pPD->hDC = 0;
- //
- // Load necessary libraries.
- //
- if (!PrintLoadLibraries())
- {
- StoreExtendedError(PDERR_LOADDRVFAILURE);
- goto PrintDlgX_DisplayWarning;
- }
- StoreExtendedError(CDERR_GENERALCODES);
- //
- // Do minimal work when requesting a default printer.
- //
- if (pPD->Flags & PD_RETURNDEFAULT)
- {
- //
- // Do not display a warning in this case if it fails.
- // MFC 3.1 does not specify PD_NOWARNING, but that's what
- // it really wants.
- //
- nResult = PrintReturnDefault(pPI);
- PrintClosePrinters(pPI);
- return (nResult);
- }
- if (!PrintLoadIcons())
- {
- //
- // If the icons cannot be loaded, then fail.
- //
- StoreExtendedError(PDERR_SETUPFAILURE);
- goto PrintDlgX_DisplayWarning;
- }
- //
- // Printer enumeration is delayed until the combobox is dropped down.
- // However, if a printer is specified, we must force enumeration in
- // order to find the printer so that the correct devmode can be created.
- //
- //
- // First : Try to open the printer in the DevMode.
- //
- if ( (!pPI->hCurPrinter) &&
- (pPD->hDevMode) &&
- (pDM = GlobalLock(pPD->hDevMode)) )
- {
- PrintOpenPrinter(pPI, pDM->dmDeviceName);
- GlobalUnlock(pPD->hDevMode);
- }
- //
- // Second : Try to open the printer in the DevNames.
- //
- if ( (!pPI->hCurPrinter) &&
- (pPD->hDevNames) &&
- (pDN = GlobalLock(pPD->hDevNames)) )
- {
- PrintOpenPrinter(pPI, (LPTSTR)pDN + pDN->wDeviceOffset);
- GlobalUnlock(pPD->hDevNames);
- }
- //
- // Third : Try to open the Default Printer.
- //
- PrintGetDefaultPrinterName(pPI);
- if (!pPI->hCurPrinter)
- {
- if (pPI->szDefaultPrinter[0])
- {
- PrintOpenPrinter(pPI, pPI->szDefaultPrinter);
- }
- }
- //
- // Fourth : Enumerate the Printers and try to open one of those.
- //
- if (!pPI->hCurPrinter)
- {
- if (!PrintEnumAndSelect(pPD->hwndOwner, 0, pPI, NULL, TRUE))
- {
- //
- // There are no printers installed in the system.
- //
- goto PrintDlgX_DisplayWarning;
- }
- }
- //
- // Save the original information passed in by the app in case the user
- // hits cancel.
- //
- dwFlags = pPD->Flags;
- nCopies = pPD->nCopies;
- nFromPage = pPD->nFromPage;
- nToPage = pPD->nToPage;
- hDevNames = pPD->hDevNames;
- hDevMode = pPD->hDevMode;
- pPD->hDevNames = NULL;
- pPD->hDevMode = NULL;
- //
- // Build a copy of the DevNames.
- //
- PrintBuildDevNames(pPI);
- //
- // Get the *correct* DevMode.
- //
- if (hDevMode)
- {
- pDevMode = GlobalLock(hDevMode);
- }
- cbNeeded = (*WinSpool_DocumentProperties)(
- pPD->hwndOwner,
- pPI->hCurPrinter,
- (pPI->pCurPrinter)
- ? pPI->pCurPrinter->pPrinterName
- : NULL,
- NULL,
- pDevMode,
- 0 );
- if ( (cbNeeded > 0) &&
- (pPD->hDevMode = GlobalAlloc(GHND, cbNeeded)) )
- {
- BOOL fSuccess = FALSE;
- if (pDM = GlobalLock(pPD->hDevMode))
- {
- fSuccess = (*WinSpool_DocumentProperties)(
- pPD->hwndOwner,
- pPI->hCurPrinter,
- (pPI->pCurPrinter)
- ? pPI->pCurPrinter->pPrinterName
- : NULL,
- pDM,
- pDevMode,
- DM_COPY ) == IDOK;
- if (pDM->dmFields & DM_COPIES)
- {
- if ((hDevMode) || (pPD->Flags & PD_USEDEVMODECOPIES))
- {
- pPD->nCopies = pDM->dmCopies;
- }
- else if (pPD->nCopies)
- {
- pDM->dmCopies = pPD->nCopies;
- }
- }
- if (pDM->dmFields & DM_COLLATE)
- {
- if ((hDevMode) || (pPD->Flags & PD_USEDEVMODECOPIES))
- {
- if (pDM->dmCollate == DMCOLLATE_FALSE)
- {
- pPD->Flags &= ~PD_COLLATE;
- pPI->Status &= ~PI_COLLATE_REQUESTED;
- }
- else
- {
- pPD->Flags |= PD_COLLATE;
- pPI->Status |= PI_COLLATE_REQUESTED;
- }
- }
- else
- {
- pDM->dmCollate = (pPD->Flags & PD_COLLATE)
- ? DMCOLLATE_TRUE
- : DMCOLLATE_FALSE;
- }
- }
- GlobalUnlock(pPD->hDevMode);
- }
- if (!fSuccess)
- {
- GlobalFree(pPD->hDevMode);
- pPD->hDevMode = NULL;
- }
- }
- if (pDevMode)
- {
- GlobalUnlock(hDevMode);
- }
- //
- // Get the default source string - "Print Manager Setting".
- //
- LoadString(g_hinst, iszDefaultSource, szDefaultSrc, SCRATCHBUF_SIZE);
- //
- // Call the appropriate dialog routine.
- //
- switch (pPD->Flags & (PD_PRINTSETUP | PD_PAGESETUP))
- {
- case ( 0 ) :
- {
- nResult = PrintDisplayPrintDlg(pPI);
- break;
- }
- case ( PD_PRINTSETUP ) :
- case ( PD_PAGESETUP ) :
- {
- nResult = PrintDisplaySetupDlg(pPI);
- break;
- }
- default :
- {
- StoreExtendedError(CDERR_INITIALIZATION);
- break;
- }
- }
- if (nResult > 0)
- {
- //
- // User hit OK, so free the copies of the handles passed in
- // by the app.
- //
- if (hDevMode)
- {
- GlobalFree(hDevMode);
- }
- if (hDevNames)
- {
- GlobalFree(hDevNames);
- }
- }
- else
- {
- //
- // User hit CANCEL or there was an error, so restore original
- // values passed in by the app.
- //
- pPD->Flags = dwFlags;
- pPD->nCopies = nCopies;
- pPD->nFromPage = nFromPage;
- pPD->nToPage = nToPage;
- if (pPD->hDevMode)
- {
- GlobalFree(pPD->hDevMode);
- }
- if (pPD->hDevNames)
- {
- GlobalFree(pPD->hDevNames);
- }
- pPD->hDevNames = hDevNames;
- pPD->hDevMode = hDevMode;
- }
- //
- // Make sure that we are really supposed to be leaving this function
- // before we start closing printers and displaying error messages.
- //
- if (pPI->Status & PI_PRINTDLGX_RECURSE)
- {
- return (nResult > 0);
- }
- //
- // Close the printers that were opened.
- //
- PrintClosePrinters(pPI);
- //
- // Display any error messages.
- //
- PrintDlgX_DisplayWarning:
- if ((nResult < 0) && (!(pPD->Flags & PD_NOWARNING)))
- {
- DWORD dwErr = GetStoredExtendedError();
- //
- // Only do this for new apps.
- //
- if ( (pPI->ProcessVersion >= 0x40000) ||
- (dwErr == PDERR_NODEFAULTPRN) ||
- (dwErr == PDERR_PRINTERNOTFOUND) )
- {
- TCHAR szWarning[SCRATCHBUF_SIZE];
- TCHAR szTitle[SCRATCHBUF_SIZE];
- int iszWarning;
- szTitle[0] = TEXT('');
- if (pPD->hwndOwner)
- {
- GetWindowText(pPD->hwndOwner, szTitle, SCRATCHBUF_SIZE);
- }
- if (!szTitle[0])
- {
- LoadString(g_hinst, iszWarningTitle, szTitle, SCRATCHBUF_SIZE);
- }
- switch (dwErr)
- {
- case ( PDERR_NODEFAULTPRN ) :
- {
- iszWarning = iszNoPrnsInstalled;
- break;
- }
- case ( PDERR_PRINTERNOTFOUND ) :
- {
- iszWarning = iszPrnNotFound;
- break;
- }
- case ( CDERR_MEMLOCKFAILURE ) :
- case ( CDERR_MEMALLOCFAILURE ) :
- case ( PDERR_LOADDRVFAILURE ) :
- {
- iszWarning = iszMemoryError;
- break;
- }
- default :
- {
- iszWarning = iszGeneralWarning;
- break;
- }
- }
- LoadString(g_hinst, iszWarning, szWarning, SCRATCHBUF_SIZE);
- MessageBeep(MB_ICONEXCLAMATION);
- MessageBox( pPD->hwndOwner,
- szWarning,
- szTitle,
- MB_ICONEXCLAMATION | MB_OK );
- }
- }
- return (nResult > 0);
- }
- #ifdef UNICODE
- ////////////////////////////////////////////////////////////////////////////
- //
- // PageSetupDlgA
- //
- // ANSI entry point for PageSetupDlg when this code is built UNICODE.
- //
- ////////////////////////////////////////////////////////////////////////////
- BOOL WINAPI PageSetupDlgA(
- LPPAGESETUPDLGA pPSDA)
- {
- PRINTINFO PI;
- BOOL bResult = FALSE;
- HANDLE hDevMode;
- HANDLE hDevNames;
- LPCSTR pTemplateName;
- ZeroMemory(&PI, sizeof(PRINTINFO));
- //
- // Get the pPDA structure from the pPSDA structure.
- //
- if (bResult = ThunkPageSetupDlg(&PI, pPSDA))
- {
- //
- // Save the original devmode and devnames.
- //
- hDevMode = pPSDA->hDevMode;
- hDevNames = pPSDA->hDevNames;
- pTemplateName = pPSDA->lpPageSetupTemplateName;
- //
- // Convert the pPDA structure to Unicode (pPI->pPD).
- //
- if (bResult = ThunkPrintDlg(&PI, PI.pPDA))
- {
- //
- // Fill in the pPI->pPD structure.
- //
- ThunkPrintDlgA2W(&PI);
- //
- // Copy the Unicode information from the pPD structure to
- // the pPSD structure for the call to PageSetupDlgX.
- //
- (PI.pPSD)->hDevMode = (PI.pPD)->hDevMode;
- (PI.pPSD)->hDevNames = (PI.pPD)->hDevNames;
- (PI.pPSD)->lpPageSetupTemplateName = (PI.pPD)->lpSetupTemplateName;
- //
- // Call the PageSetupDlgX function to do the work.
- //
- if (bResult = PageSetupDlgX(&PI))
- {
- //
- // Success. Convert the Unicode pPD structure to
- // its ANSI equivalent.
- //
- ThunkPrintDlgW2A(&PI);
- //
- // Save the ANSI devmode and devnames in the
- // pPSD structure to be returned to the caller.
- //
- pPSDA->hDevMode = (PI.pPDA)->hDevMode;
- pPSDA->hDevNames = (PI.pPDA)->hDevNames;
- }
- else
- {
- //
- // Failure. Restore the old devmode and devnames.
- //
- pPSDA->hDevMode = hDevMode;
- pPSDA->hDevNames = hDevNames;
- }
- //
- // Restore the old template name (always).
- //
- pPSDA->lpPageSetupTemplateName = pTemplateName;
- }
- FreeThunkPrintDlg(&PI);
- }
- FreeThunkPageSetupDlg(&PI);
- return (bResult);
- }
- #else
- ////////////////////////////////////////////////////////////////////////////
- //
- // PageSetupDlgW
- //
- // Stub UNICODE function for PageSetupDlg when this code is built ANSI.
- //
- ////////////////////////////////////////////////////////////////////////////
- BOOL WINAPI PageSetupDlgW(
- LPPAGESETUPDLGW pPSDW)
- {
- SetLastErrorEx(SLE_WARNING, ERROR_CALL_NOT_IMPLEMENTED);
- return (FALSE);
- }
- #endif
- ////////////////////////////////////////////////////////////////////////////
- //
- // PageSetupDlg
- //
- // The PageSetupDlg function displays a Page Setup dialog box. This
- // dialog box enables the user to specify the page orientation, the
- // paper size, the paper source, and the margin settings. The
- // appearance of the printed page is shown in the dialog's page preview.
- //
- ////////////////////////////////////////////////////////////////////////////
- BOOL WINAPI PageSetupDlg(
- LPPAGESETUPDLG pPSD)
- {
- PRINTINFO PI;
- BOOL bResult;
- ZeroMemory(&PI, sizeof(PRINTINFO));
- PI.pPSD = pPSD;
- PI.ApiType = COMDLG_WIDE;
- bResult = PageSetupDlgX(&PI);
- if (PI.pPD)
- {
- GlobalFree(PI.pPD);
- }
- return (bResult);
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // PageSetupDlgX
- //
- // Worker routine for the PageSetupDlg api.
- //
- // NOTE: Caller of this routine must free pPI->pPD.
- //
- ////////////////////////////////////////////////////////////////////////////
- BOOL PageSetupDlgX(
- PPRINTINFO pPI)
- {
- LPPAGESETUPDLG pPSD = pPI->pPSD;
- BOOL bResult = FALSE;
- LPPRINTDLG pPD;
- RECT rtMinMargin;
- RECT rtMargin;
- POINT ptPaperSize;
- DWORD Flags;
- if (!pPSD)
- {
- StoreExtendedError(CDERR_INITIALIZATION);
- return (FALSE);
- }
- if (pPSD->lStructSize != sizeof(PAGESETUPDLG))
- {
- StoreExtendedError(CDERR_STRUCTSIZE);
- return (FALSE);
- }
- if ((pPSD->Flags & PSD_RETURNDEFAULT) &&
- (pPSD->hDevNames || pPSD->hDevMode))
- {
- StoreExtendedError(PDERR_RETDEFFAILURE);
- return (FALSE);
- }
- //
- // Make sure only the PSD_* bits are on. Otherwise, bad things
- // will happen.
- //
- if ((pPSD->Flags & ~(PSD_MINMARGINS |
- PSD_MARGINS |
- PSD_INTHOUSANDTHSOFINCHES |
- PSD_INHUNDREDTHSOFMILLIMETERS |
- PSD_DISABLEMARGINS |
- PSD_DISABLEPRINTER |
- PSD_NOWARNING | // must be same as PD_*
- PSD_DISABLEORIENTATION |
- PSD_DISABLEPAPER |
- PSD_RETURNDEFAULT | // must be same as PD_*
- PSD_SHOWHELP | // must be same as PD_*
- PSD_ENABLEPAGESETUPHOOK | // must be same as PD_*
- PSD_ENABLEPAGESETUPTEMPLATE | // must be same as PD_*
- PSD_ENABLEPAGESETUPTEMPLATEHANDLE | // must be same as PD_*
- PSD_ENABLEPAGEPAINTHOOK |
- PSD_DISABLEPAGEPAINTING)) ||
- ((pPSD->Flags & (PSD_INTHOUSANDTHSOFINCHES |
- PSD_INHUNDREDTHSOFMILLIMETERS)) ==
- (PSD_INTHOUSANDTHSOFINCHES | PSD_INHUNDREDTHSOFMILLIMETERS)))
- {
- StoreExtendedError(PDERR_INITFAILURE);
- return (FALSE);
- }
- if ((pPSD->Flags & PSD_MINMARGINS) && (pPSD->Flags & PSD_MARGINS))
- {
- if ( (pPSD->rtMargin.left < pPSD->rtMinMargin.left) ||
- (pPSD->rtMargin.top < pPSD->rtMinMargin.top) ||
- (pPSD->rtMargin.right < pPSD->rtMinMargin.right) ||
- (pPSD->rtMargin.bottom < pPSD->rtMinMargin.bottom) )
- {
- StoreExtendedError(PDERR_INITFAILURE);
- return (FALSE);
- }
- }
- if (pPSD->Flags & PSD_ENABLEPAGESETUPHOOK)
- {
- if (!pPSD->lpfnPageSetupHook)
- {
- StoreExtendedError(CDERR_NOHOOK);
- return (FALSE);
- }
- }
- else
- {
- pPSD->lpfnPageSetupHook = NULL;
- }
- if (pPSD->Flags & PSD_ENABLEPAGEPAINTHOOK)
- {
- if (!pPSD->lpfnPagePaintHook)
- {
- StoreExtendedError(CDERR_NOHOOK);
- return (FALSE);
- }
- }
- else
- {
- pPSD->lpfnPagePaintHook = NULL;
- }
- if ((pPI->pPD) || (pPI->pPD = GlobalAlloc(GPTR, sizeof(PRINTDLG))))
- {
- pPD = pPI->pPD;
- pPD->lStructSize = sizeof( PRINTDLG );
- pPD->hwndOwner = pPSD->hwndOwner;
- pPD->Flags = PD_PAGESETUP |
- (pPSD->Flags &
- (PSD_NOWARNING |
- PSD_SHOWHELP |
- PSD_ENABLEPAGESETUPHOOK |
- PSD_ENABLEPAGESETUPTEMPLATE |
- PSD_ENABLEPAGESETUPTEMPLATEHANDLE));
- pPD->hInstance = pPSD->hInstance;
- pPD->lCustData = pPSD->lCustData;
- pPD->lpfnSetupHook = pPSD->lpfnPageSetupHook;
- pPD->lpSetupTemplateName = pPSD->lpPageSetupTemplateName;
- pPD->hSetupTemplate = pPSD->hPageSetupTemplate;
- //
- // Save original settings in case the user hits cancel.
- //
- rtMinMargin = pPSD->rtMinMargin;
- rtMargin = pPSD->rtMargin;
- ptPaperSize = pPSD->ptPaperSize;
- Flags = pPSD->Flags;
- //
- // Make sure the measure choice is set.
- //
- if ((pPSD->Flags & (PSD_INTHOUSANDTHSOFINCHES |
- PSD_INHUNDREDTHSOFMILLIMETERS)) == 0)
- {
- TCHAR szIMeasure[2];
- GetLocaleInfo(LOCALE_USER_DEFAULT, LOCALE_IMEASURE, szIMeasure, 2);
- if (szIMeasure[0] == TEXT('1'))
- {
- pPSD->Flags |= PSD_INTHOUSANDTHSOFINCHES;
- }
- else
- {
- pPSD->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
- }
- }
- //
- // Set minimum margins to 0 if not passed in.
- //
- if (!(pPSD->Flags & PSD_MINMARGINS))
- {
- pPSD->rtMinMargin.left = 0;
- pPSD->rtMinMargin.top = 0;
- pPSD->rtMinMargin.right = 0;
- pPSD->rtMinMargin.bottom = 0;
- }
- //
- // Set margins to defaults if not passed in.
- //
- if (!(pPSD->Flags & PSD_MARGINS))
- {
- LONG MarginDefault = (pPSD->Flags & PSD_INTHOUSANDTHSOFINCHES)
- ? INCHES_DEFAULT
- : MMS_DEFAULT;
- pPSD->rtMargin.left = MarginDefault;
- pPSD->rtMargin.top = MarginDefault;
- pPSD->rtMargin.right = MarginDefault;
- pPSD->rtMargin.bottom = MarginDefault;
- }
- TransferPSD2PD(pPI);
- bResult = PrintDlgX(pPI);
- TransferPD2PSD(pPI);
- if (!bResult)
- {
- //
- // Restore original settings when the user hits cancel.
- //
- pPSD->rtMinMargin = rtMinMargin;
- pPSD->rtMargin = rtMargin;
- pPSD->ptPaperSize = ptPaperSize;
- pPSD->Flags = Flags;
- }
- }
- else
- {
- StoreExtendedError(CDERR_MEMALLOCFAILURE);
- }
- return (bResult);
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // PrintLoadLibraries
- //
- //
- //
- ////////////////////////////////////////////////////////////////////////////
- BOOL PrintLoadLibraries()
- {
- if (!hWinSpool)
- {
- if ((hWinSpool = LoadLibrary(szWinspool)))
- {
- WinSpool_AdvancedDocProps = (LPFNADVANCEDDOCPROPS)
- GetProcAddress(hWinSpool, szAdvancedDocProps);
- WinSpool_DeviceCapabilities = (LPFNDEVICECAPABILITIES)
- GetProcAddress(hWinSpool, szDeviceCapabilities);
- WinSpool_DocumentProperties = (LPFNDOCUMENTPROPERTIES)
- GetProcAddress(hWinSpool, szDocumentProperties);
- WinSpool_EnumPrinters = (LPFNENUMPRINTERS)
- GetProcAddress(hWinSpool, szEnumPrinters);
- WinSpool_GetPrinter = (LPFNGETPRINTER)
- GetProcAddress(hWinSpool, szGetPrinter);
- WinSpool_OpenPrinter = (LPFNOPENPRINTER)
- GetProcAddress(hWinSpool, szOpenPrinter);
- WinSpool_ClosePrinter = (LPFNCLOSEPRINTER)
- GetProcAddress(hWinSpool, szClosePrinter);
- #ifdef WINNT
- WinSpool_ConnectToPrinterDlg = (LPFNCONNECTTOPRINTERDLG)
- GetProcAddress(hWinSpool, szConnectToPrinterDlg);
- #endif
- #ifdef UNICODE
- WinSpool_ExtDeviceMode = (LPFNEXTDEVICEMODE)
- GetProcAddress(hWinSpool, szExtDeviceMode);
- #endif
- if (!WinSpool_AdvancedDocProps ||
- !WinSpool_DeviceCapabilities ||
- !WinSpool_DocumentProperties ||
- !WinSpool_EnumPrinters ||
- !WinSpool_GetPrinter ||
- !WinSpool_OpenPrinter ||
- !WinSpool_ClosePrinter
- #ifdef WINNT
- ||
- !WinSpool_ConnectToPrinterDlg
- #endif
- #ifdef UNICODE
- ||
- !WinSpool_ExtDeviceMode
- #endif
- )
- {
- FreeLibrary(hWinSpool);
- hWinSpool = NULL;
- }
- }
- }
- return (hWinSpool != NULL);
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // PrintUnloadLibraries
- //
- //
- //
- ////////////////////////////////////////////////////////////////////////////
- VOID PrintUnloadLibraries()
- {
- if (hWinSpool)
- {
- FreeLibrary(hWinSpool);
- hWinSpool = NULL;
- }
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // PrintLoadIcons
- //
- //
- //
- ////////////////////////////////////////////////////////////////////////////
- BOOL PrintLoadIcons()
- {
- //
- // Load the orientation icons.
- //
- hIconPortrait = LoadIcon(g_hinst, MAKEINTRESOURCE(ICO_PORTRAIT));
- hIconLandscape = LoadIcon(g_hinst, MAKEINTRESOURCE(ICO_LANDSCAPE));
- //
- // Load the duplex icons.
- //
- hIconPDuplexNone = LoadIcon(g_hinst, MAKEINTRESOURCE(ICO_P_NONE));
- hIconLDuplexNone = LoadIcon(g_hinst, MAKEINTRESOURCE(ICO_L_NONE));
- hIconPDuplexTumble = LoadIcon(g_hinst, MAKEINTRESOURCE(ICO_P_HORIZ));
- hIconLDuplexTumble = LoadIcon(g_hinst, MAKEINTRESOURCE(ICO_L_VERT));
- hIconPDuplexNoTumble = LoadIcon(g_hinst, MAKEINTRESOURCE(ICO_P_VERT));
- hIconLDuplexNoTumble = LoadIcon(g_hinst, MAKEINTRESOURCE(ICO_L_HORIZ));
- //
- // Load the page setup icons.
- //
- hIconPSStampP = LoadIcon(g_hinst, MAKEINTRESOURCE(ICO_P_PSSTAMP));
- hIconPSStampL = LoadIcon(g_hinst, MAKEINTRESOURCE(ICO_L_PSSTAMP));
- //
- // Load the collation images.
- //
- hIconCollate = LoadImage( g_hinst,
- MAKEINTRESOURCE(ICO_COLLATE),
- IMAGE_ICON,
- 0,
- 0,
- LR_LOADREALSIZE );
- hIconNoCollate = LoadImage( g_hinst,
- MAKEINTRESOURCE(ICO_NO_COLLATE),
- IMAGE_ICON,
- 0,
- 0,
- LR_LOADREALSIZE );
- //
- // Return TRUE only if all icons/images were loaded properly.
- //
- return ( hIconPortrait &&
- hIconLandscape &&
- hIconPDuplexNone &&
- hIconLDuplexNone &&
- hIconPDuplexTumble &&
- hIconLDuplexTumble &&
- hIconPDuplexNoTumble &&
- hIconLDuplexNoTumble &&
- hIconPSStampP &&
- hIconPSStampL &&
- hIconCollate &&
- hIconNoCollate );
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // PrintDisplayPrintDlg
- //
- //
- //
- ////////////////////////////////////////////////////////////////////////////
- int PrintDisplayPrintDlg(
- PPRINTINFO pPI)
- {
- LPPRINTDLG pPD = pPI->pPD;
- int fGotInput = -1;
- HANDLE hDlgTemplate = NULL;
- HANDLE hInstance;
- #ifdef UNICODE
- UINT uiWOWFlag = 0;
- #endif
- //
- // NOTE: The print hook check must be done here rather than in
- // PrintDlgX. Old apps that set this flag without the
- // PrintHook when calling Print Setup will fail - they
- // used to succeed.
- //
- if (pPD->Flags & PD_ENABLEPRINTHOOK)
- {
- if (!pPD->lpfnPrintHook)
- {
- StoreExtendedError(CDERR_NOHOOK);
- return (FALSE);
- }
- }
- else
- {
- pPD->lpfnPrintHook = NULL;
- }
- if (pPD->Flags & PD_ENABLEPRINTTEMPLATEHANDLE)
- {
- if (pPD->hPrintTemplate)
- {
- hDlgTemplate = pPD->hPrintTemplate;
- hInstance = g_hinst;
- }
- else
- {
- StoreExtendedError(CDERR_NOTEMPLATE);
- }
- }
- else
- {
- LPTSTR pTemplateName = NULL;
- if (pPD->Flags & PD_ENABLEPRINTTEMPLATE)
- {
- if (pPD->lpPrintTemplateName)
- {
- if (pPD->hInstance)
- {
- pTemplateName = (LPTSTR)pPD->lpPrintTemplateName;
- hInstance = pPD->hInstance;
- }
- else
- {
- StoreExtendedError(CDERR_NOHINSTANCE);
- }
- }
- else
- {
- StoreExtendedError(CDERR_NOTEMPLATE);
- }
- }
- else
- {
- hInstance = g_hinst;
- pTemplateName = (LPTSTR)(DWORD)PRINTDLGORD;
- }
- if (pTemplateName)
- {
- hDlgTemplate = PrintLoadResource( hInstance,
- pTemplateName,
- RT_DIALOG );
- }
- }
- if (!hDlgTemplate)
- {
- return (FALSE);
- }
- if (LockResource(hDlgTemplate))
- {
- glpfnPrintHook = pPD->lpfnPrintHook;
- #ifdef UNICODE
- if (pPD->Flags & CD_WOWAPP)
- {
- uiWOWFlag = SCDLG_16BIT;
- }
- fGotInput = DialogBoxIndirectParamAorW( hInstance,
- (LPDLGTEMPLATE)hDlgTemplate,
- pPD->hwndOwner,
- PrintDlgProc,
- (LPARAM)pPI,
- uiWOWFlag );
- #else
- fGotInput = DialogBoxIndirectParam( hInstance,
- (LPDLGTEMPLATE)hDlgTemplate,
- pPD->hwndOwner,
- PrintDlgProc,
- (LPARAM)pPI );
- #endif
- glpfnPrintHook = NULL;
- if (fGotInput == -1)
- {
- StoreExtendedError(CDERR_DIALOGFAILURE);
- }
- }
- else
- {
- StoreExtendedError(CDERR_LOCKRESFAILURE);
- }
- return (fGotInput);
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // PrintDisplaySetupDlg
- //
- //
- //
- ////////////////////////////////////////////////////////////////////////////
- int PrintDisplaySetupDlg(
- PPRINTINFO pPI)
- {
- LPPRINTDLG pPD = pPI->pPD;
- int fGotInput = -1;
- HANDLE hDlgTemplate = NULL;
- HANDLE hInstance;
- #ifdef UNICODE
- UINT uiWOWFlag = 0;
- #endif
- //
- // NOTE: The setup hook check must be done here rather than in
- // PrintDlgX. Old apps that set this flag without the
- // SetupHook when calling Print will fail - they
- // used to succeed.
- //
- if (pPD->Flags & PD_ENABLESETUPHOOK)
- {
- if (!pPD->lpfnSetupHook)
- {
- StoreExtendedError(CDERR_NOHOOK);
- return (FALSE);
- }
- }
- else
- {
- pPD->lpfnSetupHook = NULL;
- }
- if (pPD->Flags & PD_ENABLESETUPTEMPLATEHANDLE)
- {
- if (pPD->hSetupTemplate)
- {
- hDlgTemplate = pPD->hSetupTemplate;
- hInstance = g_hinst;
- }
- else
- {
- StoreExtendedError(CDERR_NOTEMPLATE);
- }
- }
- else
- {
- LPTSTR pTemplateName = NULL;
- if (pPD->Flags & PD_ENABLESETUPTEMPLATE)
- {
- if (pPD->lpSetupTemplateName)
- {
- if (pPD->hInstance)
- {
- pTemplateName = (LPTSTR)pPD->lpSetupTemplateName;
- hInstance = pPD->hInstance;
- }
- else
- {
- StoreExtendedError(CDERR_NOHINSTANCE);
- }
- }
- else
- {
- StoreExtendedError(CDERR_NOTEMPLATE);
- }
- }
- else
- {
- hInstance = g_hinst;
- pTemplateName = (LPTSTR)(DWORD)( (pPD->Flags & PD_PRINTSETUP)
- ? PRNSETUPDLGORD
- : PAGESETUPDLGORD );
- }
- if (pTemplateName)
- {
- hDlgTemplate = PrintLoadResource( hInstance,
- pTemplateName,
- RT_DIALOG );
- }
- }
- if (!hDlgTemplate)
- {
- return (FALSE);
- }
- if (LockResource(hDlgTemplate))
- {
- glpfnSetupHook = pPD->lpfnSetupHook;
- #ifdef UNICODE
- if (pPD->Flags & CD_WOWAPP)
- {
- uiWOWFlag = SCDLG_16BIT;
- }
- fGotInput = DialogBoxIndirectParamAorW( hInstance,
- (LPDLGTEMPLATE)hDlgTemplate,
- pPD->hwndOwner,
- (DLGPROC)PrintSetupDlgProc,
- (LPARAM)pPI,
- uiWOWFlag );
- #else
- fGotInput = DialogBoxIndirectParam( hInstance,
- (LPDLGTEMPLATE)hDlgTemplate,
- pPD->hwndOwner,
- (DLGPROC)PrintSetupDlgProc,
- (LPARAM)pPI );
- #endif
- glpfnSetupHook = NULL;
- if (fGotInput == -1)
- {
- StoreExtendedError(CDERR_DIALOGFAILURE);
- }
- }
- else
- {
- StoreExtendedError(CDERR_LOCKRESFAILURE);
- }
- return (fGotInput);
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // PrintDlgProc
- //
- // Print Dialog procedure.
- //
- ////////////////////////////////////////////////////////////////////////////
- BOOL PrintDlgProc(
- HWND hDlg,
- UINT wMsg,
- WPARAM wParam,
- LONG lParam)
- {
- PPRINTINFO pPI;
- LPPRINTDLG pPD;
- HWND hCtl;
- BOOL bTest;
- BOOL bResult;
- LPDEVMODE pDM;
- LPDEVNAMES pDN;
- if (pPI = (PPRINTINFO)GetProp(hDlg, PRNPROP))
- {
- if ((pPD = pPI->pPD) && (pPD->lpfnPrintHook))
- {
- #ifdef UNICODE
- if (pPI->ApiType == COMDLG_ANSI)
- {
- ThunkPrintDlgW2A(pPI);
- }
- #endif
- if ((bResult = (*pPD->lpfnPrintHook)(hDlg, wMsg, wParam, lParam)))
- {
- #ifdef UNICODE
- if (pPI->ApiType == COMDLG_ANSI)
- {
- ThunkPrintDlgA2W(pPI);
- }
- #endif
- return (bResult);
- }
- }
- }
- else if ( glpfnPrintHook &&
- (wMsg != WM_INITDIALOG) &&
- (bResult = (*glpfnPrintHook)(hDlg, wMsg, wParam, lParam)) )
- {
- return (bResult);
- }
- switch (wMsg)
- {
- case ( WM_INITDIALOG ) :
- {
- DWORD dwResult = 0;
- HourGlass(TRUE);
- #ifndef WINNT
- msgHELPA = RegisterWindowMessage(szCommdlgHelp);
- #endif
- SetProp(hDlg, PRNPROP, (HANDLE)lParam);
- glpfnPrintHook = NULL;
- pPI = (PPRINTINFO)lParam;
- pPD = pPI->pPD;
- if (pPI->pPSD)
- {
- TCHAR szTitle[32];
- RECT aRtDlg;
- RECT aRtGrp;
- RECT aRtYep;
- RECT aRtCan;
- HWND hBtnYep;
- HWND hBtnCan;
- RECT aRtWhere;
- RECT aRtCmmnt;
- //
- // Move the OK and Cancel buttons up underneath the
- // Printer group box and then resize the dialog
- // appropriately.
- //
- GetWindowText(GetParent(hDlg), szTitle, 32);
- SetWindowText(hDlg, szTitle);
- GetWindowRect(hDlg, &aRtDlg);
- GetWindowRect(GetDlgItem(hDlg, ID_PRINT_G_PRINTER), &aRtGrp);
- GetWindowRect(hBtnYep = GetDlgItem(hDlg, IDOK), &aRtYep);
- GetWindowRect(hBtnCan = GetDlgItem(hDlg, IDCANCEL), &aRtCan);
- ScreenToClient(hDlg , (LPPOINT)&aRtYep.left );
- ScreenToClient(hDlg , (LPPOINT)&aRtCan.left );
- ScreenToClient(hDlg , (LPPOINT)&aRtDlg.right);
- ScreenToClient(hDlg , (LPPOINT)&aRtGrp.right);
- ScreenToClient(hBtnYep, (LPPOINT)&aRtYep.right);
- ScreenToClient(hBtnCan, (LPPOINT)&aRtCan.right);
- #ifdef WINNT
- if (pPD->Flags & PD_SHOWHELP)
- {
- HWND hBtnHlp = GetDlgItem(hDlg, ID_BOTH_P_HELP);
- RECT aRtHlp;
- //
- // Also move the Help button up underneath the
- // Printer group box.
- //
- if (hBtnHlp)
- {
- GetWindowRect(hBtnHlp, &aRtHlp);
- ScreenToClient(hDlg, (LPPOINT)&aRtHlp.left);
- ScreenToClient(hBtnHlp, (LPPOINT)&aRtHlp.right);
- MoveWindow( hBtnHlp,
- aRtHlp.left,
- aRtGrp.bottom + 2 * aRtHlp.bottom / 3,
- aRtHlp.right,
- aRtHlp.bottom,
- FALSE );
- }
- }
- #endif
- MoveWindow( hBtnYep,
- aRtYep.left,
- aRtGrp.bottom + 2 * aRtYep.bottom / 3,
- aRtYep.right,
- aRtYep.bottom,
- FALSE );
- MoveWindow( hBtnCan,
- aRtCan.left,
- aRtGrp.bottom + 2 * aRtCan.bottom / 3,
- aRtCan.right,
- aRtCan.bottom,
- FALSE );
- MoveWindow( hDlg,
- aRtDlg.left,
- aRtDlg.top,
- aRtDlg.right,
- aRtGrp.bottom + 10 * aRtCan.bottom / 3,
- FALSE );
- //
- // Hide all other print dlg items.
- //
- // NOTE: Need to do a SetWindowPos to actually remove
- // the window so that the AddNetButton call does
- // not think it's there.
- //
- SetWindowPos( GetDlgItem(hDlg, ID_PRINT_X_TOFILE),
- NULL,
- 0, 0, 0, 0,
- SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOZORDER );
- SetWindowPos( GetDlgItem(hDlg, ID_PRINT_X_COLLATE),
- NULL,
- 0, 0, 0, 0,
- SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOZORDER );
- SetWindowPos( GetDlgItem(hDlg, ID_PRINT_E_FROM),
- NULL,
- 0, 0, 0, 0,
- SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOZORDER );
- SetWindowPos( GetDlgItem(hDlg, ID_PRINT_E_TO),
- NULL,
- 0, 0, 0, 0,
- SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOZORDER );
- SetWindowPos( GetDlgItem(hDlg, ID_PRINT_E_COPIES),
- NULL,
- 0, 0, 0, 0,
- SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOZORDER );
- SetWindowPos( GetDlgItem(hDlg, ID_PRINT_G_RANGE),
- NULL,
- 0, 0, 0, 0,
- SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOZORDER );
- SetWindowPos( GetDlgItem(hDlg, ID_PRINT_G_COPIES),
- NULL,
- 0, 0, 0, 0,
- SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOZORDER );
- SetWindowPos( GetDlgItem(hDlg, ID_PRINT_I_COLLATE),
- NULL,
- 0, 0, 0, 0,
- SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOZORDER );
- SetWindowPos( GetDlgItem(hDlg, ID_PRINT_R_ALL),
- NULL,
- 0, 0, 0, 0,
- SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOZORDER );
- SetWindowPos( GetDlgItem(hDlg, ID_PRINT_R_SELECTION),
- NULL,
- 0, 0, 0, 0,
- SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOZORDER );
- SetWindowPos( GetDlgItem(hDlg, ID_PRINT_R_PAGES),
- NULL,
- 0, 0, 0, 0,
- SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOZORDER );
- SetWindowPos( GetDlgItem(hDlg, ID_PRINT_S_FROM),
- NULL,
- 0, 0, 0, 0,
- SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOZORDER );
- SetWindowPos( GetDlgItem(hDlg, ID_PRINT_S_TO),
- NULL,
- 0, 0, 0, 0,
- SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOZORDER );
- SetWindowPos( GetDlgItem(hDlg, ID_PRINT_S_COPIES),
- NULL,
- 0, 0, 0, 0,
- SWP_HIDEWINDOW | SWP_NOACTIVATE | SWP_NOZORDER );
- //
- // Enlarge the comment edit control, since the
- // "print to file" check box is hidden.
- //
- GetWindowRect(GetDlgItem(hDlg, ID_BOTH_S_WHERE), &aRtWhere);
- GetWindowRect( hCtl = GetDlgItem(hDlg, ID_BOTH_S_COMMENT),
- &aRtCmmnt );
- ScreenToClient(hDlg, (LPPOINT)&aRtCmmnt.left);
- MoveWindow( hCtl,
- aRtCmmnt.left,
- aRtCmmnt.top,
- aRtWhere.right - aRtWhere.left,
- aRtWhere.bottom - aRtWhere.top,
- FALSE );
- #ifdef WINNT
- //
- // Add or hide net button, if necessary.
- //
- if ((pPD->Flags & PD_NONETWORKBUTTON))
- {
- if (hCtl = GetDlgItem(hDlg, ID_BOTH_P_NETWORK))
- {
- EnableWindow(hCtl, FALSE);
- ShowWindow(hCtl, SW_HIDE);
- }
- }
- else
- {
- AddNetButton( hDlg,
- g_hinst,
- FILE_BOTTOM_MARGIN,
- TRUE,
- FALSE,
- TRUE );
- //
- // The button can be added in two ways -
- // statically (they have it predefined in their template) and
- // dynamically (successful call to AddNetButton).
- //
- if (!IsNetworkInstalled())
- {
- hCtl = GetDlgItem(hDlg, ID_BOTH_P_NETWORK);
- EnableWindow(hCtl, FALSE);
- ShowWindow(hCtl, SW_HIDE);
- }
- }
- #endif
- }
- else
- {
- if (pPD->Flags & PD_COLLATE)
- {
- pPI->Status |= PI_COLLATE_REQUESTED;
- }
- }
- if (!PrintInitGeneral(hDlg, ID_PRINT_C_NAME, pPI) ||
- ((dwResult = PrintInitPrintDlg( hDlg,
- wParam,
- pPI )) == 0xFFFFFFFF))
- {
- RemoveProp(hDlg, PRNPROP);
- EndDialog(hDlg, -2);
- }
- HourGlass(FALSE);
- bResult = (dwResult == 1);
- return (bResult);
- }
- case ( WM_COMMAND ) :
- {
- bResult = FALSE;
- if (!pPI)
- {
- break;
- }
- switch (GET_WM_COMMAND_ID(wParam, lParam))
- {
- case ( ID_PRINT_C_NAME ) : // Printer Name combobox
- {
- if (GET_WM_COMMAND_CMD(wParam, lParam) == CBN_SELCHANGE)
- {
- PrintPrinterChanged(hDlg, ID_PRINT_C_NAME, pPI);
- }
- else if ( (GET_WM_COMMAND_CMD(wParam, lParam) == CBN_DROPDOWN) &&
- !(pPI->Status & PI_PRINTERS_ENUMERATED) )
- {
- //
- // Enumerate printers if this hasn't been done yet.
- //
- PrintEnumAndSelect( hDlg,
- ID_PRINT_C_NAME,
- pPI,
- (pPI->pCurPrinter)
- ? pPI->pCurPrinter->pPrinterName
- : NULL,
- TRUE );
- }
- break;
- }
- case ( ID_BOTH_P_PROPERTIES ) : // Properties... button
- {
- PrintChangeProperties(hDlg, ID_PRINT_C_NAME, pPI);
- break;
- }
- case ( ID_PRINT_P_SETUP ) : // Setup... button
- {
- DWORD dwFlags = pPD->Flags;
- HWND hwndOwner = pPD->hwndOwner;
- pPD->Flags |= PD_PRINTSETUP;
- pPD->Flags &= ~(PD_RETURNDC | PD_RETURNIC);
- pPI->Status |= PI_PRINTDLGX_RECURSE;
- pPD->hwndOwner = hDlg;
- if (PrintDlgX(pPI))
- {
- if (!PrintInitBannerAndQuality(hDlg, pPI, pPD))
- {
- StoreExtendedError(CDERR_GENERALCODES);
- }
- }
- pPI->Status &= ~PI_PRINTDLGX_RECURSE;
- pPD->Flags = dwFlags;
- pPD->hwndOwner = hwndOwner;
- break;
- }
- case ( ID_PRINT_R_ALL ) : // Print Range - All
- case ( ID_PRINT_R_SELECTION ) : // Print Range - Selection
- case ( ID_PRINT_R_PAGES ) : // Print Range - Pages (From, To)
- {
- CheckRadioButton( hDlg,
- ID_PRINT_R_ALL,
- ID_PRINT_R_PAGES,
- GET_WM_COMMAND_ID(wParam, lParam) );
- //
- // Only move the the focus to the "From" control when
- // the up/down arrow is NOT used.
- //
- if ( !IS_KEY_PRESSED(VK_UP) &&
- !IS_KEY_PRESSED(VK_DOWN) &&
- ((BOOL)(GET_WM_COMMAND_ID(wParam, lParam) == ID_PRINT_R_PAGES)) )
- {
- SendMessage( hDlg,
- WM_NEXTDLGCTL,
- (WPARAM)GetDlgItem(hDlg, ID_PRINT_E_FROM),
- 1L );
- }
- break;
- }
- case ( ID_PRINT_E_FROM ) : // From (Print Range - Pages)
- {
- //
- // Only enable the "To" control if the "From" control
- // contains a value.
- //
- GetDlgItemInt(hDlg, ID_PRINT_E_FROM, &bTest, FALSE);
- EnableWindow(GetDlgItem(hDlg, ID_PRINT_S_TO), bTest);
- EnableWindow(GetDlgItem(hDlg, ID_PRINT_E_TO), bTest);
- // FALL THRU...
- }
- case ( ID_PRINT_E_TO ) : // To (Print Range - Pages)
- {
- if (GET_WM_COMMAND_CMD(wParam, lParam) == EN_CHANGE)
- {
- CheckRadioButton( hDlg,
- ID_PRINT_R_ALL,
- ID_PRINT_R_PAGES,
- ID_PRINT_R_PAGES );
- }
- break;
- }
- case ( ID_PRINT_X_COLLATE ) : // Collate check box
- {
- if (hCtl = GetDlgItem(hDlg, ID_PRINT_I_COLLATE))
- {
- ShowWindow(hCtl, SW_HIDE);
- SendMessage( hCtl,
- STM_SETICON,
- IsDlgButtonChecked(hDlg, ID_PRINT_X_COLLATE)
- ? (LONG)hIconCollate
- : (LONG)hIconNoCollate,
- 0L );
- ShowWindow(hCtl, SW_SHOW);
- if (IsDlgButtonChecked(hDlg, ID_PRINT_X_COLLATE))
- {
- pPI->Status |= PI_COLLATE_REQUESTED;
- }
- else
- {
- pPI->Status &= ~PI_COLLATE_REQUESTED;
- }
- }
- break;
- }
- case ( ID_BOTH_P_NETWORK ) : // Network... button
- {
- #ifdef WINNT
- HANDLE hPrinter;
- DWORD cbPrinter = 0;
- LPPRINTER_INFO_2 pPrinter = NULL;
- hPrinter = (HANDLE)(*WinSpool_ConnectToPrinterDlg)(hDlg, 0);
- if (hPrinter)
- {
- if (!(*WinSpool_GetPrinter)( hPrinter,
- 2,
- (LPBYTE)pPrinter,
- cbPrinter,
- &cbPrinter ))
- {
- if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
- {
- if (pPrinter = LocalAlloc(LPTR, cbPrinter))
- {
- if (!(*WinSpool_GetPrinter)(
- hPrinter,
- 2,
- (LPBYTE)pPrinter,
- cbPrinter,
- &cbPrinter ))
- {
- StoreExtendedError(PDERR_PRINTERNOTFOUND);
- }
- else
- {
- SendDlgItemMessage( hDlg,
- ID_PRINT_C_NAME,
- CB_RESETCONTENT,
- 0,
- 0 );
- PrintEnumAndSelect( hDlg,
- ID_PRINT_C_NAME,
- pPI,
- pPrinter->pPrinterName,
- TRUE );
- }
- }
- else
- {
- StoreExtendedError(CDERR_MEMALLOCFAILURE);
- }
- }
- else
- {
- StoreExtendedError(PDERR_SETUPFAILURE);
- }
- }
- if (!GetStoredExtendedError())
- {
- SendDlgItemMessage( hDlg,
- ID_PRINT_C_NAME,
- CB_SETCURSEL,
- (WPARAM)SendDlgItemMessage(
- hDlg,
- ID_PRINT_C_NAME,
- CB_FINDSTRING,
- 0,
- (LPARAM)pPrinter->pPrinterName ),
- (LPARAM)0 );
- PrintPrinterChanged(hDlg, ID_PRINT_C_NAME, pPI);
- }
- LocalFree(pPrinter);
- (*WinSpool_ClosePrinter)(hPrinter);
- }
- #else
- if (!hMPR)
- {
- hMPR = LoadLibrary(szMprDll);
- }
- if (hMPR && !MPR_WNetConnectionDialog)
- {
- MPR_WNetConnectionDialog = (LPFNWNETCONNECTIONDIALOG)
- GetProcAddress(hMPR, szWNetConnectionDialog);
- }
- if (MPR_WNetConnectionDialog)
- {
- (*MPR_WNetConnectionDialog)(hDlg, RESOURCETYPE_PRINT);
- }
- #endif
- break;
- }
- case ( ID_BOTH_P_HELP ) : // Help button
- {
- #ifdef UNICODE
- if (pPI->ApiType == COMDLG_ANSI)
- {
- if (msgHELPA && pPD->hwndOwner)
- {
- SendMessage( pPD->hwndOwner,
- msgHELPA,
- (WPARAM)hDlg,
- (DWORD)pPI->pPDA );
- }
- }
- else
- #endif
- {
- if (msgHELPW && pPD->hwndOwner)
- {
- SendMessage( pPD->hwndOwner,
- msgHELPW,
- (WPARAM)hDlg,
- (DWORD)pPD );
- }
- }
- break;
- }
- case ( IDOK ) : // OK button
- {
- bResult = TRUE;
- if (!(pPI->pPSD))
- {
- pPD->Flags &= ~((DWORD)( PD_PRINTTOFILE |
- PD_PAGENUMS |
- PD_SELECTION |
- PD_COLLATE ));
- pPD->nCopies = (WORD)GetDlgItemInt( hDlg,
- ID_PRINT_E_COPIES,
- &bTest,
- FALSE );
- if ((!bTest) || (!pPD->nCopies))
- {
- PrintEditError( hDlg,
- ID_PRINT_E_COPIES,
- iszCopiesZero );
- return (TRUE);
- }
- if (IsDlgButtonChecked(hDlg, ID_PRINT_R_SELECTION))
- {
- pPD->Flags |= PD_SELECTION;
- }
- else if (IsDlgButtonChecked(hDlg, ID_PRINT_R_PAGES))
- {
- //
- // Check the "From" and "To" values.
- //
- pPD->Flags |= PD_PAGENUMS;
- pPD->nFromPage = (WORD)GetDlgItemInt( hDlg,
- ID_PRINT_E_FROM,
- &bTest,
- FALSE );
- if (!bTest)
- {
- PrintEditError( hDlg,
- ID_PRINT_E_FROM,
- iszPageFromError );
- return (TRUE);
- }
- pPD->nToPage = (WORD)GetDlgItemInt( hDlg,
- ID_PRINT_E_TO,
- &bTest,
- FALSE );
- if (!bTest)
- {
- TCHAR szBuf[PAGE_EDIT_SIZE + 1];
- if (GetDlgItemText( hDlg,
- ID_PRINT_E_TO,
- szBuf,
- PAGE_EDIT_SIZE + 1 ))
- {
- PrintEditError( hDlg,
- ID_PRINT_E_TO,
- iszPageToError );
- return (TRUE);
- }
- else
- {
- pPD->nToPage = pPD->nFromPage;
- }
- }
- if ( (pPD->nFromPage < pPD->nMinPage) ||
- (pPD->nFromPage > pPD->nMaxPage) )
- {
- PrintEditError( hDlg,
- ID_PRINT_E_FROM,
- iszPageRangeError,
- pPD->nMinPage,
- pPD->nMaxPage );
- return (TRUE);
- }
- if ( (pPD->nToPage < pPD->nMinPage) ||
- (pPD->nToPage > pPD->nMaxPage) )
- {
- PrintEditError( hDlg,
- ID_PRINT_E_TO,
- iszPageRangeError,
- pPD->nMinPage,
- pPD->nMaxPage );
- return (TRUE);
- }
- if (pPD->nFromPage > pPD->nToPage)
- {
- PrintEditError( hDlg,
- ID_PRINT_E_FROM,
- iszFromToError );
- return (TRUE);
- }
- }
- }
- HourGlass(TRUE);
- if (IsDlgButtonChecked(hDlg, ID_PRINT_X_TOFILE))
- {
- pPD->Flags |= PD_PRINTTOFILE;
- }
- if ( (hCtl = GetDlgItem(hDlg, ID_PRINT_X_COLLATE)) &&
- IsWindowEnabled(hCtl) &&
- IsDlgButtonChecked(hDlg, ID_PRINT_X_COLLATE) )
- {
- pPD->Flags |= PD_COLLATE;
- }
- if (!PrintSetCopies(hDlg, pPI, ID_PRINT_C_NAME))
- {
- HourGlass(FALSE);
- return (TRUE);
- }
- pDM = NULL;
- pDN = NULL;
- if (pPD->hDevMode)
- {
- pDM = GlobalLock(pPD->hDevMode);
- }
- if (pPD->hDevNames)
- {
- pDN = GlobalLock(pPD->hDevNames);
- }
- if (pDM && pDN)
- {
- DWORD nNum;
- if ( GetDlgItem(hDlg, ID_PRINT_C_QUALITY) &&
- (nNum = SendDlgItemMessage( hDlg,
- ID_PRINT_C_QUALITY,
- CB_GETCURSEL,
- 0,
- 0L )) != CB_ERR )
- {
- pDM->dmPrintQuality =
- (WORD)SendDlgItemMessage( hDlg,
- ID_PRINT_C_QUALITY,
- CB_GETITEMDATA,
- (WPARAM)nNum,
- 0L );
- }
- PrintReturnICDC(pPD, pDN, pDM);
- }
- if (pDM)
- {
- GlobalUnlock(pPD->hDevMode);
- }
- if (pDN)
- {
- GlobalUnlock(pPD->hDevNames);
- }
- #ifdef UNICODE
- if (pPI->bUseExtDeviceMode)
- {
- UpdateSpoolerInfo(pPI);
- }
- #endif
- // FALL THRU...
- }
- case ( IDCANCEL ) : // Cancel button
- case ( IDABORT ) :
- {
- HourGlass(TRUE);
- glpfnPrintHook = pPD->lpfnPrintHook;
- RemoveProp(hDlg, PRNPROP);
- EndDialog(hDlg, bResult);
- HourGlass(FALSE);
- break;
- }
- default :
- {
- return (FALSE);
- break;
- }
- }
- break;
- }
- case ( WM_MEASUREITEM ) :
- {
- PrintMeasureItem(hDlg, (LPMEASUREITEMSTRUCT)lParam);
- break;
- }
- case ( WM_HELP ) :
- {
- if (IsWindowEnabled(hDlg))
- {
- WinHelp( (HWND)((LPHELPINFO)lParam)->hItemHandle,
- NULL,
- HELP_WM_HELP,
- (DWORD)(LPTSTR)aPrintHelpIDs );
- }
- break;
- }
- case ( WM_CONTEXTMENU ) :
- {
- if (IsWindowEnabled(hDlg))
- {
- WinHelp( (HWND)wParam,
- NULL,
- HELP_CONTEXTMENU,
- (DWORD)(LPVOID)aPrintHelpIDs );
- }
- break;
- }
- case ( WM_CTLCOLOREDIT ) :
- {
- if (GetWindowLong((HWND)lParam, GWL_STYLE) & ES_READONLY)
- {
- return ( SendMessage(hDlg, WM_CTLCOLORDLG, wParam, lParam) );
- }
- // FALL THRU...
- }
- default :
- {
- return (FALSE);
- break;
- }
- }
- return (TRUE);
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // PrintSetupDlgProc
- //
- // Print Setup Dialog proc.
- //
- ////////////////////////////////////////////////////////////////////////////
- BOOL PrintSetupDlgProc(
- HWND hDlg,
- UINT wMsg,
- WPARAM wParam,
- LONG lParam)
- {
- PPRINTINFO pPI;
- LPPRINTDLG pPD;
- BOOL bResult;
- UINT uCmdId;
- LPDEVMODE pDM;
- if (pPI = (PPRINTINFO)GetProp(hDlg, PRNPROP))
- {
- if ((pPD = pPI->pPD) && (pPD->lpfnSetupHook))
- {
- #ifdef UNICODE
- if (pPI->ApiType == COMDLG_ANSI)
- {
- ThunkPrintDlgW2A(pPI);
- TransferPDA2PSD(pPI);
- bResult = (*pPD->lpfnSetupHook)(hDlg, wMsg, wParam, lParam);
- if (bResult)
- {
- TransferPSD2PDA(pPI);
- ThunkPrintDlgA2W(pPI);
- TransferPD2PSD(pPI);
- return (bResult);
- }
- }
- else
- #endif
- {
- TransferPD2PSD(pPI);
- bResult = (*pPD->lpfnSetupHook)(hDlg, wMsg, wParam, lParam);
- if (bResult)
- {
- TransferPSD2PD(pPI);
- return (bResult);
- }
- }
- }
- }
- else if ( glpfnSetupHook &&
- (wMsg != WM_INITDIALOG) &&
- (bResult = (*glpfnSetupHook)(hDlg, wMsg, wParam, lParam)) )
- {
- return (bResult);
- }
- switch (wMsg)
- {
- case ( WM_INITDIALOG ) :
- {
- DWORD dwResult = 0;
- HourGlass(TRUE);
- #ifndef WINNT
- msgHELPA = RegisterWindowMessage(szCommdlgHelp);
- #endif
- SetProp(hDlg, PRNPROP, (HANDLE)lParam);
- pPI = (PPRINTINFO)lParam;
- pPI->bKillFocus = FALSE;
- glpfnSetupHook = NULL;
- if (!PrintInitGeneral(hDlg, ID_SETUP_C_NAME, pPI) ||
- ((dwResult = PrintInitSetupDlg( hDlg,
- wParam,
- pPI )) == 0xFFFFFFFF))
- {
- RemoveProp(hDlg, PRNPROP);
- EndDialog(hDlg, FALSE);
- }
- else if (pPI->pPSD && (pPI->pPSD->Flags & PSD_RETURNDEFAULT))
- {
- //
- // PSD_RETURNDEFAULT goes through the entire initialization
- // in order to set rtMinMargin, rtMargin, and ptPaperSize.
- // Win95 Notepad relies on this behavior.
- //
- SendMessage(hDlg, WM_COMMAND, IDOK, 0);
- }
- HourGlass(FALSE);
- bResult = (dwResult == 1);
- return (bResult);
- }
- case ( WM_COMMAND ) :
- {
- bResult = FALSE;
- if (!pPI)
- {
- break;
- }
- switch (uCmdId = GET_WM_COMMAND_ID(wParam, lParam))
- {
- case ( ID_SETUP_C_NAME ) : // Printer Name combobox
- {
- if ( (GET_WM_COMMAND_CMD(wParam, lParam) == CBN_DROPDOWN) &&
- !(pPI->Status & PI_PRINTERS_ENUMERATED) )
- {
- //
- // Enumerate printers if this hasn't been done yet.
- //
- PrintEnumAndSelect( hDlg,
- ID_SETUP_C_NAME,
- pPI,
- (pPI->pCurPrinter)
- ? pPI->pCurPrinter->pPrinterName
- : NULL,
- TRUE );
- }
- if (GET_WM_COMMAND_CMD(wParam, lParam) != CBN_SELCHANGE)
- {
- break;
- }
- if ( !GetDlgItem(hDlg, ID_SETUP_R_SPECIFIC) ||
- IsDlgButtonChecked(hDlg, ID_SETUP_R_SPECIFIC) )
- {
- PrintPrinterChanged(hDlg, ID_SETUP_C_NAME, pPI);
- break;
- }
- uCmdId = ID_SETUP_R_SPECIFIC;
- // FALL THRU...
- }
- case ( ID_SETUP_R_DEFAULT ) : // Default printer
- case ( ID_SETUP_R_SPECIFIC ) : // Specific printer
- {
- //
- // Sanity check for Publisher bug where user tries to
- // set focus to ID_SETUP_R_DEFAULT on exit if the
- // dialog has no default printer.
- //
- if (pPI->hCurPrinter)
- {
- HWND hCmb;
- DWORD dwStyle;
- hCmb = GetDlgItem(hDlg, ID_SETUP_C_NAME);
- if (hCmb && (uCmdId == ID_SETUP_R_DEFAULT))
- {
- if (!(pPI->Status & PI_PRINTERS_ENUMERATED))
- {
- //
- // Enumerate printers if this hasn't been
- // done yet. Otherwise, the default printer
- // may not be found in the list box when
- // switching from Specific to Default.
- //
- PrintEnumAndSelect( hDlg,
- ID_SETUP_C_NAME,
- pPI,
- NULL,
- TRUE );
- }
- SendMessage( hCmb,
- CB_SETCURSEL,
- (WPARAM)SendMessage(
- hCmb,
- CB_FINDSTRINGEXACT,
- (WPARAM)-1,
- (LPARAM)(pPI->szDefaultPrinter) ),
- (LPARAM)0 );
- }
- PrintPrinterChanged(hDlg, ID_SETUP_C_NAME, pPI);
- CheckRadioButton( hDlg,
- ID_SETUP_R_DEFAULT,
- ID_SETUP_R_SPECIFIC,
- uCmdId);
- dwStyle = GetWindowLong(hCmb, GWL_STYLE);
- if (uCmdId == ID_SETUP_R_DEFAULT)
- {
- dwStyle &= ~WS_TABSTOP;
- }
- else
- {
- dwStyle |= WS_TABSTOP;
- SendMessage(hDlg, WM_NEXTDLGCTL, (WPARAM)hCmb, 1L);
- }
- SetWindowLong(hCmb, GWL_STYLE, dwStyle);
- }
- break;
- }
- case ( ID_BOTH_P_PROPERTIES ) : // Properties... button
- {
- PrintChangeProperties(hDlg, ID_SETUP_C_NAME, pPI);
- break;
- }
- case ( ID_SETUP_P_MORE ) : // More... button
- {
- pDM = GlobalLock(pPD->hDevMode);
- (*WinSpool_AdvancedDocProps)(
- hDlg,
- pPI->hCurPrinter,
- (pPI->pCurPrinter)
- ? pPI->pCurPrinter->pPrinterName
- : NULL,
- pDM,
- pDM );
- GlobalUnlock(pPD->hDevMode);
- SendMessage( hDlg,
- WM_NEXTDLGCTL,
- (WPARAM)GetDlgItem(hDlg, IDOK),
- 1L );
- break;
- }
- case ( ID_SETUP_R_PORTRAIT ) : // Portrait
- case ( ID_SETUP_R_LANDSCAPE ) : // Landscape
- {
- if ((pPD->hDevMode) && (pDM = GlobalLock(pPD->hDevMode)))
- {
- PrintSetOrientation( hDlg,
- pPI,
- pDM,
- pPI->uiOrientationID,
- uCmdId );
- GlobalUnlock(pPD->hDevMode);
- }
- // FALL THRU ...
- }
- case ( ID_SETUP_R_NONE ) : // None (2-Sided)
- case ( ID_SETUP_R_LONG ) : // Long Side (2-Sided)
- case ( ID_SETUP_R_SHORT ) : // Short Side (2-Sided)
- {
- if ((pPD->hDevMode) && (pDM = GlobalLock(pPD->hDevMode)))
- {
- PrintSetDuplex(hDlg, pDM, uCmdId);
- GlobalUnlock(pPD->hDevMode);
- }
- break;
- }
- case ( ID_SETUP_C_SIZE ) : // Size combobox
- {
- UINT Orientation;
- if (GET_WM_COMMAND_CMD(wParam, lParam) == CBN_SELCHANGE)
- {
- if ((pPD->hDevMode) && (pDM = GlobalLock(pPD->hDevMode)))
- {
- // pDM->dmFields |= DM_PAPERSIZE;
- pDM->dmPaperSize =
- (SHORT)SendMessage( (HWND)lParam,
- CB_GETITEMDATA,
- SendMessage( (HWND)lParam,
- CB_GETCURSEL,
- 0,
- 0L ),
- 0L );
- Orientation =
- IsDlgButtonChecked(hDlg, ID_SETUP_R_PORTRAIT)
- ? ID_SETUP_R_PORTRAIT
- : ID_SETUP_R_LANDSCAPE;
- PrintSetOrientation( hDlg,
- pPI,
- pDM,
- Orientation,
- Orientation );
- GlobalUnlock(pPD->hDevMode);
- }
- }
- break;
- }
- case ( ID_SETUP_C_SOURCE ) : // Source combobox
- {
- if (GET_WM_COMMAND_CMD(wParam, lParam) == CBN_SELCHANGE)
- {
- if ((pPD->hDevMode) && (pDM = GlobalLock(pPD->hDevMode)))
- {
- // pDM->dmFields |= DM_DEFAULTSOURCE;
- pDM->dmDefaultSource =
- (SHORT)SendMessage( (HWND)lParam,
- CB_GETITEMDATA,
- SendMessage( (HWND)lParam,
- CB_GETCURSEL,
- 0,
- 0L ),
- 0L );
- GlobalUnlock(pPD->hDevMode);
- }
- }
- break;
- }
- case ( ID_SETUP_E_LEFT ) : // Left (Margins)
- case ( ID_SETUP_E_TOP ) : // Top (Margins)
- case ( ID_SETUP_E_RIGHT ) : // Right (Margins)
- case ( ID_SETUP_E_BOTTOM ) : // Bottom (Margins)
- {
- if (pPI->bKillFocus)
- {
- break;
- }
- switch (GET_WM_COMMAND_CMD(wParam, lParam))
- {
- case ( EN_KILLFOCUS ) :
- {
- pPI->bKillFocus = TRUE;
- PrintSetMargin( hDlg,
- pPI,
- uCmdId,
- *((LONG*)&pPI->pPSD->rtMargin +
- uCmdId - ID_SETUP_E_LEFT) );
- pPI->bKillFocus = FALSE;
- break;
- }
- case ( EN_CHANGE ) :
- {
- HWND hSample;
- PrintGetMargin( GET_WM_COMMAND_HWND(wParam, lParam),
- pPI,
- *((LONG*)&pPI->pPSD->rtMinMargin +
- uCmdId - ID_SETUP_E_LEFT),
- (LONG*)&pPI->pPSD->rtMargin +
- uCmdId - ID_SETUP_E_LEFT,
- (LONG*)&pPI->RtMarginMMs +
- uCmdId - ID_SETUP_E_LEFT );
- if (hSample = GetDlgItem(hDlg, ID_SETUP_W_SAMPLE))
- {
- RECT rect;
- GetClientRect(hSample, &rect);
- InflateRect(&rect, -1, -1);
- InvalidateRect(hSample, &rect, TRUE);
- }
- break;
- }
- }
- break;
- }
- case ( ID_SETUP_P_PRINTER ) : // Printer... button
- {
- //
- // Save a copy of the original values.
- //
- HWND hwndOwner = pPD->hwndOwner;
- DWORD dwFlags = pPD->Flags;
- HINSTANCE hInstance = pPD->hInstance;
- LPCTSTR lpPrintTemplateName = pPD->lpPrintTemplateName;
- //
- // Set up pPI so that PrintDlgX can do all the work.
- //
- pPD->hwndOwner = hDlg;
- pPD->Flags &= ~( PD_ENABLEPRINTTEMPLATEHANDLE |
- PD_RETURNIC |
- PD_RETURNDC |
- PD_PAGESETUP );
- pPD->Flags |= PD_ENABLEPRINTTEMPLATE;
- pPD->hInstance = g_hinst;
- pPD->lpPrintTemplateName = MAKEINTRESOURCE(PRINTDLGORD);
- pPI->Status |= PI_PRINTDLGX_RECURSE;
- if (PrintDlgX(pPI))
- {
- PrintUpdateSetupDlg( hDlg,
- pPI,
- GlobalLock(pPD->hDevMode),
- TRUE );
- GlobalUnlock(pPD->hDevMode);
- }
- //
- // Restore the original values.
- //
- pPD->hwndOwner = hwndOwner;
- pPD->Flags = dwFlags;
- pPD->hInstance = hInstance;
- pPD->lpPrintTemplateName = lpPrintTemplateName;
- pPI->Status &= ~PI_PRINTDLGX_RECURSE;
- //
- // Set the keyboard focus to the OK button.
- //
- SendMessage( hDlg,
- WM_NEXTDLGCTL,
- (WPARAM)GetDlgItem(hDlg, IDOK),
- 1L );
- HourGlass(FALSE);
- break;
- }
- case ( ID_BOTH_P_NETWORK ) : // Network... button
- {
- #ifdef WINNT
- HANDLE hPrinter;
- DWORD cbPrinter = 0;
- LPPRINTER_INFO_2 pPrinter = NULL;
- hPrinter = (HANDLE)(*WinSpool_ConnectToPrinterDlg)(hDlg, 0);
- if (hPrinter)
- {
- if (!(*WinSpool_GetPrinter)(
- hPrinter,
- 2,
- (LPBYTE)pPrinter,
- cbPrinter,
- &cbPrinter ))
- {
- if (GetLastError() == ERROR_INSUFFICIENT_BUFFER)
- {
- if (pPrinter = LocalAlloc(LPTR, cbPrinter))
- {
- if (!(*WinSpool_GetPrinter)(
- hPrinter,
- 2,
- (LPBYTE)pPrinter,
- cbPrinter,
- &cbPrinter ))
- {
- StoreExtendedError(PDERR_PRINTERNOTFOUND);
- }
- else
- {
- SendDlgItemMessage( hDlg,
- ID_SETUP_C_NAME,
- CB_RESETCONTENT,
- 0,
- 0 );
- PrintEnumAndSelect( hDlg,
- ID_SETUP_C_NAME,
- pPI,
- pPrinter->pPrinterName,
- TRUE );
- }
- }
- else
- {
- StoreExtendedError(CDERR_MEMALLOCFAILURE);
- }
- }
- else
- {
- StoreExtendedError(PDERR_SETUPFAILURE);
- }
- }
- if (!GetStoredExtendedError())
- {
- SendDlgItemMessage( hDlg,
- ID_SETUP_C_NAME,
- CB_SETCURSEL,
- (WPARAM)SendDlgItemMessage(
- hDlg,
- ID_SETUP_C_NAME,
- CB_FINDSTRING,
- 0,
- (LPARAM)pPrinter->pPrinterName ),
- (LPARAM)0 );
- PrintPrinterChanged(hDlg, ID_SETUP_C_NAME, pPI);
- }
- LocalFree(pPrinter);
- (*WinSpool_ClosePrinter)(hPrinter);
- }
- #else
- if (!hMPR)
- {
- hMPR = LoadLibrary(szMprDll);
- }
- if (hMPR && !MPR_WNetConnectionDialog)
- {
- MPR_WNetConnectionDialog = (LPFNWNETCONNECTIONDIALOG)
- GetProcAddress(hMPR, szWNetConnectionDialog);
- }
- if (MPR_WNetConnectionDialog)
- {
- (*MPR_WNetConnectionDialog)(hDlg, RESOURCETYPE_PRINT);
- }
- #endif
- break;
- }
- case ( ID_BOTH_P_HELP ) : // Help button
- {
- #ifdef UNICODE
- if (pPI->ApiType == COMDLG_ANSI)
- {
- if (msgHELPA && pPD->hwndOwner)
- {
- SendMessage( pPD->hwndOwner,
- msgHELPA,
- (WPARAM)hDlg,
- (LPARAM)pPI->pPDA );
- }
- }
- else
- #endif
- {
- if (msgHELPW && pPD->hwndOwner)
- {
- SendMessage( pPD->hwndOwner,
- msgHELPW,
- (WPARAM)hDlg,
- (LPARAM)pPD );
- }
- }
- break;
- }
- case ( IDOK ) : // OK button
- {
- LPPAGESETUPDLG pPSD = pPI->pPSD;
- int i;
- if (pPSD)
- {
- if ((pPSD->rtMinMargin.left + pPSD->rtMinMargin.right >
- pPSD->ptPaperSize.x) ||
- (pPSD->rtMinMargin.top + pPSD->rtMinMargin.bottom >
- pPSD->ptPaperSize.y))
- {
- //
- // This is an unprintable case that can happen.
- // Let's assume that the driver is at fault
- // and accept whatever the user entered.
- //
- }
- else if (pPSD->rtMargin.left + pPSD->rtMargin.right >
- pPSD->ptPaperSize.x)
- {
- i = (pPSD->rtMargin.left >= pPSD->rtMargin.right)
- ? ID_SETUP_E_LEFT
- : ID_SETUP_E_RIGHT;
- PrintEditError(hDlg, i, iszBadMarginError);
- return (TRUE);
- }
- else if (pPSD->rtMargin.top + pPSD->rtMargin.bottom >
- pPSD->ptPaperSize.y)
- {
- i = (pPSD->rtMargin.top >= pPSD->rtMargin.bottom)
- ? ID_SETUP_E_TOP
- : ID_SETUP_E_BOTTOM;
- PrintEditError(hDlg, i, iszBadMarginError);
- return (TRUE);
- }
- }
- else
- {
- if (!PrintSetCopies(hDlg, pPI, ID_SETUP_C_NAME))
- {
- return (TRUE);
- }
- }
- bResult = TRUE;
- SetFocus( GetDlgItem(hDlg, IDOK) );
- // FALL THRU...
- }
- case ( IDCANCEL ) : // Cancel button
- case ( IDABORT ) :
- {
- HourGlass(TRUE);
- if (bResult)
- {
- PrintGetSetupInfo(hDlg, pPD);
- #ifdef UNICODE
- if (pPI->bUseExtDeviceMode)
- {
- UpdateSpoolerInfo(pPI);
- }
- #endif
- }
- else
- {
- SetFocus( GetDlgItem(hDlg, IDCANCEL) );
- }
- pPI->bKillFocus = TRUE;
- glpfnSetupHook = pPD->lpfnSetupHook;
- RemoveProp(hDlg, PRNPROP);
- EndDialog(hDlg, bResult);
- break;
- }
- default :
- {
- return (FALSE);
- break;
- }
- }
- break;
- }
- case ( WM_MEASUREITEM ) :
- {
- PrintMeasureItem(hDlg, (LPMEASUREITEMSTRUCT)lParam);
- break;
- }
- case ( WM_HELP ) :
- {
- if (IsWindowEnabled(hDlg))
- {
- WinHelp( (HWND)((LPHELPINFO)lParam)->hItemHandle,
- NULL,
- HELP_WM_HELP,
- (DWORD)(LPTSTR)((pPD->Flags & PD_PRINTSETUP)
- ? aPrintSetupHelpIDs
- : aPageSetupHelpIDs) );
- }
- break;
- }
- case ( WM_CONTEXTMENU ) :
- {
- if (IsWindowEnabled(hDlg))
- {
- WinHelp( (HWND)wParam,
- NULL,
- HELP_CONTEXTMENU,
- (DWORD)(LPVOID)((pPD->Flags & PD_PRINTSETUP)
- ? aPrintSetupHelpIDs
- : aPageSetupHelpIDs) );
- }
- break;
- }
- case ( WM_CTLCOLOREDIT ) :
- {
- if (GetWindowLong((HWND)lParam, GWL_STYLE) & ES_READONLY)
- {
- return ( SendMessage(hDlg, WM_CTLCOLORDLG, wParam, lParam) );
- }
- // FALL THRU...
- }
- default :
- {
- return (FALSE);
- break;
- }
- }
- return (TRUE);
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // PrintEditNumberOnlyProc
- //
- //
- //
- ////////////////////////////////////////////////////////////////////////////
- LONG PrintEditNumberOnlyProc(
- HWND hWnd,
- UINT msg,
- WPARAM wP,
- LPARAM lP)
- {
- if ( (msg == WM_CHAR) &&
- (wP != BACKSPACE) &&
- ((wP < TEXT('0')) || (wP > TEXT('9'))) )
- {
- MessageBeep(0);
- return (FALSE);
- }
- return ( CallWindowProc(lpEditNumOnlyProc, hWnd, msg, wP, lP) );
- }
- ////////////////////////////////////////////////////////////////////////////
- //
- // PrintEditMarginProc
- //
- //
- //
- ////////////////////////////////////////////////////////////////////////////
- LONG PrintEditMarginProc(
- HWND hWnd,
- UINT msg,
- WPARAM wP,
- LPARAM lP)