::: µ¨ÆÄÀÌ Tip&Trick :::

µ¨ÆÄÀÌ Tip&Trick ¼º°Ý¿¡ ¸ÂÁö ¾Ê´Â ±¤°í,ºñ¹æ,Áú¹®ÀÇ ±ÛÀº Áï½Ã »èÁ¦Çϸç
³»¿ëÀ» º¹»çÇÏ¿© »ç¿ëÇÒ °æ¿ì ¹Ýµå½Ã ÀÌ°÷(http://www.howto.pe.kr)À» Ãâó·Î ¸í½ÃÇÏ¿© ÁÖ¼¼¿ä


Category

  ±è¿µ´ë(2003-03-07 20:20:14, Hit : 5166, Vote : 1315
 DOS-matrix ÇÁ¸°ÅÍ¿¡ ÀμâÇϱâ

Question:
How do I write a raw string of a data to the printer?

The following unit "PrtRaw.pas" demonstrates a 16/32 bit
raw printing unit for Delphi and Borland C Builder.

Following the unit, is an exmaple on using the
PrtRaw unit.

Notes:

1) You are responsible for embedding all necessary
control codes that the printer may require (including
form feed codes).

2) You must specify a valid printer and port name.



unit PrtRaw;

{Copyright (c) 1998 by Joe C. Hecht - All rights Reserved}
{joehecht@gte.net You may use and share this unit}
{providing my name and the copyright notice stays intact.}

interface

uses
  WinTypes;

{$IFDEF WIN32}
type SpoolInt = DWORD;
{$ELSE}
type SpoolInt = integer;
{$ENDIF}

function StartRawPrintJob(PrinterName : pChar;
                          Port : pChar;
                          DocName : pChar) : THandle;

function StartRawPrintPage(hPrn : THandle) : integer;

function PrintRawData(hPrn : THandle;
                      Buffer : pointer;
                      NumBytes : SpoolInt) : integer;

function EndRawPrintPage(hPrn : THandle) : integer;

function EndRawPrintJob(hPrn : THandle) : integer;


implementation
uses
   WinProcs,
{$IFDEF WIN32}
WinSpool;
{$ELSE}
Print;
{$ENDIF}


function StartRawPrintJob(PrinterName : pChar;
                          Port : pChar;
                          DocName : pChar) : THandle;
{$IFDEF WIN32}
var
   hPrn : THandle;
   DocInfo1 : TDocInfo1;
{$ENDIF}
begin
{$IFDEF WIN32}
   if (OpenPrinter(PChar(PrinterName),
                   hPrn,
                   nil) = FALSE)  then begin
     Result := THandle(-1);
     Exit;
   end;
   DocInfo1.pDocName := DocName;
   DocInfo1.pOutputFile := Port;
   DocInfo1.pDataType := 'RAW';
   if (StartDocPrinter(hPrn,
                       1,
                       @DocInfo1) = 0) then begin
     Result := THandle(-1);
     exit;
   end;
   Result := hPrn;
{$ELSE}
  result := OpenJob(Port,
                    DocName,
                    0);
{$ENDIF}
end;

function StartRawPrintPage(hPrn : THandle) : integer;
begin
{$IFDEF WIN32}
   if (StartPagePrinter(hPrn) = FALSE) then begin
     Result := -1;
     exit;
   end;
   result := 1;
{$ELSE}
  result := StartSpoolPage(hPrn);
{$ENDIF}
end;


function PrintRawData(hPrn : THandle;
                      Buffer : pointer;
                      NumBytes : SpoolInt) : integer;
{$IFDEF WIN32}
var
  BytesWritten : DWORD;
{$ENDIF}
begin
  if (NumBytes = 0) then begin
    Result := 1;
    exit;
  end;
{$IFDEF WIN32}
   if (WritePrinter(hPrn,
                    Buffer,
                    NumBytes,
                    BytesWritten) = FALSE) then begin
     Result := -1;
     exit;
   end;
   if (NumBytes <> BytesWritten) then begin
     Result := -1;
     exit;
   end;
   Result := 1;
{$ELSE}
  result := WriteSpool(hPrn,
                       Buffer,
                       NumBytes);
{$ENDIF}
end;


