gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15945
  • QQ554730525
  • 铜币25337枚
  • 威望15352点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
阅读:26210回复:62

[讨论]如何在mo程序中实现高质量地图打印[增加多个代码2005更新]

楼主#
更多 发布于:2003-08-03 00:17
文章来自esri的技术文库,大家看看,希望大家具体讨论问题,

Description
Despite setting the paper size and paper bin on the Printer dialog box, the printout does not print at the desired settings. This applies as well when using the Visual Basic Printer object to set the PaperBin and PaperSize properties. This document includes sample code to create a custom printer dialog box using the DeviceCapabilities API function.


Cause
Sometimes the printer driver does not recognize the constants for the Printer Object's PaperBin and PaperSize properties. (See Microsoft Developer Network knowledge base article Q194789.)


Solution or Workaround
Enumerate the constants using the DeviceCapabilities API.


Create a dialog box similar to the following (do not worry about the values for the controls):


COMBOBOX CONTROLS:
Name the ComboBox controls as follows:
Printer Name: cbPrinter
Page Size: cbSize
Page Source: cbSource

OPTION BUTTONS:
The Option buttons should be a control array. Name both Option buttons for the orientation 'rbOrientation'. The Index property values for these Option buttons should be as follows:
Portrait Option: 0
Landscape Option: 1

COMMAND BUTTONS:
Name the Command controls as follows:
OK Button: cmdOk
Cancel Button: cmdCancel

FORM:
Set the following properties for the Form:
Name: frmPrint
Caption: Printer Setup
Open the code window for the Form and paste in the following code in the General Declaration area of the code:

'This application is based on MSDN Article ID Q194789.

Option Explicit

'The DeviceCapabilities function retrieves the capabilities of a printer device driver.
Private Declare Function DeviceCapabilities Lib "winspool.drv" _
   Alias "DeviceCapabilitiesA" (ByVal lpDeviceName As String, _
   ByVal lpPort As String, ByVal iIndex As Long, lpOutput As Any, _
   ByVal dev As Long) As Long

Private Const DC_BINS = 6
Private Const DC_BINNAMES = 12
Private Const DC_PAPERNAMES = 16
Private Const DC_PAPERS = 2
Private Const DC_FIELDS = 1


Create the following Sub routine to list the available paper sources for your printer:

Sub populatePaperSource()
'If setting the PaperBin property of the Printer object fails to select the desired bin,
'it might be because the printer driver does not recognize the value being assigned.
'In this case, you need to use the constant to select the printer's upper bin.

   Dim dwbins As Long
   Dim ct As Long
   Dim nameslist As String
   Dim nextString As String
  
   cbSource.Clear
  
   ' Get count of bins supported by active printer.
   dwbins = DeviceCapabilities(Printer.DeviceName, Printer.Port, _
          DC_BINS, ByVal vbNullString, 0)
  
   If dwbins <> -1 Then
      nameslist = String(24 * dwbins, 0)
       ' Get bin names supported by active printer.
      dwbins = DeviceCapabilities(Printer.DeviceName, Printer.Port, _
        DC_BINNAMES, ByVal nameslist, 0)
      
      ' List available bin names.

      For ct = 1 To dwbins
         nextString = Mid(nameslist, 24 * (ct - 1) + 1, 24)
         nextString = Left(nextString, InStr(1, nextString, _
           Chr(0)) - 1)
         cbSource.AddItem nextString
      Next ct
   Else
      cbSource.AddItem "not applicable"  ' (-1 for plotters.)
   End If

   cbSource.ListIndex = 0
End Sub


Add another Sub routine to list the available paper sizes:

