プリンタのコメントを取得 <TOP>
プリンタのコメントを取得します。
OpenPrinter
プリンタオブジェクトをオープン
GetPrinter
プリンタの詳細な情報を取得
MoveMemory
メモリの指定領域をコピー
lstrcpy
文字列をコピーする
ClosePrinter
プリンタオブジェクトを閉じる
'================================================================ '= プリンタのコメントを取得 '= (GetPrinterComment.bas) '================================================================ #include "Windows.bi" Type PRINTER_DEFAULTS pDatatype As Long pDevMode As Long DesiredAccess As Long End Type Type PRINTER_INFO_2 pServerName As Long pPrinterName As Long pShareName As Long pPortName As Long pDriverName As Long pComment As Long pLocation As Long pDevMode As Long pSepFile As Long pPrintProcessor As Long pDatatype As Long pParameters As Long pSecurityDescriptor As Long Attributes As Long Priority As Long DefaultPriority As Long StartTime As Long UntilTime As Long Status As Long cJobs As Long AveragePPM As Long End Type #define STANDARD_RIGHTS_REQUIRED &HF0000 '標準的な権利を要求することを示す定数 #define PRINTER_ACCESS_ADMINISTER &H4 'プリンタアクセス権の管理者権限を示す #define PRINTER_ACCESS_USE &H8 'プリンタアクセス権のユーザー権限を示す #define PRINTER_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED Or PRINTER_ACCESS_ADMINISTER Or PRINTER_ACCESS_USE) ' ' プリンタオブジェクトをオープン Declare Function Api_OpenPrinter& Lib "winspool.drv" Alias "OpenPrinterA" (ByVal pPrinterName$, phPrinter&, pDefault As Any) ' プリンタの詳細な情報を取得 Declare Function Api_GetPrinter& Lib "winspool.drv" Alias "GetPrinterA" (ByVal hPrinter&, ByVal Level&, pPrinter As Any, ByVal cbBuf&, pcbNeeded&) ' メモリの指定領域をコピー Declare Sub MoveMemory Lib "Kernel32" Alias "RtlMoveMemory" (Dest As Any, Source As Any, ByVal length&) ' 文字列をコピーする Declare Function Api_lstrcpy& Lib "Kernel32" Alias "lstrcpyA" (lpszString1 As Any, lpszString2 As Any) ' プリンタオブジェクトを閉じる Declare Function Api_ClosePrinter& Lib "winspool.drv" Alias "ClosePrinter" (ByVal hPrinter&) Var Shared Text1 As Object Var Shared Text2 As Object Var Shared Button1 As Object Text1.Attach GetDlgItem("Text1") : Text1.SetFontSize 14 Text2.Attach GetDlgItem("Text2") : Text2.SetFontSize 14 Button1.Attach GetDlgItem("Button1") : Button1.SetFontSize 14 '================================================================ '= '================================================================ Declare Sub MainForm_Start edecl () Sub MainForm_Start() Text1.SetWindowText "magicolor 2400W" End Sub '================================================================ '= '================================================================ Declare Sub Button1_on edecl () Sub Button1_on() Var Devname As String Var pd As PRINTER_DEFAULTS Var pi2 As PRINTER_INFO_2 Var PrtHandle As Long Var Level As Long Var Needed As Long Var Comment As String * 128 Var Ret As Long 'プリンタ名を指定 Devname = Text1.GetWindowText 'プリンタアクセス権を指定 pd.DesiredAccess = PRINTER_ALL_ACCESS 'プリンタのオブジェクトハンドルを取得 Ret = Api_OpenPrinter(Devname, PrtHandle, pd) '構造体のレベルを指定 Level = 2 'バッファに必要なサイズを取得 Ret = Api_GetPrinter(PrtHandle, Level, ByVal 0, 0, Needed) 'バッファを確保 Var Buffer(Needed - 1) As Byte 'プリンタ情報を取得 Ret = Api_GetPrinter(PrtHandle, Level, Buffer(0), Needed, Needed) 'プリンタ情報を構造体へ MoveMemory pi2, Buffer(0), Len(pi2) 'コメントを表示 Ret = Api_lstrcpy(Comment, ByVal pi2.pComment) 'Null削除 Text2.SetWindowText Left$(Comment, InStr(Comment, Chr$(0)) - 1) 'プリンタオブジェクトをクローズ Ret = Api_ClosePrinter(PrtHandle) End Sub '================================================================ '= '================================================================ While 1 WaitEvent Wend Stop End