如何用Win32API来设置打印份数

gamesuwei 2009-06-23 06:22:39
不用CPrintDlg,用API如何来设置打印的打印份数呢?
查了下MSDN发觉用GetJob / SetJob 能设置,但是具体不知道怎么实现,有人能帮忙吗?不甚感激~
...全文
371 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
gamesuwei 2009-06-24
  • 打赏
  • 举报
回复
4楼的办法就是我现在使用的,有一个很严重的问题就是在nCopies数量很大的时候会造成打印缓存超大 因为这样他每一个copies都是当做一个新任务载入的
qq14923349 2009-06-24
  • 打赏
  • 举报
回复
水晶报表吧
如果是小程序还可以考虑API
大程序就干脆用现成类吧

你有信心写的比别人成熟吗
chehw 2009-06-24
  • 打赏
  • 举报
回复

StartDoc();
for (i=0; i <nCopies; i++)
{
for(j=0;j<nPages;j++)
{
StartPage();
DrawPage(j);
EndPage();
}
}
EndDoc();
chehw 2009-06-23
  • 打赏
  • 举报
回复
for (i=0; i<nCopies; i++)
{
StartDoc();
StartPage();
DrawPage();
EndPage();
EndDoc();
}
Gothic_girl 2009-06-23
  • 打赏
  • 举报
回复
看看这个:
http://support.microsoft.com/default.aspx?scid=kb;en-us;160129

http://support.microsoft.com/kb/158828
Gothic_girl 2009-06-23
  • 打赏
  • 举报
回复
SetJob Function

The SetJob function pauses, resumes, cancels, or restarts a print job on a specified printer. You can also use the SetJob function to set print job parameters, such as the print job priority and the document name.

Windows 95, Windows 98, Windows Me: You can use the SetJob function to give a command to a print job, or to set print job parameters, but you cannot do both in the same call. Thus, when the Command parameter is nonzero, the function ignores the Level and pJob parameters. To set print job parameters, you must set Command to 0.

Windows NT, Windows 2000, Windows XP, Windows Vista: You can use the SetJob function to give a command to a print job, or to set print job parameters, or to do both in the same call. The value of the Command parameter does not affect how the function uses the Level and pJob parameters. Also, you can use SetJob with JOB_INFO_3 to link together a set of print jobs. See Remarks for more information.
Syntax
C++


BOOL SetJob(
__in HANDLE hPrinter,
__in DWORD JobId,
__in DWORD Level,
__in LPBYTE pJob,
__in DWORD Command
);

Parameters

hPrinter [in]

Handle to the printer object of interest. Use the OpenPrinter, OpenPrinter2, or AddPrinter function to retrieve a printer handle.
JobId [in]

Identifier that specifies the print job. You obtain a print job identifier by calling the AddJob function or the StartDoc function.

Windows NT, Windows 2000, Windows XP, Windows Vista: If the Level parameter is set to 3, the JobId parameter must match the JobId member of the JOB_INFO_3 structure pointed to by pJob
Level [in]

Specifies the type of job information structure pointed to by the pJob parameter.

All versions of Windows: You can set the Level parameter to 0, 1, or 2. When you set Level to 0, pJob should be NULL. Use these values when you are not setting any print job parameters.

Windows NT, Windows 2000, Windows XP, Windows Vista: You can also set the Level parameter to 3.

Windows Vista: You can also set the Level parameter to 4.

Windows 95, Windows 98, Windows Me: The function pays attention to this parameter only if the Command parameter is 0. If Command is nonzero, the function ignores this parameter and the pJob parameter.
pJob [in]

Pointer to a structure that sets the print job parameters.

All versions of Windows: pJob can point to a JOB_INFO_1 or JOB_INFO_2 structure.

Windows NT, Windows 2000, Windows XP, Windows Vista: pJob can also point to a JOB_INFO_3 structure. You must have JOB_ACCESS_ADMINISTER access permission for the jobs specified by the JobId and NextJobId members of the JOB_INFO_3 structure.

Windows Vista: pJob can also point to a JOB_INFO_4 structure.

If the Level parameter is 0, pJob should be NULL.

