请问编写打印程序时如何自定义纸张大小(在NT4.0、win2000上)?

kmfangxun 2000-03-27 09:24:00
加精
请问编写打印程序时如何自定义纸张大小(在NT4.0、win2000上)?最好用WINAPI编写。
...全文
345 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
孩皮妞野 2001-07-04
  • 打赏
  • 举报
回复
:)
caili 2000-05-28
  • 打赏
  • 举报
回复
SetPrinter失败的原因是OpenPrinter时要指定PRINTER_ALL_ACCESS.但是SetPrinter成功后,使用D5的QuickReport打印,Preview很好,打印在打印机上也只打印指定页长的内容后走纸,但是所走的纸还是比如A4的长度而不是SetPrinter指定的长度.使用StartDoc, StartPage, EndPage调用也一样.Any idea?
kmfangxun 2000-05-28
  • 打赏
  • 举报
回复
如果用连续纸张打印的话,应该不会吧!
caili 2000-05-27
  • 打赏
  • 举报
回复
在winnt上调用SetPrinter时失败,错误信息是"拒绝访问",怎么办?
kmfangxun 2000-05-27
  • 打赏
  • 举报
回复
Copy from win32sdk:

If the calling application lacks a required permission, SetPrinter fails. Those components of a security descriptor that an application does not wish to modify should be NULL or not be present, as appropriate. If you do not want to modify the security descriptor, and are calling SetPrinter with a PRINTER_INFO_2 structure, set the pSecurityDescriptor member of that structure to NULL.
halfdream 2000-04-04
  • 打赏
  • 举报
回复
SORRY,我不清楚。 建议你再发一张帖子问问朋友们谁遇上过这种情况没有,
哪个有什么补丁包可以找一下。
kmfangxun 2000-04-03
  • 打赏
  • 举报
回复
halfdream:您好!
非常感谢您给的示列,我在用bcb4设计QuickRep报表时发觉,QuickRep->Page->PaperSize设为Custom时,当改变QuickRep->Page->Wdith和QuickRep->Page->Length时,在win95及win98下QuickRep工作均正常,但在nt4及win2000下,QuickRep->Page->Wdith和QuickRep->Page->Length只认控制面板中设置的大小,所以企图用TPrinter或您示列的WINAPI方法改变控制面板中设置的打印机纸张大小达到改变QuickRep->Page->Length和QuickRep->Page->Width的目的,但都不行。这会不会是bcb4的QuickRep的Bug呢?我试过delphi5的QuickRep,工作正常,看来只能等拿到bcb5了。如果不修改TQuickRep,还有别的解决办法吗?
kmfangxun 2000-04-02
  • 打赏
  • 举报
回复
halfdream :您好!
能举列明示吗?
halfdream 2000-04-02
  • 打赏
  • 举报
回复

BOOL SetPaper(LPTSTR pPrinterName,short width,short length)
{
HANDLE hprinter;
PRINTER_INFO_2 *pPinfo;
BYTE buf[1000];
DEVMODE *pDev;
DWORD cbNeeded;
if(!::OpenPrinter(pPrinterName,&hprinter,NULL))return 0;
if(!::GetPrinter(hprinter,2,buf,1000,&cbNeeded))return 0;
pPinfo=(PRINTER_INFO_2*)buf;
pDev=pPinfo->pDevMode;
pDev->dmPaperLength=length;
pDev->dmPaperWidth=width;
SetPrinter(hprinter,2,buf,0);
if(!::ClosePrinter(hprinter))return 0;
return 1;
}

临时写成,在BCB4下编译通过,可能存在错,不过是这种方法。
另外,如果BCB4的话,用TPrinter 实现要轻松加愉快得多。
halfdream 2000-03-30
  • 打赏
  • 举报
回复
简单点说,是调用GetPrinter(),返回打印机的信息在结构PRINT_INFO_2中,
将这个结构中的有关纸张尺寸的属性改后,后再用SetPrinter()设置.
其中,PRINT_INFO_2中成员LPDEVMODE pDevMode指向DEVMODE;
结构体DEVMODE
{......
short dmPaperLength;
short dmPaperWidth;
......}
主要就是改这两个东东.

其余的具体的你可以查相关API帮助,
kmfangxun 2000-03-28
  • 打赏
  • 举报
回复
真遗憾,没有人回答我,嫌分少吗,我再加50分,怎么样。

13,822

社区成员

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

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