Autor Beitrag
patmann2001
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 201

Windows 7 Prof.
Delphi XE2
BeitragVerfasst: Mo 21.07.03 15:38 
Hallo

Ich möchte, wie der Titel schon sagt, den Drucker direkt über die API aufrufen ohne die Printer Unit zu verwenden. Kann mir jemand sagen, wie das geht?

cu Patmann
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 21.07.03 16:14 
Hier mal ein Auschnitt aus einem programm von mir. benötigt wird nur WinSpool.pas

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
{-----------------------------------------------------------------------------
  Procedure : Print // 2003-05-08 01:34:02
  Author    : Michael Puff
  Purpose   : Does the print job
  Arguments : Caption: String; DataRecord: TDataRecord
  Result    : None
-----------------------------------------------------------------------------}

procedure Print(Caption: String; DataRecord: TDataRecord);
var
  di                   : DOCINFO;
  pd                   : TPrintDlg;
  dm                   : TDEVMODE;
  iTotalLines, yChar,
  iLinesPerPage,
  iTotalPages, iPage,
  iLine, iLineNum,
  iColCopy             : Integer;
  tm                   : TTEXTMETRIC;
  s                    : String;
  i, j                 : Integer;
  rec                  : TRect;
  OldFont              : HFONT;
  sArray               : TLVitemArray;
  sTemp                : TDataRecord;
  cntDR                : Integer;
begin
  OldFont := 0;
  cntDR := length(DataRecord);
  sTemp := DataRecord;
  ZeroMemory(@pd, sizeof(TPrintDlg));
  Zeromemory(@dm, sizeof(TDevMode));
  dm.dmSize := sizeof(TDEVMODE);
  dm.dmOrientation := DMORIENT_LANDSCAPE;
  pd.lStructSize := sizeof(TPrintDlg);
  pd.hWndOwner   := hApp;
  pd.Flags       := PD_ALLPAGES or PD_COLLATE or PD_RETURNDC or PD_NOSELECTION;
