印刷デバイスのラスタ能力を取得         <TOP>


EnumPrinters 使用可能なプリンタ・プリントサーバーなどを列挙 
MoveMemory メモリの指定領域をコピー 
GetDeviceCaps デバイス固有の情報を取得 
CreateDC デバイスコンテキストを、指定された名前で作成 
 
 
'================================================================
'= 印刷デバイスのラスタ能力を取得
'=    (PrinterRastercap.bas)
'================================================================
#include "Windows.bi"

Type PRINTER_INFO_5
    pDeviceName As Long
    pPortName   As Long
    Attributes  As Long
    DeviceNotSelectedTimeOut As Long
    TransmissionColorDeviceryTimeOut As Long
End Type

' 使用可能なプリンタ・プリントサーバーなどを列挙する
Declare Function Api_EnumPrinters& Lib "winspool.drv" Alias "EnumPrintersA" (ByVal Flags&, ByVal Name$, ByVal Level&, pPrinterEnum As Any, ByVal cbBuf&, pcbNeeded&, pcReturned&)

' メモリの指定領域をコピー
Declare Sub MoveMemory Lib "Kernel32" Alias "RtlMoveMemory" (Dest As Any, Source As Any, ByVal Length&)

' デバイス固有の情報を取得
Declare Function Api_GetDeviceCaps& Lib "gdi32" Alias "GetDeviceCaps" (ByVal hDC&, ByVal nIndex&)

' 指定されたデバイスのデバイスコンテキストを、指定された名前で作成
Declare Function Api_CreateDC& Lib "gdi32" Alias "CreateDCA" (ByVal lpDriverName$, lpDeviceName As Any, lpOutput As Any, ByVal lpInitData As Any)

#define PRINTER_ENUM_DEFAULT &H1        'デフォルトのプリンタに関する情報を列挙
#define PRINTER_ENUM_LOCAL &H2          'Nameの設定を無視して、ローカルプリンタを列挙
#define PRINTER_ENUM_NAME &H8           'Nameで指定されたプリンタを列挙
#define PRINTER_ENUM_SHARED &H20        '共有属性を持つプリンタを列挙
#define MAX_DEVICENAME 64
#define DC_COLORDEVICE 32

#define RASTERCAPS 38                   'ラスタ能力(戻り値は以下の定数の組み合わせ)
#define RC_BANDING 2                    'バンド処理のサポートが必要
#define RC_BIGFONT &H400                '大きいフォントをサポート
#define RC_BITBLT 1                     'ビットマップの転送をサポート
#define RC_BITMAP64 8                   '64KBより大きいビットマップをサポート
#define RC_DEVBITS &H8000               '
#define RC_DI_BITMAP &H80               'SetDIBits関数とGetDIBits関数をサポート
#define RC_DIBTODEV &H200               'SetDIBitsToDevice関数をサポート
#define RC_FLOODFILL &H1000             '塗りつぶしをサポート
#define RC_GDI20_OUTPUT &H10            'Windows2.0の機能をサポート
#define RC_GDI20_STATE &H20             '
#define RC_OP_DX_OUTPUT &H4000          '
#define RC_PALETTE &H100                'パレットベースのデバイス
#define RC_SAVEBITMAP &H40              '
#define RC_SCALING 4                    'スケーリングをサポート
#define RC_STRETCHBLT &H800             'StretchBlt関数をサポート
#define RC_STRETCHDIB &H2000            'StretchDIBits関数をサポート

Var Shared Text(1) As Object
Var Shared Combo1 As Object
Var Shared List1 As Object
Var Shared Button1 As Object

For i = 0 To 1
    Text(i).Attach GetDlgItem("Text" & Trim$(Str$(i + 1)))
    Text(i).SetFontSize 14
Next
Combo1.Attach GetDlgItem("Combo1") : Combo1.SetFontSize 14
List1.Attach GetDlgItem("List1") : List1.SetFontSize 14
Button1.Attach GetDlgItem("Button1") : Button1.SetFontSize 14

Var Shared DeviceName As String

