Click here to Skip to main content
15,891,529 members
Articles / Programming Languages / C#

Printers and SafeHandles (Part 2)

Rate me:
Please Sign up or sign in to vote.
3.00/5 (7 votes)
16 Apr 20073 min read 105K   3K   36  
Using SafeHandles to monitor a printer.
using System;
using System.Runtime.InteropServices;

namespace qPrintComponent
{   
    public enum Page_Orientation : short
    {
        PORTRAIT = 1,
        LANDSCAPE = 2
    }

    public enum Page_Duplex : short
    {
        SIMPLEX = 1,
        VERTICAL = 2,
        HORIZONTAL = 3
    }
    public enum Printer_Collate : short
    {
        FALSE = 0,
        TRUE = 1
    }
    public enum Printer_ICMIntend : short
    {
        SATURATE = 1,
        CONTRAST = 2,
        COLORMETRIC = 3,
        USER = 0x100
    }
    public enum Printer_ICMMethod : short
    {
        NONE = 1,
        SYSTEM = 2,
        DRIVER = 3,
        DEVICE = 4,
        USER = 0x100
    }
    public enum Printer_Dither : short
    {
        None = 0,
        NONE = 1,
        COARSE = 2, 
        FINE = 3,
        LINEART = 4,
        GRAYSCALE = 5,
        USER = 0x100
    }
    public enum Printer_Media : short
    {
        STANDARD = 1,
        TRANSPARENCY = 2,
        GLOSSY = 3,
        USER = 0x100    
    }
    public enum Paper_Source : short
    {
        FIRST = UPPER,
        UPPER = 1,
        ONLYONE = 1,
        LOWER = 2,
        MIDDLE = 3,
        MANUAL = 4,
        ENVELOPE = 5,
        ENVMANUAL = 6,
        AUTO = 7,
        TRACTOR = 8,
        SMALLFMT = 9,
        LARGEFMT = 10,
        LARGECAPACITY = 11,
        CASSETTE = 14,
        FORMSOURCE = 15,
        LAST = FORMSOURCE,
        user = 256
    }

    public enum Print_Color : short
    {
        /* color enable/disable for color printers */
        MONOCHROME = 1,
        COLOR = 2,
    }
    public enum Print_TrueType : short
    {
        BITMAP = 1,
        DOWNLOAD = 2,
        SUBDEV = 3,
        DOWNLOAD_OUTLINE = 4,
    }


    public enum PrinterControl : int
    {
        Nul = 0,
        Pause = 1,
        Resume = 2,
        Purge = 3,
        SetStatus = 4
    }

    [Flags]
    public enum Printer_Change : uint
    {
        ADD_PRINTER =             0x00000001,
        SET_PRINTER  =            0x00000002,
        DELETE_PRINTER=           0x00000004,
        FAILED_CONNECTION_PRINTER  =  0x00000008,
        PRINTER               =   0x000000FF,
        ADD_JOB               =   0x00000100,
        SET_JOB               =   0x00000200,
        DELETE_JOB            =   0x00000400,
        WRITE_JOB             =   0x00000800,
        JOB                   =   0x0000FF00,
        ADD_FORM              =   0x00010000,
        SET_FORM              =   0x00020000,
        DELETE_FORM           =   0x00040000,
        FORM                  =   0x00070000,
        ADD_PORT              =   0x00100000,
        CONFIGURE_PORT        =   0x00200000,
        DELETE_PORT           =   0x00400000,
        PORT                  =   0x00700000,
        ADD_PRINT_PROCESSOR    =  0x01000000,
        DELETE_PRINT_PROCESSOR  = 0x04000000,
        PRINT_PROCESSOR         = 0x07000000,
        ADD_PRINTER_DRIVER      = 0x10000000,
        SET_PRINTER_DRIVER      = 0x20000000,
        DELETE_PRINTER_DRIVER   = 0x40000000,
        PRINTER_DRIVER          = 0x70000000,
        TIMEOUT                 = 0x80000000,
        ALL                     = 0x7777FFFF
}
    public enum Printer_Notification_Types : short
    {
        PRINTER_NOTIFY_TYPE = 0,
        JOB_NOTIFY_TYPE = 1
    }
    public enum Printer_Notify_Field_Indexes
    {
        SERVER_NAME = 0,
        PRINTER_NAME = 1,
        SHARE_NAME = 2,
        PORT_NAME = 3,
        DRIVER_NAME = 4,
        COMMENT = 5,
        LOCATION = 6,
        DEVMODE = 7,
        SEPFILE = 8,
        PRINT_PROCESSOR = 9,
        PARAMETERS = 10,
        DATATYPE = 11,
        SECURITY_DESCRIPTOR = 12,
        ATTRIBUTES = 13,
        PRIORITY = 14,
        DEFAULT_PRIORITY = 15,
        START_TIME = 16,
        UNTIL_TIME = 17,
        STATUS = 18,
        STATUS_STRING = 19,
        CJOBS = 20,
        AVERAGE_PPM = 21,
        TOTAL_PAGES = 22,
        PAGES_PRINTED = 23,
        TOTAL_BYTES = 24,
        BYTES_PRINTED = 25,
        OBJECT_GUID = 26
    }

    public enum Job_Notify_Field_Indexes
    {
        PRINTER_NAME = 0,
        MACHINE_NAME = 1,
        PORT_NAME = 2,
        USER_NAME = 3,
        NOTIFY_NAME = 4,
        DATATYPE = 5,
        PRINT_PROCESSOR = 6,
        PARAMETERS = 7,
        DRIVER_NAME = 8,
        DEVMODE = 9,
        STATUS = 10,
        STATUS_STRING = 11,
        SECURITY_DESCRIPTOR = 12,
        DOCUMENT = 13,
        PRIORITY = 14,
        POSITION = 15,
        SUBMITTED = 16,
        START_TIME = 17,
        UNTIL_TIME = 18,
        TIME = 19,
        TOTAL_PAGES = 20,
        PAGES_PRINTED = 21,
        TOTAL_BYTES = 22,
        BYTES_PRINTED = 23//,
        //ERROR = 999
    }
    [Flags]
    public enum Job_Status
    {
        BLOCKED_DEVICEQUEUE = 0x200,
        DELETED = 0x100,
        DELETING = 4,
        ERROR = 2,
        OFFLINE = 0x20,
        PAPEROUT = 0x40,
        PAUSED = 1,
        PRINTED = 0x80,
        PRINTING = 0x10,
        RESTART = 0x800,
        SPOOLING = 8,
        INTERVENTION = 0x400
    }

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer
Belgium Belgium
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions