Solved

Printer and Paper Source Combo's

Posted on 1998-03-30
2
301 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now