Sub populatePaperSize()
    
   Dim lPaperCount As Long
   Dim lCounter As Long
   Dim sPaperNamesList As String
   Dim sNextString As String
   Dim sTextString As String
        
   cbSize.Clear
  
   ' Get count of paper names supported by active printer.
   lPaperCount = DeviceCapabilities(Printer.DeviceName, Printer.Port, _
       DC_PAPERNAMES, ByVal vbNullString, 0)
  
   sPaperNamesList = String(64 * lPaperCount, 0)
  
   ' Get paper names supported by active printer.
   lPaperCount = DeviceCapabilities(Printer.DeviceName, Printer.Port, _
       DC_PAPERNAMES, ByVal sPaperNamesList, 0)
  
   ' List available paper names.

   For lCounter = 1 To lPaperCount
       ' Get a paper name.
       sNextString = Mid(sPaperNamesList, _
           64 * (lCounter - 1) + 1, 64)
       sNextString = Left(sNextString, _
           InStr(1, sNextString, Chr(0)) - 1)
       cbSize.AddItem sNextString
   Next lCounter

   cbSize.ListIndex = 0
  
End Sub


In the Form's Load() event, list the available printers and call the Sub routines to populate the appropriate combo boxes with the available paper source and size options:

Private Sub Form_Load()
'frmPrint.cmdPrinterProperties.Enabled = False

Dim X As Printer

'Populate combo box with available printers
For Each X In Printers
   cbPrinter.AddItem X.DeviceName
Next
cbPrinter.ListIndex = 1
rbOrientation(0).Value = True

'Initialize Printer settings
Set Printer = Printers(cbPrinter.ListIndex)
Printer.Orientation = 1
populatePaperSource
populatePaperSize

End Sub


Add code to set the active printer to be the selected printer. Populate the paper source and paper size ComboBox controls so that they apply to the selected printer:

Private Sub cbPrinter_Click()
   Dim i As Integer
   i = cbPrinter.ListIndex
   Set Printer = Printers(i)
  
   populatePaperSource
  
   populatePaperSize
End Sub


Write code to unload the form if the user clicks the Cancel button:

Private Sub cmdCancel_Click()
   Unload Me
End Sub


Type in the following code for when the OK button is clicked:

Private Sub cmdOK_Click()

'Set Orientation
'================

If rbOrientation(0).Value = True Then
   Printer.Orientation = 1
Else
   Printer.Orientation = 2
End If

'Set Paper Size
'================

Dim lPaperCount As Long
Dim iNumPaper() As Integer
Dim iPaperSelected As Integer

' Get count of paper sizes supported by active printer.
lPaperCount = DeviceCapabilities(Printer.DeviceName, Printer.Port, _
    DC_PAPERS, ByVal vbNullString, 0)

ReDim iNumPaper(1 To lPaperCount)

'Get papers supported
lPaperCount = DeviceCapabilities(Printer.DeviceName, Printer.Port, _
   DC_PAPERS, iNumPaper(1), 0)


iPaperSelected = cbSize.ListIndex + 1
Printer.PaperSize = iNumPaper(iPaperSelected)


'Set Paper Bin
'================

Dim dwbins As Long
Dim numBin() As Integer
Dim iBinSelected As Integer

'Get count of bins supported
dwbins = DeviceCapabilities(Printer.DeviceName, Printer.Port, _
       DC_BINS, ByVal vbNullString, 0)
If dwbins <> -1 Then
   ReDim numBin(1 To dwbins)
   'Get bins supported
   dwbins = DeviceCapabilities(Printer.DeviceName, Printer.Port, _
     DC_BINS, numBin(1), 0)
   iBinSelected = cbSource.ListIndex + 1
   Printer.PaperBin = numBin(iBinSelected)
End If


MsgBox "Page Size: " ; Format(Printer.Width / 1440, "#0.0") ; _
        " x " ; Format(Printer.Height / 1440, "#0.0")


'Print Map
'================
Printer.Print
   frmMap.Map1.OutputMap Printer.hDC
Printer.EndDoc


End Sub



Show this form (frmPrint) from another form, for example, frmMain:


Private Sub cmdPrint_Click()
   frmPrint.Show
End Sub