function EndRawPrintPage(hPrn : THandle) : integer;
begin
{$IFDEF WIN32}
   if (EndPagePrinter(hPrn) = FALSE) then begin
     Result := -1;
     exit;
   end;
   Result := 1;
{$ELSE}
  result := EndSpoolPage(hPrn);
{$ENDIF}
end;


function EndRawPrintJob(hPrn : THandle) : integer;
begin
{$IFDEF WIN32}
   if (EndDocPrinter(hPrn) = FALSE) then begin
     Result := -1;
     exit;
   end;
   if (ClosePrinter(hPrn) = FALSE) then begin
     Result := -1;
     exit;
   end;
   Result := 1;
{$ELSE}
  result := CloseJob(hPrn);
{$ENDIF}
end;


end.

Example of use:

uses
  PrtRaw;


procedure TForm1.Button1Click(Sender: TObject);
var
  hPrn : THandle;
  Data : array[0..31] of char;
begin

  hPrn := StartRawPrintJob('Generic / Text Only',
                           'LPT1:',
                           'My Document');
  if (integer(hPrn) < 0) then begin
    ShowMessage('StartRawPrintJob Failed');
    exit;
  end;

  if (StartRawPrintPage(hPrn) < 0) then begin
    ShowMessage('StartRawPrintPage Failed');
    EndRawPrintJob(hPrn);
    exit;
  end;

  Data[0] := 'P';
  Data[1] := 'a';
  Data[2] := 'g';
  Data[3] := 'e';
  Data[4] := #32;
  Data[5] := '1';
  Data[6] := #13;
  Data[7] := #10;

  if (PrintRawData(hPrn,
                   @data,
                   8) < 0) then begin
    ShowMessage('PrintRawData Failed');
    EndRawPrintPage(hPrn);
    EndRawPrintJob(hPrn);
    exit;
  end;

  if (EndRawPrintPage(hPrn) < 0) then begin
    ShowMessage('EndRawPrintPage Failed');
    EndRawPrintJob(hPrn);
    exit;
  end;

  if (StartRawPrintPage(hPrn) < 0) then begin
    ShowMessage('StartRawPrintPage Failed');
    EndRawPrintJob(hPrn);
    exit;
  end;
  Data[0] := 'P';
  Data[1] := 'a';
  Data[2] := 'g';
  Data[3] := 'e';
  Data[4] := #32;
  Data[5] := '2';
  Data[6] := #13;
  Data[7] := #10;

  if (PrintRawData(hPrn,
                   @data,
                   8) < 0) then begin
    ShowMessage('PrintRawData Failed');
    EndRawPrintPage(hPrn);
    EndRawPrintJob(hPrn);
    exit;
  end;

  if (EndRawPrintPage(hPrn) < 0) then begin
    ShowMessage('EndRawPrintPage Failed');
    EndRawPrintJob(hPrn);
    exit;
  end;

  if (EndRawPrintJob(hPrn) < 0) then begin
    ShowMessage('EndRawPrintJob Failed');
    exit;
  end;

end;

end.





