Solved

Printer and Paper Source Combo's

Posted on 1998-03-30
2
304 Views
Last Modified: 2010-04-06
Can anyone tell me how to make two combo boxes, one with the current printers on the system and the other one showing the paper bins on the currently selected printer.
0
Comment
Question by:JasonC
  • 2
2 Comments
 
LVL 4

Accepted Solution

by:
d003303 earned 100 total points
ID: 1361086
Yo,

here wo go :

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ComCtrls, Printers, WinSpool;

type
  TForm1 = class(TForm)
    TreeView1: TTreeView;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
const cchBinName = 24;
var Index1,
    Index2,
    Needed      : Integer;
    ADeviceMode : THandle;
    RootNode,
    PrinterNode : TTreeNode;
    ADevice,
    ADriver,
    APort       : array[0..255] of char;
    BinArray    : PChar;
    BinName     : array[0..24] of Char;
begin
  RootNode := TreeView1.Items.Add(nil, 'Printers');
  for Index1 := 0 to Printer.Printers.Count - 1 do
   begin
     Printer.PrinterIndex := Index1;
     PrinterNode := TreeView1.Items.AddChild(RootNode, Printer.Printers[Index1]);
     Printer.GetPrinter(ADevice, ADriver, APort, ADeviceMode);
     Needed := DeviceCapabilities(ADevice, APort, dc_binnames, nil, nil);
     GetMem(BinArray, cchBinName * Needed);
     try OpenPrinter
       DeviceCapabilities(ADevice, APort, dc_binnames, BinArray, nil);
       for Index2 := 1 to Needed do
        begin
          move(BinArray[cchBinName * (Index2 - 1)], BinName[0], cchBinName);
          TreeView1.Items.AddChild(PrinterNode, String(BinName));
        end;
     finally
       FreeMem(BinArray, cchBinName * Needed);
     end;
   end;
  Printer.PrinterIndex := -1;
end;

end.


Slash/d003303
0
 
LVL 4

Expert Comment

by:d003303
ID: 1361087
Hi JasonC,
the 'try' line is incorrect. I don't know how the OpenPrinter command got there ???? It should just read 'try'.
Also the declaration
BinName     : array[0..24] of Char;
should better read
BinName     : array[0..cchBinName] of Char;
if Microsoft ever wants to change this constant in future driver releases (Nt5, Win98).

Slash/d003303
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question