中の技術日誌ブログ

C#とC++/CLIと
VBと.NETとWindowsで戯れる
 

目次

Blog 利用状況

ニュース

自己紹介

東京でソフトウェアエンジニアをやっています。
お仕事大募集中です。
記事執筆や、講師依頼とかでも何でもどうぞ(*^_^*)
似顔絵 MSMVPロゴ
MSMVP Visual C# Since 2004/04-2013/03

記事カテゴリ

書庫

日記カテゴリ

00-整理

01-MSMVP

GetDeviceCapsWrapper

/// <summary>
/// PrinterInfo の概要の説明です。
/// </summary>
public class GetDeviceCapsWrapper : IDisposable
{

    #region P/Invoke
    [DllImport("gdi32.dll")]
    private static extern int GetDeviceCaps(IntPtr hdc, int nIndex);

    [DllImport("gdi32.dll")]
    private static extern IntPtr CreateDC(string lpszDriver, string lpszDevice, string lpszOutput, IntPtr lpInitData);

    [DllImport("gdi32.dll")]
    private static extern bool DeleteDC(IntPtr hdc);

    #endregion
    #region メンバ
    /// <summary>
    /// プリンタハンドル
    /// </summary>
    private IntPtr _PrinterHandle;

    /// <summary>
    /// プリンタ名
    /// </summary>
    private string _PrinterName = null;
    #endregion
    #region public enum CommandIndex
    /// <summary>
    /// データ取得用コマンド番号
    /// </summary>
    public enum CommandIndex
    {
        /// <summary>
        /// Device driver version
        /// </summary>
        DRIVERVERSION = 0,     // Device driver version
        /// <summary>
        /// Device classification
        /// </summary>
        TECHNOLOGY    = 2,     // Device classification
        /// <summary>
        /// Horizontal size in millimeters
        /// </summary>
        HORZSIZE      = 4,     // Horizontal size in millimeters
        /// <summary>
        /// Vertical size in millimeters
        /// </summary>
        VERTSIZE      = 6,     // Vertical size in millimeters
        /// <summary>
        /// Horizontal width in pixels
        /// </summary>
        HORZRES       = 8,     // Horizontal width in pixels
        /// <summary>
        /// Vertical height in pixels
        /// </summary>
        VERTRES       = 10,    // Vertical height in pixels
        /// <summary>
        /// Number of bits per pixel
        /// </summary>
        BITSPIXEL     = 12,    // Number of bits per pixel
        /// <summary>
        /// Number of planes
        /// </summary>
        PLANES        = 14,    // Number of planes
        /// <summary>
        /// Number of brushes the device has
        /// </summary>
        NUMBRUSHES    = 16,    // Number of brushes the device has
        /// <summary>
        /// Number of pens the device has
        /// </summary>
        NUMPENS       = 18,    // Number of pens the device has
        /// <summary>
        /// Number of markers the device has
        /// </summary>
        NUMMARKERS    = 20,    // Number of markers the device has
        /// <summary>
        /// Number of fonts the device has
        /// </summary>
        NUMFONTS      = 22,    // Number of fonts the device has
        /// <summary>
        /// Number of colors the device supports
        /// </summary>
        NUMCOLORS     = 24,    // Number of colors the device supports
        /// <summary>
        /// Size required for device descriptor
        /// </summary>
        PDEVICESIZE   = 26,    // Size required for device descriptor
        /// <summary>
        /// Curve capabilities
        /// </summary>
        CURVECAPS     = 28,    // Curve capabilities
        /// <summary>
        /// Line capabilities
        /// </summary>
        LINECAPS      = 30,    // Line capabilities
        /// <summary>
        /// Polygonal capabilities
        /// </summary>
        POLYGONALCAPS = 32,    // Polygonal capabilities
        /// <summary>
        /// Text capabilities
        /// </summary>
        TEXTCAPS      = 34,    // Text capabilities
        /// <summary>
        /// Clipping capabilities
        /// </summary>
        CLIPCAPS      = 36,    // Clipping capabilities
        /// <summary>
        /// Bitblt capabilities
        /// </summary>
        RASTERCAPS    = 38,    // Bitblt capabilities
        /// <summary>
        /// Length of the X leg
        /// </summary>
        ASPECTX       = 40,    // Length of the X leg
        /// <summary>
        /// Length of the Y leg
        /// </summary>
        ASPECTY       = 42,    // Length of the Y leg
        /// <summary>
        /// Length of the hypotenuse
        /// </summary>
        ASPECTXY      = 44,    // Length of the hypotenuse
        /// <summary>
        /// Logical pixels/inch in X
        /// </summary>
        LOGPIXELSX    = 88,    // Logical pixels/inch in X
        /// <summary>
        /// Logical pixels/inch in Y
        /// </summary>
        LOGPIXELSY    = 90,    // Logical pixels/inch in Y
        /// <summary>
        /// Number of entries in physical palette
        /// </summary>
        SIZEPALETTE  = 104,    // Number of entries in physical palette
        /// <summary>
        /// Number of reserved entries in palette
        /// </summary>
        NUMRESERVED  = 106,    // Number of reserved entries in palette
        /// <summary>
        /// Actual color resolution
        /// </summary>
        COLORRES     = 108,    // Actual color resolution
        // Printing related DeviceCaps. These replace the appropriate Escapes
        /// <summary>
        /// Physical Width in device units
        /// </summary>
        PHYSICALWIDTH   = 110, // Physical Width in device units
        /// <summary>
        /// Physical Height in device units
        /// </summary>
        PHYSICALHEIGHT  = 111, // Physical Height in device units
        /// <summary>
        /// Physical Printable Area x margin
        /// </summary>
        PHYSICALOFFSETX = 112, // Physical Printable Area x margin
        /// <summary>
        /// Physical Printable Area y margin
        /// </summary>
        PHYSICALOFFSETY = 113, // Physical Printable Area y margin
        /// <summary>
        /// Scaling factor x
        /// </summary>
        SCALINGFACTORX  = 114, // Scaling factor x
        /// <summary>
        /// Scaling factor y
        /// </summary>
        SCALINGFACTORY  = 115, // Scaling factor y