451   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] ÆÄÀÏÀÇ º¯°æ/»ý¼º/»ç¿ëÇÑ ³¯Â¥ ¹Ù²Ù±â  ±è¿µ´ë 2003/03/07 5372 1344
450   [½Ã½ºÅÛ] ¼³Ä¡µÈ modem ¸®½ºÆ® ±¸ÇÏ±â  ±è¿µ´ë 2003/03/07 5367 1539
449   [À©µµ¿ìÁî API] Windows 3.1x/32s/95/98/NT ±¸ºÐÇÏ±â  ±è¿µ´ë 2003/03/07 3436 976
448   [½Ã½ºÅÛ] WM_COPYDATA ¸Þ½ÃÁö¸¦ »ç¿ëÇÑ IPC  ±è¿µ´ë 2003/03/07 7185 1746
447   [½Ã½ºÅÛ] ¸¶¿ì½ºÀÇ ÁÂ,¿ì ¹öÆ°ÀÇ µ¿ÀÛ ¹Ù²Ù±â  ±è¿µ´ë 2003/03/07 4730 1286
446   [À©µµ¿ìÁî API] windowÀÇ maximize, minimize ¾Ë¾Æ³»±â  ±è¿µ´ë 2003/03/07 5228 1385
445   [½Ã½ºÅÛ] WM_COPYDATA ¸Þ½ÃÁö¸¦ »ç¿ëÇÑ IPC 2  ±è¿µ´ë 2003/03/07 6427 1811
444   [À©µµ¿ìÁî API] µ¥½ºÅ©Å¾ ¾ÆÀÌÄÜ ÀüºÎ °¨Ãß±â/º¸ÀÌ±â  ±è¿µ´ë 2003/03/07 4400 1282
443   [À©µµ¿ìÁî API] ¹ÙÅÁÈ­¸é, ½ÃÀÛ¸Þ´º icon ¼û±â±â  ±è¿µ´ë 2003/03/07 5698 1353
442   [½Ã½ºÅÛ] ¸¶¿ì½º°¡ ¼³Ä¡µÇ¾î ÀÖ´ÂÁö °Ë»çÇÏ±â  ±è¿µ´ë 2003/03/07 7390 1973
441   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] MemoÀÇ ÀÔ·Â Çà¼ö/¿­¼ö Á¦ÇÑÇÏ±â  ±è¿µ´ë 2003/03/07 4133 1350
440   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] À©µµ¿ìÁî ÆÄÀϸíÀÇ ¹«È¿ÇÑ ±¸¼º¹®ÀÚ  ±è¿µ´ë 2003/03/07 5116 1565
439   [½Ã½ºÅÛ] ÆÄÀÏÀÌ ´Ù¸¥ ÇÁ·Î±×·¥¿¡ ÀÇÇØ »ç¿ëÁßÀÎÁö °Ë»ç  ±è¿µ´ë 2003/03/07 6835 1589
438   [½Ã½ºÅÛ] ÀÏÁ¤½Ã°£ °æ°úÈÄ ¾ø¾îÁö´Â MessageBox  ±è¿µ´ë 2003/03/07 7880 1527
437   [½Ã½ºÅÛ] CPU speed ±¸Çϱâ 2  ±è¿µ´ë 2003/03/07 4666 1275
436   [³×Æ®¿÷/ÀÎÅͳÝ] LAN ¿¡ Á¢¼ÓÇß´ÂÁö °Ë»çÇÏ±â  ±è¿µ´ë 2003/03/07 4956 1317
435   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] TIFF Images and manipulation  ±è¿µ´ë 2003/03/07 5579 1405
434   [½Ã½ºÅÛ] reboot 95/98/NT  ±è¿µ´ë 2003/03/07 5018 1416
433   [³×Æ®¿÷/ÀÎÅͳÝ] Ethernet ·£Ä«µåÀÇ MAC adress ±¸ÇÏ±â  ±è¿µ´ë 2003/03/07 7931 2288
432   [³×Æ®¿÷/ÀÎÅͳÝ] Serial Port »ç¿ëÇÏ±â  ±è¿µ´ë 2003/03/07 7427 1886
431   [À©µµ¿ìÁî API] IEÀÇ ÇöÀç url °¡Á®¿À±â  ±è¿µ´ë 2003/03/07 5167 1274
  [½Ã½ºÅÛ] DOS-matrix ÇÁ¸°ÅÍ¿¡ ÀμâÇÏ±â  ±è¿µ´ë 2003/03/07 5166 1315
