Click here to Skip to main content
15,895,142 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 105.1K   3K   36  
Using SafeHandles to monitor a printer.
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.ComponentModel;

namespace qPrintComponent
{
    [TypeConverter(typeof(ExpandableObjectConverter)), Browsable(true), RefreshProperties(RefreshProperties.None)]
    public sealed class qPrinterStatus
    {
        private PrinterStatus _status;

        public qPrinterStatus(int Status)
        {
            _status = (PrinterStatus)Status;
        }
        public override string ToString()
        {
            return System.Enum.Format(typeof(PrinterStatus), _status, "g");
        }
        public bool Busy
        {
            get { return ((_status & PrinterStatus.Busy) == PrinterStatus.Busy); }
        }
        public bool DoorOpen
        {
            get { return ((_status & PrinterStatus.DoorOpen) == PrinterStatus.DoorOpen); }
        }
        public bool Error
        {
            get { return ((_status & PrinterStatus.Error) == PrinterStatus.Error); }
        }
        public bool Initializing
        {
            get { return ((_status & PrinterStatus.Initializing) == PrinterStatus.Initializing); }
        }
        public bool InputOutputActive
        {
            get { return ((_status & PrinterStatus.IOActive) == PrinterStatus.IOActive); }
        }
        public bool ManualFeed
        {
            get { return ((_status & PrinterStatus.ManualFeed) == PrinterStatus.ManualFeed); }
        }
        public bool NoToner
        {
            get { return ((_status & PrinterStatus.NoToner) == PrinterStatus.NoToner); }
        }
        public bool NotAvailable
        {
            get { return ((_status & PrinterStatus.NotAvailable) == PrinterStatus.NotAvailable); }
        }
        public bool Offline
        {
            get { return ((_status & PrinterStatus.Offline) == PrinterStatus.Offline); }
        }
        public bool OutOfMemory
        {
            get { return ((_status & PrinterStatus.OutOfMemory) == PrinterStatus.OutOfMemory); }
        }
        public bool OutPutBinFull
        {
            get { return ((_status & PrinterStatus.OutputBinFull) == PrinterStatus.OutputBinFull); }
        }
        public bool PagePunt
        {
            get { return ((_status & PrinterStatus.PagePunt) == PrinterStatus.PagePunt); }
        }
        public bool PaperJam
        {
            get { return ((_status & PrinterStatus.PaperJam) == PrinterStatus.PaperJam); }
        }
        public bool PaperOut
        {
            get { return ((_status & PrinterStatus.PaperOut) == PrinterStatus.PaperOut); }
        }
        public bool PaperProblem
        {
            get { return ((_status & PrinterStatus.PaperProblem) == PrinterStatus.PaperProblem); }
        }
        public bool Paused
        {
            get { return ((_status & PrinterStatus.Paused) == PrinterStatus.Paused); }
        }
        public bool PendingDeletion
        {
            get { return ((_status & PrinterStatus.PendingDeletion) == PrinterStatus.PendingDeletion); }
        }
        public bool PowerSave
        {
            get { return ((_status & PrinterStatus.PowerSave) == PrinterStatus.PowerSave); }
        }
        public bool Printing
        {
            get { return ((_status & PrinterStatus.Printing) == PrinterStatus.Printing); }
        }
        public bool Processing
        {
            get { return ((_status & PrinterStatus.Processing) == PrinterStatus.Processing); }
        }
        public bool Ready
        {
            get { return ((_status & PrinterStatus.Ready) == PrinterStatus.Ready); }
        }
        public bool ServerUnknown
        {
            get { return ((_status & PrinterStatus.ServerUnknown) == PrinterStatus.ServerUnknown); }
        }
        public bool TonerLow
        {
            get { return ((_status & PrinterStatus.TonerLow) == PrinterStatus.TonerLow); }
        }
        public bool UserInterventionRequired
        {
            get { return ((_status & PrinterStatus.UserIntervention) == PrinterStatus.UserIntervention); }
        }
        public bool Waiting
        {
            get { return ((_status & PrinterStatus.Waiting) == PrinterStatus.Waiting); }
        }
        public bool WarmingUp
        {
            get { return ((_status & PrinterStatus.WarmingUp) == PrinterStatus.WarmingUp); }
        }


        [FlagsAttribute]
        private enum PrinterStatus : int
        {
            Ready = 0,
            Busy = 0x200,
            DoorOpen = 0x400000,
            Error = 2,
            Initializing = 0x8000,
            IOActive = 0x100,
            ManualFeed = 0x20,
            NotAvailable = 0x1000,
            NoToner = 0x40000,
            Offline = 0x80,
            OutOfMemory = 0x200000,
            OutputBinFull = 0x800,
            PagePunt = 0x80000,
            PaperJam = 8,
            PaperOut = 0x10,
            PaperProblem = 0x40,
            Paused = 1,
            PendingDeletion = 4,
            PowerSave = 0x1000000,
            Printing = 0x400,
            Processing = 0x4000,
            ServerUnknown = 0x800000,
            TonerLow = 0x20000,
            UserIntervention = 0x100000,
            Waiting = 0x2000,
            WarmingUp = 0x10000
        }
    }
}

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