can9999
asked on
how to check printer status
How can I check printer status ?
The property Printer.Page Returns the current page being sent to the printer. (Since your app started, or the last time you sent Printer.EndDoc)
This assumes, of course, that you are printing using the printer object. If you use the API to print, this won't work.
This assumes, of course, that you are printing using the printer object. If you use the API to print, this won't work.
ASKER
Tward !
- I already tried it, but failed.(always return NULL)
- I don't how to get printer handle (I'd get it "printer.hdc")
clifABB !
- Sure, Printer.Page is .
- But I want to know the method which it is able to use
under printing with CrystalReport (.Action).
- I already tried it, but failed.(always return NULL)
- I don't how to get printer handle (I'd get it "printer.hdc")
clifABB !
- Sure, Printer.Page is .
- But I want to know the method which it is able to use
under printing with CrystalReport (.Action).
Sorry. I was assuming you were printing from VB.
Good luck.
Good luck.
The Crystal Reports ocx has a status property. Use a timer to occasionally poll this property to see if the printing has finished:
Private Sub Timer1_Timer()
If Report1.Status = 3 Then
g_bReportDone = True
ElseIf Report1.Status = 5 Then
g_bReportCanceled = True
Else
g_bReportDone = False
g_bReportCanceled = False
End If
End Sub
Private Sub Timer1_Timer()
If Report1.Status = 3 Then
g_bReportDone = True
ElseIf Report1.Status = 5 Then
g_bReportCanceled = True
Else
g_bReportDone = False
g_bReportCanceled = False
End If
End Sub
ASKER
Did you try it ?
I used "Action".
Status value is "3" when printing is on.
But It doesn't clear although printing is over. Alway "3".
Please, try it.
I used "Action".
Status value is "3" when printing is on.
But It doesn't clear although printing is over. Alway "3".
Please, try it.
When you call Report1.Action = 1, the Status property resets to 0, when the complete document has been sent to the printer the Status property will be set to 3. It will remain at 3 until you use Action = 1 again.
This property only measures the status of the document sent to the printer (usually a very short time depending on the number of pages and the amount of printer memory), not the actual printer actions (which can be as slow as 2-3 ppm).
This property only measures the status of the document sent to the printer (usually a very short time depending on the number of pages and the amount of printer memory), not the actual printer actions (which can be as slow as 2-3 ppm).
can9999,
If you are using VB5 (or an ealier version of VB with SpyWorks or similar subclassing control), you can trap for the WM_SPOOLERSTATUS message.
This message is sent to every top level window in the system whenever a print jpb is added or removed from the print queue, regardless of its source. It also will tell you the total number of jobs in the print queue.
Hope this helps!
zsi
If you are using VB5 (or an ealier version of VB with SpyWorks or similar subclassing control), you can trap for the WM_SPOOLERSTATUS message.
This message is sent to every top level window in the system whenever a print jpb is added or removed from the print queue, regardless of its source. It also will tell you the total number of jobs in the print queue.
Hope this helps!
zsi
ASKER
zsi !
How can I use "WM_SPOOLERSTATUS" ?
How can I use "WM_SPOOLERSTATUS" ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Public Const PRINTER_ATTRIBUTE_DEFAULT = &H4
Public Const PRINTER_ATTRIBUTE_DIRECT = &H2
Public Const PRINTER_ATTRIBUTE_ENABLE_B
Public Const PRINTER_ATTRIBUTE_HIDDEN = &H20
Public Const PRINTER_ATTRIBUTE_LOCAL = &H40
Public Const PRINTER_ATTRIBUTE_NETWORK = &H10
Public Const PRINTER_ATTRIBUTE_QUEUED = &H1
Public Const PRINTER_ATTRIBUTE_SHARED = &H8
Public Const PRINTER_ATTRIBUTE_WORK_OFF
Public Const PRINTER_STATUS_BUSY = &H200
Public Const PRINTER_STATUS_DOOR_OPEN = &H400000
Public Const PRINTER_STATUS_ERROR = &H2
Public Const PRINTER_STATUS_INITIALIZIN
Public Const PRINTER_STATUS_IO_ACTIVE = &H100
Public Const PRINTER_STATUS_MANUAL_FEED
Public Const PRINTER_STATUS_NO_TONER = &H40000
Public Const PRINTER_STATUS_NOT_AVAILAB
Public Const PRINTER_STATUS_OFFLINE = &H80
Public Const PRINTER_STATUS_OUT_OF_MEMO
Public Const PRINTER_STATUS_OUTPUT_BIN_
Public Const PRINTER_STATUS_PAGE_PUNT = &H80000
Public Const PRINTER_STATUS_PAPER_JAM = &H8
Public Const PRINTER_STATUS_PAPER_OUT = &H10
Public Const PRINTER_STATUS_PAPER_PROBL
Public Const PRINTER_STATUS_PAUSED = &H1
Public Const PRINTER_STATUS_PENDING_DEL
Public Const PRINTER_STATUS_PRINTING = &H400
Public Const PRINTER_STATUS_PROCESSING = &H4000
Public Const PRINTER_STATUS_TONER_LOW = &H20000
Public Const PRINTER_STATUS_USER_INTERV
Public Const PRINTER_STATUS_WAITING = &H2000
Public Const PRINTER_STATUS_WARMING_UP = &H10000
Type PRINTER_INFO_1
flags As Long
pDescription As String
pName As String
pComment As String
End Type
Type PRINTER_INFO_2
pServerName As String
pPrinterName As String
pShareName As String
pPortName As String
pDriverName As String
pComment As String
pLocation As String
pDevMode As DEVMODE
pSepFile As String
pPrintProcessor As String
pDatatype As String
pParameters As String
pSecurityDescriptor As SECURITY_DESCRIPTOR
Attributes As Long
Priority As Long
DefaultPriority As Long
StartTime As Long
UntilTime As Long
Status As Long
cJobs As Long
AveragePPM As Long
End Type
Type PRINTER_INFO_5
pPrinterName As String
pPortName As String
Attributes As Long
DeviceNotSelectedTimeout As Long
TransmissionRetryTimeout As Long
End Type
Declare Function GetPrinter Lib "winspool" Alias "GetPrinterA" (ByVal hPrinter As Long, ByVal Level As Long, pPrinter As Byte, ByVal cbBuf As Long, pcbNeeded As Long) As Boolean
C Explanation of GetPrinter:
The GetPrinter function retrieves information about a specified printer.
BOOL GetPrinter(
HANDLE hPrinter, // handle to printer of interest
DWORD Level, // version of printer info data structure
LPBYTE pPrinter, // pointer to array of bytes that receives printer info. structure
DWORD cbBuf, // size, in bytes, of array of bytes
LPDWORD pcbNeeded // pointer to variable with count of bytes retrieved (or required)
);
Parameters
hPrinter
Handle to the printer of interest.
Level
Specifies the level, or type, of PRINTER_INFO_* structure that the function stores into the buffer pointed to by pPrinter.
Windows 95: This value can be 1, 2, or 5.
Windows NT: This value can be 1, 2, 3, 4, or 5.
pPrinter
Pointer to a buffer that receives a PRINTER_INFO_* structure. This structure contains information about the specified printer. The type of structure is determined by the value of Level.
Windows 95: The buffer can receive a PRINTER_INFO_1, PRINTER_INFO_2, PRINTER_INFO_5 structure.
Windows NT: The buffer can receive a PRINTER_INFO_1, PRINTER_INFO_2, PRINTER_INFO_3, PRINTER_INFO_4, or PRINTER_INFO_5 structure.
cbBuf
Specifies the size, in bytes, of the buffer pointed to by pPrinter.
pcbNeeded
Pointer to a variable that the function sets to the size in bytes of the printer information. If cbBuf is smaller than this value, GetPrinter fails, and the value represents the required buffer size. If cbBuf is equal to or greater than this value, GetPrinter succeeds, and the value represents the number of bytes stored into the buffer.
Return Values
If the function succeeds, the return value is TRUE.
If the function fails, the return value is FALSE. To get extended error information, call GetLastError.
Remarks
If the structure returned in the buffer pointed to by the pPrinter parameter contains a pointer to a security descriptor, only those components of the security descriptor that the caller has permission to read will be present. An application that wants to retrieve particular security descriptor components must open the printer with sufficient access permission. The following table shows the security descriptor components that are retrieved for particular access permission values:
Access Permission Security Descriptor Components Retrieved
READ_CONTROL Owner, Primary Group, Discretionary access-control list (ACL)
ACCESS_SYSTEM_SECURITY System ACL
See Also
AbortPrinter, AddPrinter, ClosePrinter, DeletePrinter, EnumPrinters, PRINTER_INFO_1, PRINTER_INFO_2, PRINTER_INFO_3, PRINTER_INFO_4, PRINTER_INFO_5, OpenPrinter, SetPrinter
The PRINTER_INFO_1 structure specifies general printer information.
typedef struct _PRINTER_INFO_1 { // pri1
DWORD Flags;
LPTSTR pDescription;
LPTSTR pName;
LPTSTR pComment;
} PRINTER_INFO_1;
Members
Flags
Specifies information about the returned data. Following are the values for this member
Value Meaning
PRINTER_ENUM_EXPAND A print provider can set this flag as a hint to a calling application to enumerate this object further if default expansion is enabled. For example, when domains are enumerated, a print provider might indicate the user's domain by setting this flag.
PRINTER_ENUM_CONTAINER If this flag is set, the printer object may contain enumerable objects. For example, the object may be a print server that contains printers.
PRINTER_ENUM_ICON1 Indicates that, where appropriate, an application should display an icon identifying the object as a top-level network name, such as Microsoft Windows Network.
PRINTER_ENUM_ICON2 Indicates that, where appropriate, an application should display an icon that identifies the object as a network domain.
PRINTER_ENUM_ICON3 Indicates that, where appropriate, an application should display an icon that identifies the object as a print server.
PRINTER_ENUM_ICON4 Reserved for future use.
PRINTER_ENUM_ICON5 Reserved for future use.
PRINTER_ENUM_ICON6 Reserved for future use.
PRINTER_ENUM_ICON7 Reserved for future use.
PRINTER_ENUM_ICON8 Indicates that, where appropriate, an application should display an icon that identifies the object as a printer.
pDescription
Windows NT: Points to a null-terminated string that describes the contents of the structure.
Windows 95: Points to a null-terminated string that describes the printer. The string contains the pPrinterName, pDriverName, and pComment members of the PRINTER_INFO_2 structure concatenated and separated by commas.
pName
Windows NT: Points to a null-terminated string that names the contents of the structure.
Windows 95: Points to a null-terminated string that specifies the name of the printer.
pComment
Windows NT: Points to a null-terminated string that contains additional data describing the structure.
Windows 95: Points to a null-terminated string that provides a brief description of the printer.
See Also
GetPrinter, EnumPrinters, PRINTER_INFO_2, PRINTER_INFO_3, PRINTER_INFO_4
The PRINTER_INFO_2 structure specifies detailed printer information.
typedef struct _PRINTER_INFO_2 { // pri2
LPTSTR pServerName;
LPTSTR pPrinterName;
LPTSTR pShareName;
LPTSTR pPortName;
LPTSTR pDriverName;
LPTSTR pComment;
LPTSTR pLocation;
LPDEVMODE pDevMode;
LPTSTR pSepFile;
LPTSTR pPrintProcessor;
LPTSTR pDatatype;
LPTSTR pParameters;
PSECURITY_DESCRIPTOR pSecurityDescriptor;
DWORD Attributes;
DWORD Priority;
DWORD DefaultPriority;
DWORD StartTime;
DWORD UntilTime;
DWORD Status;
DWORD cJobs;
DWORD AveragePPM;
} PRINTER_INFO_2;
Members
pServerName
Points to a null-terminated string identifying the server that controls the printer. If this string is NULL, the printer is controlled locally.
pPrinterName
Points to a null-terminated string that specifies the name of the printer.
pShareName
Points to a null-terminated string that identifies the sharepoint for the printer. (This string is used only if the PRINTER_ATTRIBUTE_SHARED constant was set for the Attributes member.)
pPortName
Points to a null-terminated string that identifies the port(s) used to transmit data to the printer. If a printer is connected to more than one port, the names of each port must be separated by commas (for example, "LPT1:,LPT2:,LPT3:").
pDriverName
Points to a null-terminated string that specifies the name of the printer driver.
pComment
Points to a null-terminated string that provides a brief description of the printer.
pLocation
Points to a null-terminated string that specifies the physical location of the printer (for example, "Bldg. 38, Room 1164").
pDevMode
Points to a DEVMODE structure that defines default printer data such as the paper orientation and the resolution.
pSepFile
Points to a null-terminated string that specifies the name of the file used to create the separator page. This page is used to separate print jobs sent to the printer.
pPrintProcessor
Points to a null-terminated string that specifies the name of the print processor used by the printer.
pDatatype
Points to a null-terminated string that specifies the data type used to record the print job.
pParameters
Points to a null-terminated string that specifies the default print-processor parameters.
pSecurityDescriptor
Points to a SECURITY_DESCRIPTOR structure for the printer. This member may be NULL.
Attributes
Specifies the printer attributes. This member can be one of the following values:
PRINTER_ATTRIBUTE_DEFAULT
PRINTER_ATTRIBUTE_DIRECT
PRINTER_ATTRIBUTE_DO_COMPL
PRINTER_ATTRIBUTE_ENABLE_B
PRINTER_ATTRIBUTE_ENABLE_D
PRINTER_ATTRIBUTE_KEEPPRIN
PRINTER_ATTRIBUTE_QUEUED
PRINTER_ATTRIBUTE_SHARED
PRINTER_ATTRIBUTE_WORK_OFF
Priority
Specifies a priority value that the spooler uses to route print jobs.
DefaultPriority
Specifies the default priority value assigned to each print job.
StartTime
Specifies the earliest time at which the printer will print a job. This value is expressed as minutes elapsed since 12:00 A.M. GMT (Greenwich Mean Time).
UntilTime
Specifies the latest time at which the printer will print a job. This value is expressed as minutes elapsed since 12:00 A.M. GMT (Greenwich Mean Time).
Status
Specifies the printer status. This member can be one of the following values:
Windows NT:
PRINTER_STATUS_PAUSED
PRINTER_STATUS_PENDING_DEL
Windows 95:
PRINTER_STATUS_BUSY
PRINTER_STATUS_DOOR_OPEN
PRINTER_STATUS_ERROR
PRINTER_STATUS_INITIALIZIN
PRINTER_STATUS_IO_ACTIVE
PRINTER_STATUS_MANUAL_FEED
PRINTER_STATUS_NO_TONER
PRINTER_STATUS_NOT_AVAILAB
PRINTER_STATUS_OFFLINE
PRINTER_STATUS_OUT_OF_MEMO
PRINTER_STATUS_OUTPUT_BIN_
PRINTER_STATUS_PAGE_PUNT
PRINTER_STATUS_PAPER_JAM
PRINTER_STATUS_PAPER_OUT
PRINTER_STATUS_PAPER_PROBL
PRINTER_STATUS_PAUSED
PRINTER_STATUS_PENDING_DEL
PRINTER_STATUS_PRINTING
PRINTER_STATUS_PROCESSING
PRINTER_STATUS_TONER_LOW
PRINTER_STATUS_UNAVAILABLE
PRINTER_STATUS_USER_INTERV
PRINTER_STATUS_WAITING
PRINTER_STATUS_WARMING_UP
cJobs
Specifies the number of print jobs that have been queued for the printer.
AveragePPM
Specifies the average number of pages per minute that have been printed on the printer.
Remarks
Windows 95: The PRINTER_STATUS_PAGE_PUNT value specifies that the page is being "punted" (that is, not printed) because it is too complex for the printer to print.
See Also
DEVMODE, EnumPrinters, PRINTER_INFO_1, PRINTER_INFO_3, PRINTER_INFO_4, SECURITY_DESCRIPTOR
The PRINTER_INFO_5 structure specifies detailed printer information.
typedef struct _PRINTER_INFO_5 { // pri5
LPTSTR pPrinterName;
LPTSTR pPortName;
DWORD Attributes;
DWORD DeviceNotSelectedTimeout;
DWORD TransmissionRetryTimeout;
} PRINTER_INFO_5;
Members
pPrinterName
Pointer to a null-terminated string that specifies the name of the printer.
pPortName
Pointer to a null-terminated string that identifies the port(s) used to transmit data to the printer. If a printer is connected to more than one port, the names of each port must be separated by commas (for example, "LPT1:,LPT2:,LPT3:").
Attributes
Specifies the printer attributes. This member can be one of the following values:
PRINTER_ATTRIBUTE_QUEUED
PRINTER_ATTRIBUTE_DIRECT
PRINTER_ATTRIBUTE_DEFAULT
PRINTER_ATTRIBUTE_SHARED
PRINTER_ATTRIBUTE_WORK_OFF
DeviceNotSelectedTimeout
Windows 95: Specifies the maximum time, in milliseconds, allowed to elapse between attempts to select a device.
Windows NT: This value is not used.
TransmissionRetryTimeout
Windows 95: Specifies the maximum time, in milliseconds, allowed to elapse between transmission retries.
Windows NT: This value is not used.
See Also
EnumPrinters, GetPrinter, SetPrinter, PRINTER_INFO_1, PRINTER_INFO_2, PRINTER_INFO_3, PRINTER_INFO_4