gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
阅读:26300回复: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
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
1楼#
发布于: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)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
2楼#
发布于:2003-09-10 09:19
呵呵,拿出来亮?
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
3楼#
发布于:2003-09-17 10:30
以下是引用wangjunjolly在2003-9-17 9:50:19的发言:
前面那位兄弟提供的打印程序代码运行不了。总提示说“类型不匹配”,不知是怎么回事,哪位大虾可否告诉我。谢谢了!!

在esri上有人提出过问题,回答如下,偷懒之举,呵呵
That sample is expecting the MO2Legend.ocx and ScaleBar.ocx controls. If you have MO 2.1 or 2.2, then the legend and scale bar controls you have on your machine are probably the MO21Legend.ocx and MO21ScaleBar.ocx. So to fix this, open the composition.vbp project in VB6 and do the following:

a. Delete the legend and scale bar controls off the form.
b. Open your Project Components to remove the references to those old controls by unchecking them.
c. Check 'on' the two new controls listed above. If they're not in your list, then use the Browse button to navigate to them. They're probably in the C:\Program Files\Common Files\ESRI folder. Then check them 'on'.
d. Add the new legend and new scale bar to the frmView form. Name them "legMapView" and "sbMapView", respectively so that you don't need to change their names in the code.

Should work fine now.
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
4楼#
发布于:2003-09-23 08:57
把程序做好点,放上来共享啊,也让兄弟们免去一些烦恼
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
5楼#
发布于:2003-09-24 08:46
以下是引用wangjunjolly在2003-9-22 14:06:41的发言:
谢谢斑竹。看了你的指导我终于把问题解决了!!谢谢!!!

希望你把调试的过程给出来,那样大家也免去了好多麻烦,兄弟
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
6楼#
发布于:2003-09-27 12:58
是啊,那样大家可以少做很多无用功
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
7楼#
发布于:2003-09-28 10:50
按比例尺打印思路的powerpoint[下载]
<a href="attachment/200392810503829608.rar">200392810503829608.rar</a>
举报 回复(0) 喜欢(0)     评分
gis
gis
管理员
管理员
  • 注册日期2003-07-16
  • 发帖数15947
  • QQ554730525
  • 铜币25339枚
  • 威望15364点
  • 贡献值0点
  • 银元0个
  • GIS帝国居民
  • 帝国沙发管家
  • GIS帝国明星
  • GIS帝国铁杆
8楼#
发布于:2003-10-23 10:59
利用网格进行打印,在ao中实现方便点。
举报 回复(0) 喜欢(0)     评分
游客

返回顶部