印刷
ローカルプリンタと
カレントフォルダに"test.bmp"が必要。


'印刷テスト
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (lpApplicationName As BytePtr, lpKeyName As BytePtr, lpDefault As BytePtr, lpReturnedString As BytePtr, nSize As Long, lpFileName As BytePtr) As Long
Declare Function SetDIBitsToDevice Lib "gdi32" (hdc As Long,XDest As Long,YDest As Long,dwWidth As Long,dwHeight As Long,XSrc As Long,YSrc As Long,uStartScan As Long,cScanLines As Long,lpvBits As Long,lpbmi As *BITMAPINFO,ByVal fuColorUse As Long) As Long
Dim docinfo As DOCINFO
Dim hDC As HDC
Dim txtm As TEXTMETRIC

hDC = LPRINTDC()

'DOCINFO初期化
ZeroMemory(VarPtr(docinfo), SizeOf(DOCINFO))
docinfo.cbSize = SizeOf(DOCINFO)
docinfo.lpszDocName = "PLARINT test"

'hDCのフォント取得
GetTextMetrics(hDC, txtm)

'印刷ジョブ開始
StartDoc(hDC, docinfo)
StartPage(hDC)

'印刷
TextOut(hDC, 0, txtm.tmHeight*1, "テスト", 6)
TextOut(hDC, 0, txtm.tmHeight*2, "2行目", 5)
PrintBitmap(hDC, "test.bmp", 0, txtm.tmHeight*4)

'後処理
EndPage(hDC)
EndDoc(hDC)

DeleteDC(hDC)
End
'プリンタのDCを返す
Function LPRINTDC() As HDC
Dim need As DWord , ret As DWord, size As DWord, r As DWord
Dim pprninfo As *PRINTER_INFO_5
size = 0
r = EnumPrinters(PRINTER_ENUM_LOCAL, NULL, 5, NULL, size, need, ret)
pprninfo = malloc(need)
size = need
r = EnumPrinters( PRINTER_ENUM_LOCAL, NULL, 5, pprninfo, size, need, ret)
LPRINTDC = CreateDC("WINSPOOL", pprninfo[0].pPrinterName, NULL,ByVal NULL)
free(pprninfo)
End Function

'ビットマップをプリンタのhDCに座標x,yを印刷
Function PrintBitmap(hDC As HDC, file As *Byte, x As Long, y As Long) As Long
Dim bfh As BITMAPFILEHEADER
Dim bi As BITMAPINFO
Dim px As *Byte
Dim hFile As HANDLE
Dim size As DWord
hFile = CreateFile(file, GENERIC_READ, 0, ByVal NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)
If hFile = INVALID_HANDLE_VALUE Then Exit Function
ReadFile(hFile, VarPtr(bfh), SizeOf(BITMAPFILEHEADER), VarPtr(size) ,ByVal NULL)
ReadFile(hFile, VarPtr(bi), SizeOf(BITMAPINFOHEADER), VarPtr(size) ,ByVal NULL)
px = malloc (bfh.bfSize - bfh.bfOffBits)
ReadFile(hFile, px, bfh.bfSize - bfh.bfOffBits, VarPtr(size) ,ByVal NULL)
CloseHandle(hFile)
SetDIBitsToDevice(hDC, x, y,
bi.bmiHeader.biWidth, bi.bmiHeader.biHeight,
0, 0, 0, bi.bmiHeader.biHeight,
px, VarPtr(bi), DIB_RGB_COLORS)
PrintBitmap = TRUE
End Function

タグ:

+ タグ編集
  • タグ:

このサイトはreCAPTCHAによって保護されており、Googleの プライバシーポリシー利用規約 が適用されます。

最終更新:2010年05月09日 09:29