如何获得打印机的句柄??

wlfei 2003-11-16 09:00:31
我想用vb 6.0编写的控件,该控件的其中一个方法是要调用打印机的指针。我不知道现在如何才能获得打印机的指针????
请教各位高手,谢谢了!

...全文
103 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
wlfei 2003-11-17
  • 打赏
  • 举报
回复
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim printer As New Printing.PrinterSettings
printer.PrinterName = "Adobe PDF"
PrintDocument1.PrinterSettings = printer
PrintDocument1.Print()

End Sub

Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
MsgBox("调用打印")

MapDisp.OutputMap(e.Graphics.GetHdc.ToInt32)

End Sub


错误提示如下:
未处理的“System.InvalidOperationException”类型的异常出现在 system.drawing.dll 中。

其他信息: 该对象当前正在其他地方使用。

其中MapDisp就是用vb 6.0编写的控件。
不知道上面的代码到底存在什么问题??????
请教各位高手了,谢谢!
allanli 2003-11-16
  • 打赏
  • 举报
回复
Public Declare Function OpenPrinter Lib "winspool.drv" Alias "OpenPrinterA" _
(ByVal pPrinterName As String, ByRef phPrinter As Int32, ByVal pDefault As Int32) As Boolean


Dim PrinterHandle As Long ' Handle to printer

OpenPrinter(PrinterName, PrinterHandle, 0&) 'PrinterHandle is what U want



16,556

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