by M.K » 2008年3月02日(日) 00:10
こんばんは、
参考になるかどうかわかりませんが、以下をお試しください。
1.メインウィンドウ(MainWnd)へ一つのリストボックス(ListBox1)と
一つのボタン(CommandButton1)を貼り付けます。
2.グローバルの場所へ以下の定義を行います。
コード: 全て選択
' プリンタデバイスドライバの能力を取得する関数の宣言
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
3.ボタン(CommandButton1)のClickイベントへ以下のコードを入力します。
コード: 全て選択
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
4.実行してボタンをクリックします。
参考:DeviceCapabilities
http://msdn.microsoft.com/library/ja/de ... lities.asp
こんばんは、
参考になるかどうかわかりませんが、以下をお試しください。
1.メインウィンドウ(MainWnd)へ一つのリストボックス(ListBox1)と
一つのボタン(CommandButton1)を貼り付けます。
2.グローバルの場所へ以下の定義を行います。
[code]
' プリンタデバイスドライバの能力を取得する関数の宣言
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
[/code]
3.ボタン(CommandButton1)のClickイベントへ以下のコードを入力します。
[code]
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
[/code]
4.実行してボタンをクリックします。
参考:DeviceCapabilities
[url]http://msdn.microsoft.com/library/ja/default.asp?url=/library/ja/jpgdi/html/_win32_devicecapabilities.asp[/url]