//  pd.hDevMode    := dm;
  Move(pd.hDevMode,dm,sizeof(TDevMode));
  pd.nCopies     := 1;
  if PrintDlg(pd) = TRUE then
  begin
    MyFont := CreateFont(FontSize, 000500000, ANSI_CHARSET,
      OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
      DEFAULT_PITCH, FontName);
      if MyFont <> 0 then
        OldFont := SelectObject(pd.hDC, MyFont);
    iTotalLines := SendDlgItemMessage(hApp, IDC_LV, LVM_GETITEMCOUNT, 00);
    GetTextMetrics(pd.hDC, tm);
    yChar := tm.tmHeight + tm.tmExternalLeading;
    iLinesPerPage := (GetDeviceCaps(pd.hDC, VERTRES) div yChar) - 1;
    iTotalPages   := (iTotalLines + iLinesPerPage - 1div iLinesPerPage;
    rec.Left := 25;
    rec.Right := GetDeviceCaps(pd.hDC, HORZRES);
    ZeroMemory(@di, sizeof(DOCINFO));
    di.cbSize := sizeof(DOCINFO);
    di.lpszDocName := 'Test';
    if StartDoc(pd.hDC, di) > 0 then
    begin
      for iColCopy := 0 to pd.nCopies-1 do
      begin
        s := Caption;
        rec.Top := yChar-5;
        rec.Bottom := rec.Top+yChar;
        DrawText(pd.hDC, pointer(s), length(s), rec, DT_CENTER);
        for iPage := 0 to iTotalPages-1 do
        begin
          rec.Top := yChar*3;
          rec.Bottom := yChar*4;
          for i := 0 to 7 do
          begin
            case i of
              0: rec.Left := 25;
              1: rec.Left := rec.Left+500;
              2: rec.Left := rec.Left+500;
              3: rec.Left := rec.Left+175;
              4: rec.Left := rec.Left+375;
              5: rec.Left := rec.Left+375;
              6: rec.Left := rec.Left+375;
              7: rec.Left := rec.Left+660;
            end;
            s := PrnColumns[i];
            DrawText(pd.hDC, pointer(s), length(s), rec, 0);
          end;

          for iLine := 0 to iLinesPerPage-1 do
          begin
            ProcessMessages(hApp);
            if iPage = 0 then
              iLineNum := iLinesPerpage*iPage+iLine
            else
              iLineNum := iLinesPerpage*iPage+iLine-4;
            if iLineNum < cntDR then
              sArray := sTemp[iLineNum]
            else
              break;

            rec.Left := 25;
            rec.Top := (yChar*iLine)+(5*yChar);
            rec.Bottom := rec.Top+yChar;
            for j := 0 to length(sArray)-1 do
            begin
              case j of
                0: rec.Left := 25;
                1: rec.Left := rec.Left+500;
                2: rec.Left := rec.Left+500;
                3: rec.Left := rec.Left+175;
                4: rec.Left := rec.Left+375;
                5: rec.Left := rec.Left+375;
                6: rec.Left := rec.Left+375;
                7: rec.Left := rec.Left+660;
              end;
              s := sArray[j];
              DrawText(pd.hDC, pointer(s), length(s), rec, DT_TABSTOP);
            end;
          end;
          if EndPage(pd.hDC) < 0 then exit;
        end;
      end;
    end;
    EndDoc(pd.hDC);
    SelectObject(pd.hDC, OldFont);
    DeleteObject(pd.hDC);
  end;
end;


Nachtrag: Wenn du weißt, dass du es ohne VCL machen willst und direkt mit der WinAPI, warum postest du trotzdem im falschen Forum? :roll:
patmann2001 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 201

Windows 7 Prof.
Delphi XE2
BeitragVerfasst: Mi 23.07.03 11:28 
Erstmal Sorry für das Eintragen im falschen Forum. :oops:
Habe da wohl nicht richtig aufgepasst.

Dieser Type von TDataRecord was enthält der? Bzw. Wie kann ich einen Canvas übergeben?

cu Patmann
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mi 23.07.03 11:42 
TDataRecord ist ein eigener Record aus meinem Programm. Interessant für dich sind:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
var
  di                   : DOCINFO; 
  pd                   : TPrintDlg; 
  dm                   : TDEVMODE;
  iTotalLines, yChar, 
  iLinesPerPage, 
  iTotalPages, iPage, 
  iLine, iLineNum, 
  iColCopy             : Integer; 
  tm                   : TTEXTMETRIC;
begin
  ZeroMemory(@pd, sizeof(TPrintDlg)); 
  Zeromemory(@dm, sizeof(TDevMode)); 
  dm.dmSize := sizeof(TDEVMODE); 
  dm.dmOrientation := DMORIENT_LANDSCAPE; 
  pd.lStructSize := sizeof(TPrintDlg); 
  pd.hWndOwner   := hApp; 
  pd.Flags       := PD_ALLPAGES or PD_COLLATE or PD_RETURNDC or PD_NOSELECTION; 
//  pd.hDevMode    := dm; 
  Move(pd.hDevMode,dm,sizeof(TDevMode)); 
  pd.nCopies     := 1
  if PrintDlg(pd) = TRUE then   //PrinterDialog aufrufen
  begin 
    iTotalLines := SendDlgItemMessage(hApp, IDC_LV, LVM_GETITEMCOUNT, 00); 
    GetTextMetrics(pd.hDC, tm); 
    yChar := tm.tmHeight + tm.tmExternalLeading; 
    iLinesPerPage := (GetDeviceCaps(pd.hDC, VERTRES) div yChar) - 1
    iTotalPages   := (iTotalLines + iLinesPerPage - 1div iLinesPerPage; 
    rec.Left := 25
    rec.Right := GetDeviceCaps(pd.hDC, HORZRES); 
    ZeroMemory(@di, sizeof(DOCINFO)); 
    di.cbSize := sizeof(DOCINFO); 
    di.lpszDocName := 'Test'
    if StartDoc(pd.hDC, di) > 0 then  // Drucken beginnen 
    begin

Und dann alle Ausgaben mit
ausblenden Delphi-Quelltext
1:
DrawText(pd.hDC, pointer(s), length(s), rec, DT_CENTER);					


Moderiert von user profile iconTino: Delphi-Tags hinzugefügt.
AndyB
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1173
Erhaltene Danke: 14


RAD Studio XE2
BeitragVerfasst: Mi 23.07.03 12:15 
patmann2001 hat folgendes geschrieben:
Bzw. Wie kann ich einen Canvas übergeben?

Du wolltest doch mit der WinAPI drucken. Dann trage auch die Konsequenzen. Es ist zwar möglich, aber nicht um sonst hat Borland eine eigene TPrinterCanvas Klasse geschaffen, die in Printers eingesetzt wird.

_________________
Ist Zeit wirklich Geld?