選択したプリンタの用紙一覧

ActiveBasicでのプログラミングでわからないこと、困ったことなどがあったら、ここで質問してみましょう(質問を行う場合は、過去ログやWeb上であらかじめ問題を整理するようにしましょう☆)。
返信する
メッセージ
作成者
まついち

選択したプリンタの用紙一覧

#1 投稿記事 by まついち »

選択したプリンタの用紙一覧を取り出すにはどうしたらいいでしょうか?
APIか何かを使うのでしょうか?
M.K
記事: 18
登録日時: 2005年6月07日(火) 22:06
お住まい: 長崎県

Re:選択したプリンタの用紙一覧

#2 投稿記事 by M.K »

こんばんは、
参考になるかどうかわかりませんが、以下をお試しください。

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
まついち

Re:選択したプリンタの用紙一覧

#3 投稿記事 by まついち »

ありがとう御座いました。 助かりました。
返信する