• 全部
  • Windows SDK/API
  • 基础类
  • ActiveX
  • 数据库及相关技术
  • 网络及通讯开发
  • VCL组件使用和开发
  • 问答

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

hackerning 2002-03-07 07:49:48
加精
比如纸张不足等,我可以捕获这些错误,从中加入自己的代码????
用的是CBUILDER中默认打印控件????
...全文
9 点赞 收藏 14
写回复
14 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
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域。

比如塞纸、缺纸、忙等。

如果需要例子的话,我可以写出来
回复
相关推荐
发帖
C++ Builder
创建于2007-08-02

1.3w+

社区成员

C++ Builder相关内容讨论区
申请成为版主
帖子事件
创建了帖子
2002-03-07 07:49
社区公告
暂无公告