        // Display driver specific

        /// <summary>
        /// Current vertical refresh rate of the display device (for displays only) in Hz
        /// </summary>
        VREFRESH        = 116,  // Current vertical refresh rate of the display device (for displays only) in Hz
        /// <summary>
        /// Horizontal width of entire desktop in pixels
        /// </summary>
        DESKTOPVERTRES  = 117,  // Horizontal width of entire desktop in pixels
        /// <summary>
        /// Vertical height of entire desktop in pixels
        /// </summary>
        DESKTOPHORZRES  = 118,  // Vertical height of entire desktop in pixels
        /// <summary>
        /// Preferred blt alignment
        /// </summary>
        BLTALIGNMENT    = 119,  // Preferred blt alignment

        /// <summary>
        /// Shading and blending caps
        /// </summary>
        SHADEBLENDCAPS  = 120,  // Shading and blending caps
        /// <summary>
        /// Color Management caps
        /// </summary>
        COLORMGMTCAPS   = 121,  // Color Management caps
    }

    #endregion
    #region public GetDeviceCapsWrapper()
    /// <summary>
    /// コンストラクタ
    /// </summary>
    public GetDeviceCapsWrapper()
    {
    }
    #endregion
    #region public bool Init(string PrinterName)
    /// <summary>
    /// 初期化処理
    /// </summary>
    /// <param name="PrinterName">情報を取得するプリンタ名を設定</param>
    /// <returns>true = 取得成功, false = 取得失敗</returns>
    public bool Init(string PrinterName)
    {
        if ( PrinterName == null || PrinterName == "" )
        {
            throw new ArgumentNullException("PrinterName");
        }

        this._PrinterName = PrinterName;
        return this.InitPrinter();
    }
    #endregion
    #region public bool Init(PrinterSettings ps)
    /// <summary>
    /// 初期化処理
    /// </summary>
    /// <param name="ps">情報を取得するプリンタ設定</param>
    /// <returns>true = 取得成功, false = 取得失敗</returns>
    public bool Init(PrinterSettings ps)
    {
        if ( ps == null )
        {
            throw new ArgumentNullException("ps");
        }

        this._PrinterName = ps.PrinterName;
        return this.InitPrinter();
    }
    #endregion
    #region private bool InitPrinter()
    /// <summary>
    /// プリンタハンドルを取得する
    /// </summary>
    /// <returns>true=成功, false=失敗</returns>
    private bool InitPrinter()
    {
        IntPtr PrinterHandle;
        PrinterHandle = CreateDC(@"WINSPOOL", this._PrinterName, null, IntPtr.Zero );
        if ( PrinterHandle == IntPtr.Zero )
        {
            //失敗
            return false;
        }
        else
        {
            this._PrinterHandle = PrinterHandle;
            return true;
        }
    }
    #endregion
    #region public int GetData(CommandIndex ci)
    /// <summary>
    /// データ取得
    /// </summary>
    /// <param name="ci">コマンド番号</param>
    /// <returns>取得した値</returns>
    public int GetData(CommandIndex ci)
    {
        if ( this._PrinterHandle == IntPtr.Zero )
        {
            throw new Exception("手続きミス");
        }
        return GetDeviceCaps(this._PrinterHandle, (int)ci);
    }
    #endregion
    #region IDisposable メンバ

    /// <summary>
    /// Dispose処理
    /// プリンタを開放します。
    /// </summary>
    public void Dispose()
    {
        // TODO:  PrinterInfo.Dispose 実装を追加します。
        if ( this._PrinterHandle != IntPtr.Zero )
        {
            DeleteDC(this._PrinterHandle);
        }
    }

    #endregion
}//class

投稿日時 : 2010年4月20日 8:44

コメントを追加

#  GetDeviceCapsWrapper 2010/04/20 11:05 Pingback/TrackBack

GetDeviceCapsWrapper

#  GetDeviceCapsWrapper 2010/04/20 11:39 Pingback/TrackBack

GetDeviceCapsWrapper

#  GetDeviceCapsWrapper 2010/04/20 11:39 Pingback/TrackBack

GetDeviceCapsWrapper

#  GetDeviceCapsWrapper 2010/04/20 13:46 Pingback/TrackBack

GetDeviceCapsWrapper

# ブーツ UGG 2012/10/06 16:17 UGG シューズ

機能を理解するために見つけることは、完全な10年の履物の研究に従事'、

タイトル
名前
URL
コメント