?
Solved

Printer and Paper Source Combo's

Posted on 1998-03-30
2
Medium Priority
?
307 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 4

Accepted Solution

by:
d003303 earned 300 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month12 days, 10 hours left to enroll

777 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