TPW: How to print... 
Author Message
 TPW: How to print...

Hello!

I want to print something out of my Windows-program. I've used

  PDC:=GetDC('HPPCDL','HP Deskjet','PRN:',nil); to get the DC of the printer.

Then I used

  MoveTo(PDC, 10,10); LineTo(PDC, 100,200);

to draw something into it. So far, so good. But now the problems:

1. How can I get a list of all avaiable printers on the system ?

2. How can I get the name of the drivers and the name of the current printer?

3. How can I print out something I've written into PDC (see above) ?

Thanks a lot for your help !

  Greetings...

    Marco



Wed, 18 Jun 1902 08:00:00 GMT  
 TPW: How to print...

Quote:

>Hello!
>I want to print something out of my Windows-program. I've used
>  PDC:=GetDC('HPPCDL','HP Deskjet','PRN:',nil); to get the DC of the printer.
>Then I used
>  MoveTo(PDC, 10,10); LineTo(PDC, 100,200);
>to draw something into it. So far, so good. But now the problems:
>1. How can I get a list of all avaiable printers on the system ?

They are in WIN.INI. You can retrieve the list of printers there.

Quote:
>2. How can I get the name of the drivers and the name of the current printer?

idem.

Quote:
>3. How can I print out something I've written into PDC (see above) ?

For a demonstration, see the source code for a LST-TFDD for Windows at the
end of the article.

Quote:
>Thanks a lot for your help !
>  Greetings...
>    Marco


Unit WPrinter;
{ Deze unit voorziet in LST voor Windows
  (is een Text File Device Driver) }

interface

uses WinDOS, WinTypes, WinProcs, Strings;

{$S+,F+,R+}

Var
  LST : Text;

Procedure NieuwDoc(var Lst : Text);

{----------------------------------------------------------------------------}

implementation
{$F+}

var
  OudeExitProc : Pointer;
  LineSpace    : integer;
  LinesPerPage : integer;
  KarBreedte   : integer;
  HuidigeLijn  : integer;
  HuidigeKolom : integer;
  LijnLengte   : integer;
  TextMetric   : ^TTextMetric;

Procedure NieuwDoc(var Lst : Text);
var
  Vlag : byte;
  PrinterHouder : Array[1..4] of byte;
  PrinterHandel : HDC ABSOLUTE PrinterHouder;

begin
  With TTextRec(LST) do
  begin
    HuidigeLijn := 0;
    HuidigeKolom := 0;
    Move(UserData,PrinterHouder,4);
    Escape(PrinterHandel, NEWFRAME, 0, nil, nil);
    Escape(PrinterHandel, ENDDOC, 0, nil, nil);

  end;
end;

Procedure MijnExitProc;
var
  PrinterHouder : Array[1..4] of byte;
  PrinterHandel : HDC ABSOLUTE PrinterHouder;
  Vlag : byte;
begin
  ExitProc := OudeExitProc;
  With TTextRec(LST) do
  begin
    Move(UserData[1],PrinterHouder,4);
    Move(UserData[5],Vlag,1);
  end;
  If Vlag <> 0 then
     Close(LST);
  DeleteDC(PrinterHandel);
end;

Function LstDoeNiets(VAR F:TTextRec) : integer;
begin
  LstDoeNiets := 0;
end;

Function LSTOpenen(VAR F: TTextRec) : integer;
var
  Vlag : byte;
  PrinterHouder : Array[1..4] of byte;
  PrinterHandel : HDC ABSOLUTE PrinterHouder;
  Bladgrootte  : TPoint;
  Naam : Array[0..4] of char;
begin
  LSTOpenen := 0;
  With F do
  begin
    Move(F.UserData[5],Vlag,1);
    Move(UserData,PrinterHouder,4);
  end;
  IF Vlag = 1 then { 1 = reeds open }
    Exit;
  With F do
  begin
    GetMem(TextMetric,SizeOf(TTextMetric));
    GetTextMetrics(PrinterHandel,TextMetric^);
    LineSpace := TextMetric^.tmHeight + TextMetric^.tmExternalLeading;
    KarBreedte:= TextMetric^.tmAveCharWidth;
    StrCopy(Naam,'LST');


    LinesPerPage := Round(BladGrootte.y / LineSpace);
    HuidigeLijn := 0;
    HuidigeKolom := 0;
    Userdata[5] := 1;
  end;
end;

Function LSTSluiten(VAR F: TTextRec) : integer;
var
  Vlag : byte;
  PrinterHouder : Array[1..4] of byte;
  PrinterHandel : HDC ABSOLUTE PrinterHouder;

begin
  LSTSluiten := 0;
  With F do
  begin
    Move(F.UserData[5],Vlag,1);
    Move(UserData,PrinterHouder,4);
  end;
  IF Vlag = 0 then { 0 = reeds gesloten }
    Exit;
  With F do
  begin
    Userdata[5] := 0;
    Escape(PrinterHandel, NEWFRAME, 0, nil, nil);
    Escape(PrinterHandel, ENDDOC, 0, nil, nil);
  end;
