主题:关于监视打印的问题!!!
hdr447017532
[专家分:400] 发布于 2008-03-11 16:09:00
各位大侠,小弟我想写一个监视打印机的程序,主要是用来记录打印机所打印的各种文档的信息等内容,具体如何实现只知道大概用到[color=FF0000]FindFirstPrinterChangeNotification[/color]和[color=FF0000]FindNextPrinterChangeNotification[/color],但是这两个函数中的参数什么的怎么设置都不清楚[em18],因此都没有办法成功取得信息。还希望各位有什么好的建议或者例子拿出来分享下。[em11][em11]
回复列表 (共3个回复)
沙发
f-wind [专家分:1240] 发布于 2008-03-14 16:52:00
HANDLE FindFirstPrinterChangeNotification(
HANDLE hPrinter, // handle to printer
DWORD fdwFlags, // conditions to monitor
DWORD fdwOptions, // reserved, must be zero
LPVOID pPrinterNotifyOptions // fields to monitor
);
Parameters
hPrinter
[in] Handle to the printer or print server that you want to monitor. Use the OpenPrinter or AddPrinter function to retrieve a printer handle.
fdwFlags
[in] Specify the conditions that will cause the change notification object to enter a signaled state. A change notification occurs when one or more of the specified conditions are met. The fdwFlags parameter can be zero if pPrinterNotifyOptions is non-NULL.
This parameter can be one or more of the following values. Value Meaning
PRINTER_CHANGE_FORM Notify of any changes to a form. You can set this general flag or one or more of the following specific flags:
PRINTER_CHANGE_ADD_FORM PRINTER_CHANGE_SET_FORM PRINTER_CHANGE_DELETE_FORM
PRINTER_CHANGE_JOB Notify of any changes to a job. You can set this general flag or one or more of the following specific flags:
PRINTER_CHANGE_ADD_JOB PRINTER_CHANGE_SET_JOB PRINTER_CHANGE_DELETE_JOB PRINTER_CHANGE_WRITE_JOB
PRINTER_CHANGE_PORT Notify of any changes to a port. You can set this general flag or one or more of the following specific flags:
PRINTER_CHANGE_ADD_PORT PRINTER_CHANGE_CONFIGURE_PORT PRINTER_CHANGE_DELETE_PORT
PRINTER_CHANGE_PRINT_PROCESSOR Notify of any changes to a print processor. You can set this general flag or one or more of the following specific flags: PRINTER_CHANGE_ADD_PRINT_PROCESSOR PRINTER_CHANGE_DELETE_PRINT_PROCESSOR
PRINTER_CHANGE_PRINTER Notify of any changes to a printer. You can set this general flag or one or more of the following specific flags:
PRINTER_CHANGE_ADD_PRINTER PRINTER_CHANGE_SET_PRINTER PRINTER_CHANGE_DELETE_PRINTER PRINTER_CHANGE_FAILED_CONNECTION_PRINTER
PRINTER_CHANGE_PRINTER_DRIVER Notify of any changes to a printer driver. You can set this general flag or one or more of the following specific flags:
PRINTER_CHANGE_ADD_PRINTER_DRIVER PRINTER_CHANGE_SET_PRINTER_DRIVER PRINTER_CHANGE_DELETE_PRINTER_DRIVER
PRINTER_CHANGE_ALL Notify if any of the preceding changes occur.
For descriptions of the more specific flags in the preceding table, see the FindNextPrinterChangeNotification function.
fdwOptions
Reserved; must be zero.
pPrinterNotifyOptions
[in] Pointer to a PRINTER_NOTIFY_OPTIONS structure. The pTypes member of this structure is an array of one or more PRINTER_NOTIFY_OPTIONS_TYPE structures, each of which specifies a printer information field to monitor. A change notification occurs when one or more of the specified fields changes. When a change occurs, the FindNextPrinterChangeNotification function can retrieve the new printer information. This parameter can be NULL if fdwFlags is nonzero.
For a list of fields that can be monitored, see PRINTER_NOTIFY_OPTIONS_TYPE.
Return Values
If the function succeeds, the return value is a handle to a change notification object associated with the specified printer or print server.
If the function fails, the return value is INVALID_HANDLE_VALUE. To get extended error information, call GetLastError.
板凳
f-wind [专家分:1240] 发布于 2008-03-14 16:53:00
BOOL FindNextPrinterChangeNotification(
HANDLE hChange, // change notification
PDWORD pdwChange, // condition that changed
LPVOID pPrinterNotifyOptions, // refresh option
LPVOID *ppPrinterNotifyInfo // printer information
);
Parameters
hChange
[in] Handle to a change notification object associated with a printer or print server. You obtain such a handle by calling the FindFirstPrinterChangeNotification function. The operating system sets this change notification object to the signaled state when it detects one of the changes specified in the object's change notification filter.
pdwChange
[out] Pointer to a variable whose bits are set to indicate the changes that occurred to cause the most recent notification. The bit flags that might be set correspond to those specified in the fdwFlags parameter of the FindFirstPrinterChangeNotification call. The system sets one or more of the following bit flags. Value Meaning
PRINTER_CHANGE_ADD_FORM A form was added to the server.
PRINTER_CHANGE_ADD_JOB A print job was sent to the printer.
PRINTER_CHANGE_ADD_PORT A port or monitor was added to the server.
PRINTER_CHANGE_ADD_PRINT_PROCESSOR A print processor was added to the server.
PRINTER_CHANGE_ADD_PRINTER A printer was added to the server.
PRINTER_CHANGE_ADD_PRINTER_DRIVER A printer driver was added to the server.
PRINTER_CHANGE_CONFIGURE_PORT A port was configured on the server.
PRINTER_CHANGE_DELETE_FORM A form was deleted from the server.
PRINTER_CHANGE_DELETE_JOB A job was deleted.
PRINTER_CHANGE_DELETE_PORT A port or monitor was deleted from the server.
PRINTER_CHANGE_DELETE_PRINT_PROCESSOR A print processor was deleted from the server.
PRINTER_CHANGE_DELETE_PRINTER A printer was deleted.
PRINTER_CHANGE_DELETE_PRINTER_DRIVER A printer driver was deleted from the server.
PRINTER_CHANGE_FAILED_CONNECTION_PRINTER A printer connection has failed.
PRINTER_CHANGE_SET_FORM A form was set on the server.
PRINTER_CHANGE_SET_JOB A job was set.
PRINTER_CHANGE_SET_PRINTER A printer was set.
PRINTER_CHANGE_SET_PRINTER_DRIVER A printer driver was set.
PRINTER_CHANGE_WRITE_JOB Job data was written.
PRINTER_CHANGE_TIMEOUT The job timed out.
pPrinterNotifyOptions
[in] Pointer to a PRINTER_NOTIFY_OPTIONS structure. Set the Flags member of this structure to PRINTER_NOTIFY_OPTIONS_REFRESH, to cause the function to return the current data for all monitored printer information fields. The function ignores all other members of the structure. This parameter can be NULL.
ppPrinterNotifyInfo
[out] Pointer to a pointer variable that receives a pointer to a system-allocated, read-only buffer. Call the FreePrinterNotifyInfo function to free the buffer when you are finished with it. This parameter can be NULL if no information is required.
The buffer contains a PRINTER_NOTIFY_INFO structure, which contains an array of PRINTER_NOTIFY_INFO_DATA structures. Each element of the array contains information about one of the fields specified in the pPrinterNotifyOptions parameter of the FindFirstPrinterChangeNotification call. Typically, the function provides data only for the fields that changed to cause the most recent notification. However, if the structure pointed to by the pPrinterNotifyOptions parameter specifies PRINTER_NOTIFY_OPTIONS_REFRESH, the function provides data for all monitored fields.
If the PRINTER_NOTIFY_INFO_DISCARDED bit is set in the Flags member of the PRINTER_NOTIFY_INFO structure, an overflow or error occurred, and notifications may have been lost. In this case, no additional notifications will be sent until you make a second FindNextPrinterChangeNotification call that specifies PRINTER_NOTIFY_OPTIONS_REFRESH.
Return Values
If the function succeeds, the return value is a nonzero value.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
3 楼
hdr447017532 [专家分:400] 发布于 2008-03-26 15:39:00
多谢拉,事实证明这个还是能用的
我来回复