|
-
August 11th, 2004, 02:59 PM
#1
Please help------ Printer
I am trying the code below to set the printer settings so that the page setup is Landscape but its not working.
I have been stuck on it for some time now any help is very much appreciated.
HANDLE m_hDevNames=NULL,m_hDevMode=NULL;
PRINTDLG pd2;
// Retrieve MFC's default printer.
AfxGetApp()->GetPrinterDeviceDefaults(&pd2);
// Make our own private copy of MFC's DEVMODE and DEVNAMES data.
// Note: we should NOT GlobalFree the handles returned
// to us in the PRINTDLG structure, because those are the
// actual handles that MFC uses!
m_hDevMode = CopyHandle(pd2.hDevMode);
m_hDevNames = CopyHandle(pd2.hDevNames);
{
// Get default printer settings.
PRINTDLG pd;
pd.lStructSize = (DWORD) sizeof(PRINTDLG);
if (AfxGetApp()->GetPrinterDeviceDefaults(&pd))
{
// Lock memory handle.
DEVMODE FAR* pDevMode =
(DEVMODE FAR*)::GlobalLock(m_hDevMode);
LPDEVNAMES lpDevNames;
LPTSTR lpszDriverName, lpszDeviceName, lpszPortName;
HANDLE hPrinter;
TCHAR name[256];
DWORD sz=sizeof(name);
::GetDefaultPrinter(name,&sz);
//_tcscpy(lpszDeviceName,name);
if (pDevMode)
{
// Change printer settings in here.
pDevMode->dmOrientation = DMORIENT_LANDSCAPE;
// Unlock memory handle.
lpDevNames = (LPDEVNAMES)GlobalLock(pd.hDevNames);
lpszDriverName = (LPTSTR )lpDevNames + lpDevNames->wDriverOffset;
lpszDeviceName = (LPTSTR )lpDevNames + lpDevNames->wDeviceOffset;
lpszPortName = (LPTSTR )lpDevNames + lpDevNames->wOutputOffset;
BOOL hiya3 = ::OpenPrinter(name/*lpszDeviceName*/, &hPrinter, NULL);
: ocumentProperties(NULL,hPrinter,lpszDeviceName,NULL,//pDevMode,
pDevMode, DM_IN_BUFFER);//|DM_OUT_BUFFER);
// Sync the pDevMode.
// See SDK help for DocumentProperties for more info.
::ClosePrinter(hPrinter);
::GlobalUnlock(m_hDevNames);
::GlobalUnlock(m_hDevMode);
}
}
}
/////////Once above is done I am using the msword automation to print the //document
}
VARIANT vName;
vName.vt = VT_BSTR;
vName.bstrVal = SysAllocString(L"WdPrintOutRange.wdPrintFromTo");
VARIANT vName2;
vName2.vt = VT_BSTR;
vName2.bstrVal = SysAllocString(L"1-2");
TRY
{Doc.PrintOut(covFalse, // Background.
covOptional, // Append.
covOptional, // Range.
covOptional, // OutputFileName.
covOptional, // // From.
covOptional, // // To.
covOptional, // Item.
COleVariant((long)1), // Copies.
covOptional, // Pages.
covOptional, // PageType.
covOptional, // PrintToFile.
covOptional, // Collate.
covOptional, // ActivePrinterMacGX.
covOptional, // ManualDuplexPrint.
covOptional, // PrintZoomColumn New with Word 2002
covOptional, // PrintZoomRow ditto
covOptional, // PrintZoomPaperWidth ditto
covOptional);
}
CATCH(CException, e)
{
return FALSE;
}
END_CATCH
Thanks for your time!
Pauli
-
August 11th, 2004, 04:50 PM
#2
Look at the CPrintInfo class/struct.
-
August 11th, 2004, 04:56 PM
#3
Actually this strcut:
typedef struct _devicemode { // dvmd
BCHAR dmDeviceName[CCHDEVICENAME];
WORD dmSpecVersion;
WORD dmDriverVersion;
WORD dmSize;
WORD dmDriverExtra;
DWORD dmFields;
short dmOrientation;
short dmPaperSize;
short dmPaperLength;
short dmPaperWidth;
short dmScale;
short dmCopies;
short dmDefaultSource;
short dmPrintQuality;
short dmColor;
short dmDuplex;
short dmYResolution;
short dmTTOption;
short dmCollate;
BCHAR dmFormName[CCHFORMNAME];
WORD dmLogPixels;
DWORD dmBitsPerPel;
DWORD dmPelsWidth;
DWORD dmPelsHeight;
DWORD dmDisplayFlags;
DWORD dmDisplayFrequency;
#if(WINVER >= 0x0400)
DWORD dmICMMethod; // Windows 95 only
DWORD dmICMIntent; // Windows 95 only
DWORD dmMediaType; // Windows 95 only
DWORD dmDitherType; // Windows 95 only
DWORD dmReserved1; // Windows 95 only
DWORD dmReserved2; // Windows 95 only
#endif /* WINVER >= 0x0400 */
} DEVMODE;
... DEVMODE, .... I think it's the dmOrientation parameter you have to set!!1
dmOrientation
Selects the orientation of the paper. This member can be either DMORIENT_PORTRAIT (1) or DMORIENT_LANDSCAPE (2).
... DEVMODE, .... I think it's the
Don't forget to post your results, I like to stay on top of the printing stuff, I like to get involved in all PRINTING threads.
-
August 11th, 2004, 04:59 PM
#4
Hello
Well thats what I am doing in the code above but its not working.
Once this is done I alos have to implement selecting between color/ black and white printing as well.
Thanks for your time!
Pauli
-
August 11th, 2004, 05:02 PM
#5
I don't know. But, does the settings you do, get passed on to the automation object ?
-
August 11th, 2004, 06:52 PM
#6
 Originally Posted by paulina_lui
Well thats what I am doing in the code above but its not working.
Once this is done I alos have to implement selecting between color/ black and white printing as well.
Thanks for your time!
Pauli
The CPrintdlg class takes care of that. Once you call it, the dialog box has all those options????
-
August 11th, 2004, 07:30 PM
#7
Well
Kirants,
I dont know how to pass those to he printer using automation(WORD,PowerPoint), so was hoping if I am able to change the default settings of the printer, anyone who prints afterwards should see the same settings and it should print fine, as this I what I plan to do.
Change the printer setting to landscape and black and white only if possible, and then print.
And thanks for your help earlier as well.
ADSOFT,
I dont want to display any dialog, and want to change the settings my self.
Thanks for your time
Pauli
-
August 11th, 2004, 08:36 PM
#8
For full features about page setup of the printer,I think the fullowing 3rd Party XD++ MFC Flow/Diagram will help you:
http://www.********.net
Regards
-
August 11th, 2004, 09:00 PM
#9
It doesn't look like its good at doing reports??
For Graphical stuff it might be alright but the FRAMEWORK supports graphical by printing what is done via OnDraw(pDC);
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|