Solved

Printer and Paper Source Combo's

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

696 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