?
Solved

Sending data to chosen Paper Source

Posted on 1998-03-31
1
Medium Priority
?
229 Views
Last Modified: 2010-04-06
I have two combo boxes that choose printer and paper source information, and store this info in the registry for my app.
How do I tell windows to use my selected paper source, the printer is easy. I don't want to use the printer setup dialog.
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
1 Comment
 
LVL 4

Accepted Solution

by:
d003303 earned 160 total points
ID: 1361140
Hi again,
I included the code into my code of the previuos answer. The main thing is to get a BinID-List and set the desired bin before the job starts. The Bin-ID is stored as a Word in the Data property of the Bin-Nodes, the Printer-ID as an Integer at the same place.

//////////////////////////
//
// to be unit1.pas
//
unit Unit1;

interface

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

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

var
  Form1: TForm1;

function MyDocumentProperties(hWnd: HWND; hPrinter: THandle; pDeviceName: PChar;
  const pDevModeOutput: PDeviceMode; pDevModeInput: PDeviceMode;
  fMode: DWORD): Longint; stdcall;

implementation

{$R *.DFM}

const
  winspl = 'winspool.drv';

function MyDocumentProperties; external winspl name 'DocumentPropertiesA';

procedure TForm1.Button1Click(Sender: TObject);
const cchBinName = 24;
var Index1,
    Index2,
    Needed       : Integer;
    ADeviceMode  : THandle;
    RootNode,
    PrinterNode,
    TempNode     : TTreeNode;
    ADevice,
    ADriver,
    APort        : array[0..255] of char;
    BinIDArray,
    BinNameArray : PChar;
    BinID        : Word;
    BinName      : array[0..24] of Char;
begin
  TreeView1.Items.Clear;
  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]);
     PrinterNode.Data := Pointer(LongInt(Index1));
     Printer.GetPrinter(ADevice, ADriver, APort, ADeviceMode);
     Needed := DeviceCapabilities(ADevice, APort, dc_binnames, nil, nil);
     GetMem(BinNameArray, cchBinName * Needed);
     GetMem(BinIDArray, 2 * Needed);
     FillChar(BinNameArray[0], cchBinName * Needed, 0);
     FillChar(BinIDArray[0], 2 * Needed, 0);
     try
       DeviceCapabilities(ADevice, APort, dc_binnames, BinNameArray, nil);
       DeviceCapabilities(ADevice, APort, dc_bins, BinIDArray, nil);
       for Index2 := 1 to Needed do
        begin
          move(BinNameArray[cchBinName * (Index2 - 1)], BinName[0], cchBinName);
          move(BinIDArray[2 * (Index2 - 1)], BinID, 2);
          TempNode := TreeView1.Items.AddChild(PrinterNode, String(BinName));
          TempNode.Data := Pointer(LongInt(BinID));
        end;
     finally
       FreeMem(BinIDArray, 2 * Needed);
       FreeMem(BinNameArray, cchBinName * Needed);
     end;
   end;
  Printer.PrinterIndex := -1;
end;

procedure TForm1.Button2Click(Sender: TObject);
var ANode       : TTreeNode;
    PrinterID   : Integer;
    BinID       : Word;
    ADevice,
    ADriver,
    APort       : array[0..255] of char;
    ADeviceMode : THandle;
    DevMode     : PDeviceMode;
begin
  ANode := TreeView1.Selected;
  if ANode <> nil then
   if ANode.Parent <> nil then
    if ANode.Parent.Text <> 'Printers' then
     begin
       BinID := Word(ANode.Data);
       PrinterID := Integer(ANode.Parent.Data);

       Printer.PrinterIndex := PrinterID;
       Printer.GetPrinter(ADevice, ADriver, APort, ADeviceMode);
       DevMode := GlobalLock(ADeviceMode);
       DevMode^.dmDefaultSource := BinID;
       Printer.SetPrinter(ADevice, ADriver, APort, ADeviceMode);
       GlobalUnlock(ADeviceMode);

       Printer.Title := 'Hello World!';
       Printer.BeginDoc;
       Printer.Canvas.TextOut(200, 200, 'Hello World!');
       Printer.EndDoc;
       Printer.PrinterIndex := -1;
     end;
end;

end.

//////////////////////////
//
// to be unit1.dfm
//
object Form1: TForm1
  Left = 200
  Top = 108
  BorderStyle = bsDialog
  Caption = 'Form1'
  ClientHeight = 375
  ClientWidth = 262
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  PixelsPerInch = 96
  TextHeight = 13
  object TreeView1: TTreeView
    Left = 8
    Top = 8
    Width = 245
    Height = 329
    Indent = 19
    TabOrder = 0
  end
  object Button1: TButton
    Left = 8
    Top = 344
    Width = 121
    Height = 25
    Caption = 'Query Printers'
    TabOrder = 1
    OnClick = Button1Click
  end
  object Button2: TButton
    Left = 132
    Top = 344
    Width = 121
    Height = 25
    Caption = 'Print to selected bin'
    TabOrder = 2
    OnClick = Button2Click
  end
end

Have fun,
Slash/d003303
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

719 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