在CBUILDER中如何能针对打印时候出错的事件编写代码????

hackerning 2002-03-07 07:49:48
加精
比如纸张不足等,我可以捕获这些错误,从中加入自己的代码????
用的是CBUILDER中默认打印控件????
...全文
39 14 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
hackerning 2002-03-17
  • 打赏
  • 举报
回复
好啊,谢谢了EMAIL:hackerning@21cn.com
dev_uoboy 2002-03-17
  • 打赏
  • 举报
回复
已经发出来了,注意查收
Behard 2002-03-17
  • 打赏
  • 举报
回复
能不能也给我一份?
behard@21cn.com
dev_uoboy 2002-03-13
  • 打赏
  • 举报
回复
分数已经下发是什么意思???

我把程序发给你算了……看例子是最好的学习方法?
hackerning 2002-03-13
  • 打赏
  • 举报
回复
分数已经下发了,能给出 点解释吗,谢谢了:)会再给分的
dev_uoboy 2002-03-13
  • 打赏
  • 举报
回复
帖出来了,人就不见了???
dev_uoboy 2002-03-12
  • 打赏
  • 举报
回复
.h文件

#ifndef MainUnitH
#define MainUnitH
//---------------------------------------------------------------------------
#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>
#include <Forms.hpp>
#include <ComCtrls.hpp>
//---------------------------------------------------------------------------
class TMainForm : public TForm
{
__published: // IDE-managed Components
TLabel *Label1;
TComboBox *PrinterComboBox;
TLabel *Label2;
TEdit *CommentEdit;
TButton *SetCommentButton;
TStatusBar *StatusBar;
void __fastcall FormCreate(TObject *Sender);
void __fastcall SetCommentButtonClick(TObject *Sender);
void __fastcall PrinterComboBoxClick(TObject *Sender);
private: // User declarations
void __fastcall UpdateStatusBar();
AnsiString __fastcall GetComment(char *szPrinterName);
void __fastcall SetComment(char *szPrinterName, AnsiString &asComment);
public: // User declarations
__fastcall TMainForm(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TMainForm *MainForm;
//---------------------------------------------------------------------------
#endif

.cpp文件

#include <vcl.h>
#pragma hdrstop

#include "MainUnit.h"
#include <printers.hpp> // Include VCL's TPrinter
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TMainForm *MainForm;
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormCreate(TObject *Sender)
{
PrinterComboBox->Items = Printer()->Printers;
PrinterComboBox->ItemIndex = 0;
UpdateStatusBar();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::UpdateStatusBar()
{
char szDeviceName[CCHDEVICENAME], // 打应机名
szDriverName[MAX_PATH],
szPortName[MAX_PATH];
THandle hPrnDevMode;

PrinterComboBox
Printer()->PrinterIndex = PrinterComboBox->ItemIndex;
// 取得名字
Printer()->GetPrinter(szDeviceName, szDriverName, szPortName, hPrnDevMode);

StatusBar->SimpleText = "Comment: "+GetComment(szDeviceName);
}
//---------------------------------------------------------------------------
AnsiString __fastcall TMainForm::GetComment(char *szPrinterName)
{
HANDLE hPrinter;
PRINTER_DEFAULTS pd;


DWORD dwNeeded;

PRINTER_INFO_2 *pPrtInfo2; // PRINTER_INFO_2 结构指针.

AnsiString asComment;


ZeroMemory(&pd, sizeof(PRINTER_DEFAULTS));

pd.DesiredAccess = PRINTER_ALL_ACCESS;

if(!OpenPrinter(szPrinterName, &hPrinter, &pd))
{
throw Exception("Call to OpenPrinter() failed");
}

if(!GetPrinter(hPrinter, 2, NULL, 0, &dwNeeded))
{
if(GetLastError() != ERROR_INSUFFICIENT_BUFFER)
{
ClosePrinter(hPrinter);
throw Exception("1st call to GetPrinter() failed");
}
}

pPrtInfo2 = (PRINTER_INFO_2*) malloc(dwNeeded);
if(pPrtInfo2 == NULL)
{
ClosePrinter(hPrinter);
throw Exception("Call to malloc() failed");
}

// 填充 PRINTER_INFO_2
if(!GetPrinter(hPrinter, 2, (LPBYTE)pPrtInfo2,
dwNeeded, &dwNeeded))
{
free(pPrtInfo2);
ClosePrinter(hPrinter);
throw Exception("2nd call to GetPrinter() failed");
}

asComment = pPrtInfo2->pComment;

free(pPrtInfo2);
ClosePrinter(hPrinter);

return asComment;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::SetComment(char *szPrinterName,
AnsiString &asComment)
{
HANDLE hPrinter;
PRINTER_DEFAULTS pd;


DWORD dwNeeded;

PRINTER_INFO_2 *pPrtInfo2;


ZeroMemory(&pd, sizeof(PRINTER_DEFAULTS));
pd.DesiredAccess = PRINTER_ALL_ACCESS;

if(!OpenPrinter(szPrinterName, &hPrinter, &pd))
{
throw Exception("Call to OpenPrinter() failed");
}

if(!GetPrinter(hPrinter, 2, NULL, 0, &dwNeeded))
{
if(GetLastError() != ERROR_INSUFFICIENT_BUFFER)
{
ClosePrinter(hPrinter);
throw Exception("1st call to GetPrinter() failed");
}
}

pPrtInfo2 = (PRINTER_INFO_2*) malloc(dwNeeded);
if(pPrtInfo2 == NULL)
{
ClosePrinter(hPrinter);
throw Exception("Call to malloc() failed");
}

if(!GetPrinter(hPrinter, 2, (LPBYTE)pPrtInfo2,
dwNeeded, &dwNeeded))
{
free(pPrtInfo2);
ClosePrinter(hPrinter);
throw Exception("2nd call to GetPrinter() failed");
}

pPrtInfo2->pComment = asComment.c_str();

if(!SetPrinter(hPrinter, 2, (LPBYTE)pPrtInfo2, 0))
{
free(pPrtInfo2);
ClosePrinter(hPrinter);
throw Exception("Call to SetPrinter() failed");
}

free(pPrtInfo2);
ClosePrinter(hPrinter);
}
//---------------------------------------------------------------------------

void __fastcall TMainForm::SetCommentButtonClick(TObject *Sender)
{
char szDeviceName[CCHDEVICENAME],
szDriverName[MAX_PATH],
szPortName[MAX_PATH];
THandle hPrnDevMode;


Printer()->PrinterIndex = PrinterComboBox->ItemIndex;

Printer()->GetPrinter(szDeviceName, szDriverName, szPortName, hPrnDevMode);

SetComment(szDeviceName, CommentEdit->Text);
CommentEdit->Text = "";
UpdateStatusBar();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::PrinterComboBoxClick(TObject *Sender)
{
UpdateStatusBar();
}
hackerning 2002-03-11
  • 打赏
  • 举报
回复
好加分没问题 ,能写写例子出来吗,给200分
dev_uoboy 2002-03-10
  • 打赏
  • 举报
回复
能不能加点分啊?20,似乎感觉上少了点:(
dev_uoboy 2002-03-10
  • 打赏
  • 举报
回复
呵呵
大大怪老张 2002-03-10
  • 打赏
  • 举报
回复
敲诈!

不过.....................赶快加点分吧
jintaocom 2002-03-08
  • 打赏
  • 举报
回复
我也需要。。look
rocsoar 2002-03-08
  • 打赏
  • 举报
回复
需要需要。:)
dev_uoboy 2002-03-07
  • 打赏
  • 举报
回复
使用PRINTER_INFO_2结构的Status域。

比如塞纸、缺纸、忙等。

如果需要例子的话,我可以写出来

13,871

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