選択したプリンタの用紙一覧
Posted: 2008年3月01日(土) 16:55
選択したプリンタの用紙一覧を取り出すにはどうしたらいいでしょうか?
APIか何かを使うのでしょうか?
APIか何かを使うのでしょうか?
コード: 全て選択
' プリンタデバイスドライバの能力を取得する関数の宣言
Declare Function DeviceCapabilities Lib "winspool.drv" _
Alias "DeviceCapabilitiesA" _
(pDevice As BytePtr, pPort As BytePtr, _
ByVal fwCapability As Long, pOutput As BytePtr, _
ByRef pDevMode As DEVMODE) As Long
Const DC_PAPERNAMES = 16
コード: 全て選択
Sub MainWnd_CommandButton1_Click()
Dim strPrinterName As String
Dim strPort As String
Dim retPaperCount As Long
Dim retPaperBuf As BytePtr
Dim retPaperByte[64] As Byte '各用紙情報は64バイト単位で格納
Dim J As Long
'プリンタ名とポート名を設定
'ここではそのままプリンタ名・ポート名を設定しています
'環境に応じて変更してください
strPrinterName = "Canon Bubble-Jet BJC-455J"
strPort = "LPT1:"
'DeviceCapabilitiesをコールして、上記プリンタの用紙登録数を取得
retPaperCount = DeviceCapabilities(strPrinterName,strPort,DC_PAPERNAMES,NULL,ByVal 0)
If retPaperCount = 0 Then Exit Sub
'用紙の名前を入れるバッファを確保(上記登録数 x 64バイト)
retPaperBuf = calloc(retPaperCount * 64)
'上記バッファを指定して、再度DeviceCapabilitiesをコール
'バッファに用紙名が連なって格納される
DeviceCapabilities(strPrinterName,strPort,DC_PAPERNAMES,retPaperBuf,ByVal 0)
'登録用紙の数だけループ
For J = 0 To retPaperCount - 1
'バッファから用紙名を一つ一つ転記する
memcpy(retPaperByte,retPaperBuf + (J * 64),64)
'リストボックスへ用紙名を挿入
SendMessage(GetDlgItem(hMainWnd,ListBox1),LB_ADDSTRING,0,retPaperByte)
Next J
'バッファを開放
free(retPaperBuf)
End Sub