429   [À©µµ¿ìÁî API] À©µµ¿ìÁî "½ÃÀÛ" ¸Þ´º¸¦ ³» ÇÁ·Î±×·¥ ¾ÈÀ¸·Î...  ±è¿µ´ë 2003/03/07 5087 1392
428   [À©µµ¿ìÁî API] ¸ðµç âÀ» ¾ÆÀÌÄÜ Ç¥½Ã/Ãë¼Ò  ±è¿µ´ë 2003/03/07 4805 1340
427   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] RichEdit È­¸é¿¡ º¸¿©Áö´Â ù¹ø°/¸¶Áö¸· Çà¹øÈ£  ±è¿µ´ë 2003/03/07 6030 1566
426   [³×Æ®¿÷/ÀÎÅͳÝ] ³×Æ®¿öÅ© ÄÄÇ»ÅÍ°¡ Á¸ÀçÇÏ´ÂÁö °Ë»çÇÏ±â  ±è¿µ´ë 2003/03/07 5363 1367
425   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] ÅؽºÆ® ÆÄÀÏ ÇÕÄ¡±â(Merging)  ±è¿µ´ë 2003/03/07 5678 1296
424   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] TRichEdit¸¦ »ç¿ëÇÑ syntax highlighting ¿¹Á¦  ±è¿µ´ë 2003/03/07 7024 1858
423   [³×Æ®¿÷/ÀÎÅͳÝ] NetMask ¾Ë¾Æ³»±â  ±è¿µ´ë 2003/03/07 7682 1958
422   [À©µµ¿ìÁî API] ApplicationÀÇ ÃÖ¼ÒÈ­½Ã Zooming È¿°ú ÁÖ±â2  ±è¿µ´ë 2003/03/07 13825 1611
421   [½Ã½ºÅÛ] driveÀÇ ÀϷùøÈ£ ¹Ù²Ù±â  ±è¿µ´ë 2003/03/07 7046 1683
420   [½Ã½ºÅÛ] CPUÀÇ »ç¿ë·ü ±¸ÇÏ±â  ±è¿µ´ë 2003/03/07 5468 3382
419   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] ¼ýÀÚÀÇ ±Ù»çÄ¡ ±¸ÇÏ±â  ±è¿µ´ë 2003/03/07 4624 1246
418   [À©µµ¿ìÁî API] How to flush key buffer  ±è¿µ´ë 2003/03/07 5032 1335
417   [COM/OLE] À©µµ¿ìÁî ½ÃÀÛÀÇ "½ÇÇà" È­¸é ¶ç¿ì±â  ±è¿µ´ë 2003/03/07 4411 1236
416   [À©µµ¿ìÁî API] ÀÛ¾÷°ü¸®ÀÚÀÇ task switching ±ÝÁö½ÃÅ°±â  ±è¿µ´ë 2003/03/07 5175 1343
415   [³×Æ®¿÷/ÀÎÅͳÝ] ÀÎÅͳݿ¡ LAN ¶Ç´Â ModemÀ¸·Î Á¢¼ÓÁßÀÎÁö °Ë»ç  ±è¿µ´ë 2003/03/07 5563 1536
414   [À©µµ¿ìÁî API] Window Handle ·Î ½ÇÇàÆÄÀÏ¸í ±¸ÇÏ±â  ±è¿µ´ë 2003/03/07 5363 1353
413   [³×Æ®¿÷/ÀÎÅͳÝ] Getting Novell Netware Login NAME  ±è¿µ´ë 2003/03/07 4087 1110
412   [ÀϹÝ/ÄÄÆ÷³ÍÆ®] ListBoxÀÇ È­¸é¿¡ º¸¿©Áö´Â ÃÖ»óÀ§ Item ¹øÈ£  ±è¿µ´ë 2003/03/07 4768 1272

[ÀÌÀü 10°³] [1]..[11][12][13] 14 [15][16][17][18][19][20]..[25] [´ÙÀ½ 10°³]
 

Copyright 1999-2024 Zeroboard / skin by zero