Windows 95, Windows 98, Windows Me: The function pays attention to this parameter only if the Command parameter is 0. If Command is nonzero, the function ignores this parameter and the Level parameter.
Command [in]

Specifies the print job operation to perform. This parameter can be one of the following values.
Value Meaning

JOB_CONTROL_CANCEL



Windows 95, Windows 98, Windows Me, Windows NT 3.51 and earlier: Delete the print job.

Windows NT 4.0 and later: Do not use. To delete a print job, use JOB_CONTROL_DELETE.

JOB_CONTROL_PAUSE



Pause the print job.

JOB_CONTROL_RESTART



Restart the print job. A job can only be restarted if it was printing.

JOB_CONTROL_RESUME



Resume a paused print job.

JOB_CONTROL_DELETE



Windows NT 4.0 and later: Delete the print job.

JOB_CONTROL_SENT_TO_PRINTER



Windows NT 4.0 and later: Used by port monitors to end the print job.

JOB_CONTROL_LAST_PAGE_EJECTED



Windows NT 4.0 and later: Used by language monitors to end the print job.

JOB_CONTROL_RETAIN



Windows Vista and later: Keep the job in the queue after it prints.

JOB_CONTROL_RELEASE



Windows Vista and later: Release the print job.



Windows 95, Windows 98, Windows Me: If you are using the SetJob function to set print job parameters, you must set the Command parameter to 0.

Windows NT, Windows 2000, Windows XP, Windows Vista: You can use the same call to the SetJob function to set print job parameters and to give a command to a print job. Thus, Command does not need to be 0 if you are setting print job parameters, although it can be.

Return Value

If the function succeeds, the return value is a nonzero value.

If the function fails, the return value is zero.
Remarks

You can use the SetJob function to set various print job parameters by supplying a pointer to a JOB_INFO_1, JOB_INFO_2, JOB_INFO_3, or JOB_INFO_4 structure that contains the necessary data.

Windows 95, Windows 98, Windows Me: When you use the function to set print job parameters, you must set the Command parameter to 0.

To remove or delete all of the print jobs for a particular printer, call the SetPrinter function with its Command parameter set to PRINTER_CONTROL_PURGE.

The following members of a JOB_INFO_1, JOB_INFO_2, or JOB_INFO_4 structure are ignored on a call to SetJob: JobId, pPrinterName, pMachineName, pUserName, pDrivername, Size, Submitted, Time, and TotalPages.

You must have PRINTER_ACCESS_ADMINISTER access permission for a printer in order to change a print job's position in the print queue.

If you do not want to set a print job's position in the print queue, you should set the Position member of the JOB_INFO_1, JOB_INFO_2, or JOB_INFO_4 structure to JOB_POSITION_UNSPECIFIED.

Windows NT, Windows 2000, Windows XP, Windows Vista: Use the SetJob function with the JOB_INFO_3 structure to link together a set of print jobs (also known as a chain). This is useful in situations where a single document consists of several parts that you want to render separately. To print jobs A, B, C, and D in order, call SetJob with JOB_INFO_4 to link A to B, B to C, and C to D.

If you link print jobs, note the following:

* Jobs can be added to the beginning or end of a chain.
* All jobs in the chain must have the same data type.
* The chain must be completely linked before spooling begins, otherwise the spooler may print and delete spooled jobs before you link them all. There are two ways to keep the chain from printing prematurely:

o Pause the first job in the chain until the chain is completely linked. The paused state of the first job governs the state of all jobs in the chain.
o Keep the first job incomplete, that is, do not call EndDoc or ScheduleJob for the first job. However, if 'print while spooling' is enabled (the default), this method blocks the port while the chain is built, which also prevents the printing of non-related jobs.
* The application must handle the case where the user deletes a job in the chain before the chain finishes printing. GetLastError returns INVALID_PARAMETER when a JobID does not exist.

Windows 95, Windows 98, Windows Me: SetJobW is supported by the Microsoft Layer for Unicode. To use this, you must add certain files to your application, as outlined in Microsoft Layer for Unicode on Windows 95/98/Me Systems.
skyxie 2009-06-23
  • 打赏
  • 举报
回复
You create and display a Print dialog box by initializing a PRINTDLG structure and passing the structure to the PrintDlg function.

PRINTDLG.nCopies

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

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