投稿時間:2002/09/17(Tue) 17:50 投稿者名:Yuuko
Eメール:
URL :
タイトル:Re: APIによる印刷
早々にご返答 ありがとうございました。
>どうせGDIを使うならVB.NETに移行した方が楽かも…しれません ユーザーさんの指定なもので・・(^^;
提示いただいたキーワードで いくつか参考になりそうな ところが見つかりましたので がんばってみましたが・・。
下記のようなソースを組んでみたのですが印刷出来ません。 プリンタージョブは現れて消えるのですが 用紙さえも出てこないのです。
'---------------------------------------- '宣言部 '----------------------------------------
' StartDocPrinterに必要な構造体 Private Type DOC_INFO_1 pDocName As String pOutputFile As String pDatatype As String End Type
Private Declare Function OpenPrinter Lib "winspool.drv" _ Alias "OpenPrinterA" _ (ByVal pPrinterName As String, phPrinter As Long, _ pDefault As Any) As Long Private Declare Function StartDocPrinter Lib "winspool.drv" _ Alias "StartDocPrinterA" _ (ByVal hPrinter As Long, ByVal Level As Long, _ pDocInfo As DOC_INFO_1) As Long Private Declare Function StartPagePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long Private Declare Function WritePrinter Lib "winspool.drv" _ (ByVal hPrinter As Long, pBuf As Any, ByVal cdBuf As Long, pcWritten As Long) As Long Private Declare Function EndPagePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long Private Declare Function EndDocPrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long Private Declare Function ClosePrinter Lib "winspool.drv" (ByVal hPrinter As Long) As Long
'---------------------------------------- Private Type POINTAPI x As Long y As Long End Type
Private Declare Function LineTo Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long) As Long Private Declare Function MoveToEx Lib "gdi32" (ByVal hdc As Long, ByVal x As Long, ByVal y As Long, lpPoint As POINTAPI) As Long Private Declare Function TextOut Lib "gdi32" Alias "TextOutA" (ByVal hdc As Long, ByVal nXStart As Long, ByVal nYStart As Long, ByVal lpString As String, ByVal cbString As Long) As Boolean
'---------------------------------------- '実行部 '---------------------------------------- Private Sub Command3_Click() Dim x1 As Double Dim y1 As Double Dim x2 As Double Dim y2 As Double Dim OldCurrentPos As POINTAPI '古いカレントポジションが格納される Dim hPrinter As Long Dim di As DOC_INFO_1 Dim TmpS As String Dim RetC As Long
di.pDocName = App.Title di.pOutputFile = vbNullString di.pDatatype = "RAW"
'プリンターオープン Call OpenPrinter("レーザー", hPrinter, vbNullString) Call StartDocPrinter(hPrinter, 1, di) Call StartPagePrinter(hPrinter)
'線を書いてみる x1 = 10 y1 = 15 x2 = 190 y2 = 180 RetC = MoveToEx(hPrinter, x1, y1, OldCurrentPos) RetC = LineTo(hPrinter, x2, y2)
'文字を書いてみる TmpS = "なんたらかんたら" RetC = TextOut(hPrinter, x1, y1, TmpS, LenB(StrConv(TmpS, vbFromUnicode)))
'終了 Call EndPagePrinter(hPrinter) Call EndDocPrinter(hPrinter) Call ClosePrinter(hPrinter)
End Sub
|