Solved

Printer and Paper Source Combo's

Posted on 1998-03-30
2
306 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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

690 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