阅读:1984回复:2
打印的问题(选择打印机和预览指北针,图例)
<P>打印的时候,需要选择对话框,然后打印出pagelayout里面的元素。以下代码功能:实现调用系统的打印机,请问,
1,我怎么设置系统的Printer到AE中的IPrinter,调出打印功能。pagelayout的打印机属性为只读属性。 2,怎么样实现打印预览功能,我是采用CopytoCocusMap的例子,但不能Copy Pagelayout或map中的指北针,图例等元素。只能copy Map。 </P> <P>///showprinter/////////// ////waterblue///////////</P> <P>Public Const CCHDEVICENAME = 32 Public Const CCHFORMNAME = 32 Public Const GMEM_MOVEABLE = ;H2 Public Const GMEM_ZEROINIT = ;H40 Public Const DM_DUPLEX = ;H1000; Public Const DM_ORIENTATION = ;H1;</P> <P>Public Type PRINTDLG_TYPE lStructSize As Long hwndOwner As Long hDevMode As Long hDevNames As Long hdc As Long Flags As Long nFromPage As Integer nToPage As Integer nMinPage As Integer nMaxPage As Integer nCopies As Integer hInstance As Long lCustData As Long lpfnPrintHook As Long lpfnSetupHook As Long lpPrintTemplateName As String lpSetupTemplateName As String hPrintTemplate As Long hSetupTemplate As Long End Type Public Type DEVNAMES_TYPE wDriverOffset As Integer wDeviceOffset As Integer wOutputOffset As Integer wDefault As Integer extra As String * 100 End Type Public Type DEVMODE_TYPE dmDeviceName As String * CCHDEVICENAME dmSpecVersion As Integer dmDriverVersion As Integer dmSize As Integer dmDriverExtra As Integer dmFields As Long dmOrientation As Integer dmPaperSize As Integer dmPaperLength As Integer dmPaperWidth As Integer dmScale As Integer dmCopies As Integer dmDefaultSource As Integer dmPrintQuality As Integer dmColor As Integer dmDuplex As Integer dmYResolution As Integer dmTTOption As Integer dmCollate As Integer dmFormName As String * CCHFORMNAME dmUnusedPadding As Integer dmBitsPerPel As Integer dmPelsWidth As Long dmPelsHeight As Long dmDisplayFlags As Long dmDisplayFrequency As Long End Type Public Declare Function PrintDialog Lib "comdlg32.dll" Alias "PrintDlgA" (pPrintdlg As PRINTDLG_TYPE) As Long Public Declare Sub CopyMemory Lib "KERNEL32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long) Public Declare Function GlobalLock Lib "KERNEL32" (ByVal hMem As Long) As Long Public Declare Function GlobalUnlock Lib "KERNEL32" (ByVal hMem As Long) As Long Public Declare Function GlobalAlloc Lib "KERNEL32" (ByVal wFlags As Long, ByVal dwBytes As Long) As Long Public Declare Function GlobalFree Lib "KERNEL32" (ByVal hMem As Long) As Long</P> <P>Public Sub showprinter(frmOwner As Form, Optional PrintFlags As Long) Dim PrintDlg As PRINTDLG_TYPE Dim DEVMODE As DEVMODE_TYPE Dim DevName As DEVNAMES_TYPE</P> <P> Dim lpDevMode As Long, lpDevName As Long Dim bReturn As Integer Dim objPrinter As printer, NewPrinterName As String</P> <P> ' Use PrintDialog to get the handle to a memory ' block with a DevMode and DevName structures</P> <P> PrintDlg.lStructSize = Len(PrintDlg) PrintDlg.hwndOwner = frmOwner.hwnd</P> <P> PrintDlg.Flags = PrintFlags On Error Resume Next 'Set the current orientation and duplex setting DEVMODE.dmDeviceName = printer.DeviceName DEVMODE.dmSize = Len(DEVMODE) DEVMODE.dmFields = DM_ORIENTATION Or DM_DUPLEX DEVMODE.dmPaperWidth = printer.Width DEVMODE.dmOrientation = printer.Orientation DEVMODE.dmPaperSize = printer.PaperSize DEVMODE.dmDuplex = printer.Duplex On Error GoTo 0</P> <P> 'Allocate memory for the initialization hDevMode structure 'and copy the settings gathered above into this memory PrintDlg.hDevMode = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, Len(DEVMODE)) lpDevMode = GlobalLock(PrintDlg.hDevMode) If lpDevMode > 0 Then CopyMemory ByVal lpDevMode, DEVMODE, Len(DEVMODE) bReturn = GlobalUnlock(PrintDlg.hDevMode) End If</P> <P> 'Set the current driver, device, and port name strings With DevName .wDriverOffset = 8 .wDeviceOffset = .wDriverOffset + 1 + Len(printer.DriverName) .wOutputOffset = .wDeviceOffset + 1 + Len(printer.Port) .wDefault = 0 End With</P> <P> With printer DevName.extra = .DriverName ; Chr(0) ; .DeviceName ; Chr(0) ; .Port ; Chr(0) End With</P> <P> 'Allocate memory for the initial hDevName structure 'and copy the settings gathered above into this memory PrintDlg.hDevNames = GlobalAlloc(GMEM_MOVEABLE Or GMEM_ZEROINIT, Len(DevName)) lpDevName = GlobalLock(PrintDlg.hDevNames) If lpDevName > 0 Then CopyMemory ByVal lpDevName, DevName, Len(DevName) bReturn = GlobalUnlock(lpDevName) End If</P> <P> 'Call the print dialog up and let the user make changes If PrintDialog(PrintDlg) <> 0 Then</P> <P> 'First get the DevName structure. lpDevName = GlobalLock(PrintDlg.hDevNames) CopyMemory DevName, ByVal lpDevName, 45 bReturn = GlobalUnlock(lpDevName) GlobalFree PrintDlg.hDevNames</P> <P> 'Next get the DevMode structure and set the printer 'properties appropriately lpDevMode = GlobalLock(PrintDlg.hDevMode) CopyMemory DEVMODE, ByVal lpDevMode, Len(DEVMODE) bReturn = GlobalUnlock(PrintDlg.hDevMode) GlobalFree PrintDlg.hDevMode NewPrinterName = UCase$(Left(DEVMODE.dmDeviceName, InStr(DEVMODE.dmDeviceName, Chr$(0)) - 1)) If printer.DeviceName <> NewPrinterName Then For Each objPrinter In Printers If InStr(1, objPrinter.DeviceName, NewPrinterName, vbTextCompare) > 0 Then Set printer = objPrinter Exit For 'set printer toolbar name at this point End If Next End If</P> <P> On Error Resume Next 'Set printer object properties according to selections made 'by user printer.Copies = DEVMODE.dmCopies printer.Duplex = DEVMODE.dmDuplex printer.Orientation = DEVMODE.dmOrientation</P> <P> printer.PaperSize = DEVMODE.dmPaperSize printer.PrintQuality = DEVMODE.dmPrintQuality printer.ColorMode = DEVMODE.dmColor printer.PaperBin = DEVMODE.dmDefaultSource </P> <P> On Error GoTo 0 End If End Sub </P> [此贴子已经被作者于2005-4-7 11:24:52编辑过]
|
|
|
1楼#
发布于:2005-04-07 15:55
<P>调出的对话框,都只是基于desktop的</P><P>Private Sub cmdSetup_Click()
296: If (Not m_pApp.IsDialogVisible(esriMxDlgPageSetup)) Then Dim bDialog As Boolean Dim pPrinter As IPrinter Dim pMxApp As IMxApplication 300: m_pApp.ShowDialog esriMxDlgPageSetup, True 302: m_pExportFrame.Visible = False ' Me.Hide 304: bDialog = True 306: While bDialog = True 307: bDialog = m_pApp.IsDialogVisible(esriMxDlgPageSetup) 308: DoEvents ' Sleep 1 312: Wend 314: Set pMxApp = m_pApp 315: Set pPrinter = pMxApp.Printer 316: frmPrint.lblName.Caption = pPrinter.Paper.PrinterName 317: frmPrint.lblType.Caption = pPrinter.DriverName 318: If TypeOf pPrinter Is IPsPrinter Then 319: Me.chkPrintToFile.Enabled = True 320: Else 321: Me.chkPrintToFile.Value = 0 322: Me.chkPrintToFile.Enabled = False 323: End If ' Me.Show 325: m_pExportFrame.Visible = True 326: End If End Sub</P> |
|
|
2楼#
发布于:2005-04-07 12:30
<P>你可以看看AO开发包里自带的mapbook例子</P><img src="images/post/smile/dvbbs/em02.gif" />
|
|
|