'================================================================
'=
'================================================================
Declare Sub MainForm_Start edecl ()
Sub MainForm_Start()
    Var PrintServer As String
    Var Needed As Long
    Var Returned As Long
    Var Level As Long
    Var CT As Long
    Var Device As Long

    'ローカルプリンタから検索
    PrintServer = ""

    'PRINTER_INFO_5構造体を受け取る
    Level = 5

    'バッファに必要なバイト数を調べる
    Device = Api_EnumPrinters(PRINTER_ENUM_NAME, PrintServer, Level, Chr$(0), 0, Needed, Returned)
    If Needed = 0 Then End

    '全プリンタ情報を得る
    Var Buffer(Needed - 1) As byte
    Device = Api_EnumPrinters(PRINTER_ENUM_NAME, PrintServer, Level, Buffer(0), Needed, Needed, Returned)

    '構造体リストの準備
    Var PI_5(Returned - 1) As PRINTER_INFO_5

    For CT = 0 To Returned - 1
        'バッファから構造体1つ分を抜き取る
        MoveMemory PI_5(CT), Buffer(CT * Len(PI_5(CT))), Len(PI_5(CT))

        'プリンタ名を得る
        DeviceName = String$(MAX_DEVICENAME, Chr$(0))
        MoveMemory DeviceName, ByVal PI_5(CT).pDeviceName, Len(DeviceName)
        DeviceName = KLeft$(DeviceName, KInStr(1, DeviceName, Chr$(0)) - 1)

        Combo1.AddString DeviceName
    Next
End Sub

'================================================================
'=
'================================================================
Declare Sub Button1_on edecl ()
Sub Button1_on()
    Var PrinterRasterCaps As Long
    Var hDC As Long

    'リストボックスを初期化
    List1.Resetcontent

    DeviceName = Combo1.GetWindowText
    If DeviceName = "" Then
        A% = MessageBox(GetWindowtext, "プリンタ名を指定してください!", 0, 2)
        Exit Sub
    End If

    hDC = Api_CreateDC(ByVal 0, DeviceName, ByVal 0, ByVal 0)

    'ラスタ能力を取得
    PrinterRasterCaps = Api_GetDeviceCaps(hDC, RASTERCAPS)

    'ラスタ能力を表示
    If PrinterRasterCaps And RC_BITBLT Then       List1.AddString "BITBLT"
    If PrinterRasterCaps And RC_BANDING Then      List1.AddString "BANDING"
    If PrinterRasterCaps And RC_SCALING Then      List1.AddString "SCALING"
    If PrinterRasterCaps And RC_BITMAP64 Then     List1.AddString "BITMAP64"
    If PrinterRasterCaps And RC_GDI20_OUTPUT Then List1.AddString "GDI20_OUTPUT"
    If PrinterRasterCaps And RC_GDI20_STATE Then  List1.AddString "GDI20_STATE"
    If PrinterRasterCaps And RC_SAVEBITMAP Then   List1.AddString "SAVEBITMAP"
    If PrinterRasterCaps And RC_DI_BITMAP Then    List1.AddString "DI_BITMAP"
    If PrinterRasterCaps And RC_PALETTE Then      List1.AddString "PALETTE"
    If PrinterRasterCaps And RC_DIBTODEV Then     List1.AddString "DIBTODEV"
    If PrinterRasterCaps And RC_BIGFONT Then      List1.AddString "BIGFONT"
    If PrinterRasterCaps And RC_STRETCHBLT Then   List1.AddString "STRETCHBLT"
    If PrinterRasterCaps And RC_FLOODFILL Then    List1.AddString "FLOODFILL"
    If PrinterRasterCaps And RC_STRETCHDIB Then   List1.AddString "STRETCHDIB"
    If PrinterRasterCaps And RC_OP_DX_OUTPUT Then List1.AddString "OP_DX_OUTPUT"
    If PrinterRasterCaps And RC_DEVBITS Then      List1.AddString "DEVBITS"
End Sub

'================================================================
'=
'================================================================
Declare Sub Combo1_Click edecl ()
Sub Combo1_Click()
    List1.Resetcontent
End Sub

'================================================================
'=
'================================================================
While 1
    WaitEvent
Wend
Stop
End