end;

Function LSTOutputToPrinter(VAR F: TTextRec) : Integer;
{ LSTOutputToPrinter zend de output naar de printerpoort, die bewaard wordt
  in het eerste byte van het 'UserData' gebied van het TextRecord. }
Var
  PrinterHouder : Array[1..4] of byte;
  PrinterHandel : HDC ABSOLUTE PrinterHouder;
  Vlag : byte;
  Eind1, Eind2 : byte;
  NieuweLijn : Boolean;
Begin
  NieuweLijn := False;
  With F do
  Begin
    Move(Userdata[5],Vlag,1);
    If Vlag = 0 then
    begin
       LSTOutPutToPrinter := LSTOpenen(F);
       Vlag := 1;
    end;
    If (BufPos > 1) and (Byte(BufPtr^[BufPos - 2]) = 13 ) and
(Byte(BufPtr^[BufPos - 1]) = 10) then
    begin
       BufPos := BufPos - 2;
       NieuweLijn := True;
    end;
    BufPos := BufPos + 1;
    Eind1 := 0;
    Move(Eind1,BufPtr^[BufPos],1);
    Move(UserData[1],PrinterHouder,4);
    if TextOut(PrinterHandel,HuidigeKolom * KarBreedte,HuidigeLijn *
LineSPace, BufPtr^,BufPos-1) then
       LstOutPutToPrinter := 0
    else
       LstOutPutToPrinter := 160; { Device write fout }
    If NieuweLijn then
    begin
      HuidigeLijn := HuidigeLijn + 1;
      HuidigeKolom := 0;
          If HuidigeLijn > LinesPerPage then
          begin
            Escape(PrinterHandel, NEWFRAME, 0, nil, nil);
            HuidigeLijn := 0;
          end;
    end else
      HuidigeKolom := HuidigeKolom + BufPos - 1;
    BufPos := 0;
  end;
end;
{.$F-}

Procedure AssignLST;
{ AssignLST zet het LST text file record op, zoals Assign zou doen,
  en initialiseert het zoals Reset zou doen. }
var
  PrinterInfo   : Array[0..80] of char;
  PrinterType   : Array[0..40] of char;
  PrinterDriver : Array[0..40] of char;
  PrinterPoort  : Array[0..40] of char;
  PrinterInfoStr: String[80];
  PrinterHouder : Array[1..4] of byte;
  PrinterHandel : HDC ABSOLUTE PrinterHouder;
Begin

  PrinterInfoStr := StrPas(PrinterInfo);
  StrPCopy(PrinterType,Copy(PrinterInfoStr,1,Pos(',',PrinterInfoStr) -1));
  PrinterInfoStr := Copy(PrinterInfoStr,Pos(',',PrinterInfoStr) + 1,
Length(PrinterinfoStr) - Pos(',',PrinterInfoStr));
  StrPCopy(PrinterDriver,Copy(PrinterInfoStr,1,Pos(',',PrinterInfoStr)
-1));
  PrinterInfoStr := Copy(PrinterInfoStr,Pos(',',PrinterInfoStr) + 1,
Length(PrinterinfoStr) - Pos(',',PrinterInfoStr));
  StrPCopy(PrinterPoort,PrinterInfoStr);
  PrinterHandel := CreateDC(PrinterDriver,PrinterType,PrinterPoort,nil);
{  PrinterHandel := CreateDC('Epson9','EPSON 9 Pin','LPT1:',nil);}
  With TTextRec(LST) do
    begin
      Handle       := $FFFF;
      Mode         := fmOutput;
      BufSize      := SizeOf(Buffer);

      BufPos       := 0;




      Userdata[1]  := PrinterHouder[1];
      Userdata[2]  := PrinterHouder[2];
      Userdata[3]  := PrinterHouder[3];
      Userdata[4]  := PrinterHouder[4];
      UserData[5]  := 0; {gesloten}
      StrCopy(Name,'LST');
    end;
  end;

Begin    {initialisatie}
  AssignLst;
  OudeExitProc := ExitProc;

End.



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. TPW: How to print TPW prog output ?

2. TPW: How to print TPW prog output ?

3. TPW v1.5 - Printing

4. TPW 1.5 and printing

5. TPW 1.5 and Printing

6. TPW 1.5 using LPT1 to print with LEXMARK PRINTER

7. Help..(TPW Printing )

8. Printing and fonts in TPW

9. Problem printing color bitmap on color printer wih TPW 1.5

10. Printing with TPW 1.5

11. Printing DIB files from a TPW application

12. Printing with TPW 1.5

 

 
Powered by phpBB® Forum Software