[此贴子已经被作者于2005-1-15 10:12:55编辑过]
喜欢0 评分0
admin
  • 注册日期
  • 发帖数
  • QQ
  • 铜币
  • 威望
  • 贡献值
  • 银元
1楼#
发布于:2003-08-18 18:02
vb打印代码
vb打印代码
可加入指南和文字等布局设置
希望大家调试得更好,再发到这里,大家交流,
要不我发到这里就没什么意义了,呵呵

<a href="attachment/20038181804647523.rar">20038181804647523.rar</a>
<a href="attachment/2003818181399005.rar">2003818181399005.rar</a>
<a href="attachment/20038181811488865.rar">20038181811488865.rar</a>
<img src="images/post/smile/dvbbs/em04.gif" />
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15945
  • QQ554730525
  • 铜币25337枚
  • 威望15352点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
2楼#
发布于:2003-08-18 18:05
<P>希望大家快快把他做得更好,刚找到的一个打印程序。发上来大家看看,改改后记得给我看啊。</P>
<P>按比例尺打印的程序:</P>
<P><a href="attachment/2005-1/200511510118611.zip">2005-1/200511510118611.zip</a></P>
<P>有比例尺和指北针,标题设置的打印程序代码:
</P>
<P><a href="attachment/2005-1/200511510125473.zip">2005-1/200511510125473.zip</a>
</P>
<P>第二个程序的调试方法在12楼已经有说明,大家可以多参照别人的方法</P>
[此贴子已经被作者于2005-1-15 10:15:14编辑过]
举报 回复(0) 喜欢(0)     评分
zergs
路人甲
路人甲
  • 注册日期2003-09-01
  • 发帖数113
  • QQ
  • 铜币386枚
  • 威望0点
  • 贡献值0点
  • 银元0个
3楼#
发布于:2003-09-03 08:54
不错的说!
举报 回复(0) 喜欢(0)     评分
huangsf
路人甲
路人甲
  • 注册日期2003-08-13
  • 发帖数53
  • QQ
  • 铜币292枚
  • 威望0点
  • 贡献值0点
  • 银元0个
4楼#
发布于:2003-09-04 10:55
能否在MO上在包装一个Layerout布局控件?ESRI为何就不做一个呢?唉
举报 回复(0) 喜欢(0)     评分
huangsf
路人甲
路人甲
  • 注册日期2003-08-13
  • 发帖数53
  • QQ
  • 铜币292枚
  • 威望0点
  • 贡献值0点
  • 银元0个
5楼#
发布于:2003-09-05 11:30
提供的代码中缺少MO21scale.ocx文件。
举报 回复(0) 喜欢(0)     评分
xiaoqiangwei
路人甲
路人甲
  • 注册日期2003-09-02
  • 发帖数48
  • QQ
  • 铜币341枚
  • 威望0点
  • 贡献值0点
  • 银元0个
6楼#
发布于:2003-09-09 21:52
esri提供了一个打印的例子,基本上是对位图的操作,我感觉还不错。
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15945
  • QQ554730525
  • 铜币25337枚
  • 威望15352点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
7楼#
发布于:2003-09-10 09:19
呵呵,拿出来亮?
举报 回复(0) 喜欢(0)     评分
wangjunjolly
路人甲
路人甲
  • 注册日期2003-09-11
  • 发帖数356
  • QQ
  • 铜币1040枚
  • 威望0点
  • 贡献值0点
  • 银元0个
8楼#
发布于:2003-09-13 10:35
是呀。拿出来看看!!
举报 回复(0) 喜欢(0)     评分
hsylovelzr
路人甲
路人甲
  • 注册日期2003-07-30
  • 发帖数48
  • QQ
  • 铜币207枚
  • 威望0点
  • 贡献值0点
  • 银元0个
9楼#
发布于:2003-09-14 16:20
很好
举报 回复(0) 喜欢(0)     评分
上一页
游客

返回顶部