線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1530
推到 Plurk!
推到 Facebook!

Builder 5 單行列印

尚未結案
x8051
一般會員


發表:12
回覆:18
積分:6
註冊:2004-04-15

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-06-29 03:05:34 IP:218.172.xxx.xxx 未訂閱
以前有看過,不過只能使用LPT1 或 EPSON廠牌,無法使用USB LPT 界面及HP廠牌?
 #include //INI file
#include     #pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;    String ppstr;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}    //§ì¨ú¦Lªí¾÷«¬¸¹//-----------------------------------------------------------------------------
void GetDefaultPrinter(char *printer_name) 
{ 
    char *def_string = "no printer"; 
    char buffer[MAX_PATH]; 
    GetProfileString("windows", "device", def_string,buffer, MAX_PATH);        AnsiString Abuffer(buffer); 
    int first_comma = Abuffer.Pos(","); 
    strcpy(printer_name, Abuffer.SubString(1, first_comma - 1).c_str()); 
}     //-------------------------------------------------------------------------------------------------
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{    ////Other Pring Mode Example ////////////
/*
 Printers::Printer()->Refresh();
int LineNum , MaxLineNum , LineSpace , FontHeight, posy , i;     if (PrintDialog1->Execute())
 {      Printer()->Canvas->Font = Memo1->Font;//³]©w¦r«¬»PMemo1¤¤ªº¦r«¬¬Û¦P
  Printer()->BeginDoc();//<<±Ò°Ê¤@­Ó·sªº¦Lªí¤u§@
  LineNum = 0;
  //¨ú¦Lªí¾÷²{¦b¦r«¬ªº°ª«×
  FontHeight = Printer()->Canvas->TextHeight("Ay");
  MaxLineNum = (Printer()->PageHeight/(FontHeight 10))-4;
  LineSpace = FontHeight 10;
  posy = LineSpace; //¦C¦L««ª½¤è¦Vªº¦ì¸m
    for (i=0;iLines->Count;i  )
    {
     //§â¤å¦r¤@¦æ¦æªº¦C¦L¥X¨Ó
     Printer()->Canvas->TextOut(10,posy,Memo1->Lines->Strings[i]);
     LineNum  ;//­pºâ¦æ¼Æ
     posy =LineSpace;//««ª½¤è¦V¦ì¸m
        if (LineNum > MaxLineNum)
        {//¦pªG¶W¹L³Ì¤j¦æ¼Æ´N¸õ­¶
         Printer()->NewPage();//°e¥X¸õ­¶½X
         posy = LineSpace;
         LineNum = 0;
         }
     }
Printer()->EndDoc();//<<<µ²§ô¦C¦L«ü¥O
   }    */
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{    String st="012345678901234567890AAAAAAAAAAAA" AnsiString(char(0x0a));//0x0a´«¦æ(carriage)
char *szPrinterName= ppstr.c_str();
char *szBuffer= st.c_str();      HANDLE hPrinter;
  int iLen = strlen(szBuffer);// ­n¦C¦L¶Ç°e¸ê®Æªºªø«×
  DWORD dwWritten;            // ¸ê®Æ¶q¦h¤Ö    // ¶}±Ò¨èú±o¤@­Ó¦C¦L¦æµ{HANDLE
if( OpenPrinterA(szPrinterName, &hPrinter, NULL) )
{
//¬ÛÃö¦C¦L°Ñ¼Æ¸ê°T
DOC_INFO_1 Info;
int szInfo = sizeof(Info);
memset(&Info, 0, szInfo);         //²M°£buffer
Info.pDocName = "The Test Print"; // µ¹­Óprint±M®×¦WºÙ
Info.pOutputFile = NULL;          //¤£¦s¦¨ÀɮשҥH NULL´N¥i¥H
Info.pDatatype = "RAW";           //¶Ç°e¼Ò¦¡¨Ï¥Î RAW Format    // ¶}±Ò¦C¦L
if(!StartDocPrinterA(hPrinter, 1, (LPBYTE)&Info))
ShowMessage("StartDocPrinter Error~");    StartPagePrinter(hPrinter);     // ¶}±Ò¦C¦L­¶¶Ç¤J«ü©wªº¦C¦L¦æHANDLE
if(!WritePrinter(hPrinter, szBuffer, iLen, &dwWritten))
{
ShowMessage("¦C¦L¿ù»~");// ¼g¤J¿ù»~
}    EndPagePrinter(hPrinter);//§¹¦¨µ²§ô¦C¦L­¶    if(!EndDocPrinter(hPrinter)) 
ShowMessage("Ãö³¬¿ù»~");    ClosePrinter(hPrinter);//Ãö³¬¦C¦L¦æµ{
ListBox1->Items->Add(st);
} 
else 
{ 
ShowMessage("OpenPrinter Error~");
}
}
發表人 - taishyang 於 2004/06/29 12:31:04
系統時間:2017-12-16 15:23:50
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!