如何判断打印机的状态??

ppkele 2010-04-18 10:33:09
在一个对话框中,当点击打印按钮之后,弹出标准打印对话框,然后进行打印,主要代码如下:
void CMyDialog::OnBnClickPrint()
{
CDC pDc;
CPrintDialog dlg(FALSE); //标准打印对话框
if( IDOK == dlg.DoModal() )
{
pDc.Attrack(dlg.GetPrintDC());
}
pDc.Textout(100,100,"Hellow World!");
pDc.DeleteDc();
}
怎样判断打印机的一些状态(例如:打印机没开、缺纸等),然后给用户一些提示?
刚刚接触打印这一块,希望大家帮帮我,谢谢了!!
...全文
244 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ppkele 2010-05-11
  • 打赏
  • 举报
回复
虽然没有满意答案,还是结贴吧!
踏实每一步 2010-04-23
  • 打赏
  • 举报
回复
GetPrinter
The GetPrinter function retrieves information about a specified printer.

BOOL GetPrinter(
HANDLE hPrinter, // handle to printer
DWORD Level, // information level
LPBYTE pPrinter, // printer information buffer
DWORD cbBuf, // size of buffer
LPDWORD pcbNeeded // bytes received or required
);
Parameters
hPrinter
[in] Handle to the printer for which the function retrieves information. Use the OpenPrinter or AddPrinter function to retrieve a printer handle.
Level
[in] Specifies the level or type of structure that the function stores into the buffer pointed to by pPrinter.
Windows 95/98/Me: This value can be 1, 2, or 5.

Windows NT/2000/XP: This value can be 1, 2, 3, 4, 5, 6, 7, 8 or 9.

pPrinter
[out] Pointer to a buffer that receives a structure containing information about the specified printer. The buffer must be large enough to receive the structure and any strings or other data to which the structure members point. If the buffer is too small, the pcbNeeded parameter returns the required buffer size.
The type of structure is determined by the value of Level. Level Structure
1 A PRINTER_INFO_1 structure containing general printer information.
2 A PRINTER_INFO_2 structure containing detailed information about the printer.
3 Windows NT/2000/XP: A PRINTER_INFO_3 structure containing the printer's security information.
4 Windows NT/2000/XP: A PRINTER_INFO_4 structure containing minimal printer information, including the name of the printer, the name of the server, and whether the printer is remote or local.
5 A PRINTER_INFO_5 structure containing printer information such as printer attributes and time-out settings.
6 Windows 2000/XP: A PRINTER_INFO_6 structure specifying the status value of a printer.
7 Windows 2000/XP: A PRINTER_INFO_7 structure that indicates whether the printer is published in the directory service.
8 Windows 2000/XP: A PRINTER_INFO_8 structure specifying the global default printer settings.
9 Windows 2000/XP: A PRINTER_INFO_9 structure specifying the per-user default printer settings.



cbBuf
[in] Specifies the size, in bytes, of the buffer pointed to by pPrinter.
pcbNeeded
[out] 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 in the buffer.
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.

ppkele 2010-04-23
  • 打赏
  • 举报
回复
请大家多帮帮我,解决了可以加分。。。。
iccke1 2010-04-19
  • 打赏
  • 举报
回复
MFC下没找到相应的东西
iccke1 2010-04-19
  • 打赏
  • 举报
回复
有人写的然后编写获取打印机状态的函数如下:

/// <summary>
/// 获取打印机的当前状态
/// </summary>
/// <param name="PrinterDevice">打印机设备名称</param>
/// <returns>打印机状态</returns>
private PrinterStatus GetPrinterStat(string PrinterDevice)
{
PrinterStatus ret=0;
string path=@"win32_printer.DeviceId='"+PrinterDevice+"'";
ManagementObject printer=new ManagementObject(path);
printer.Get();
ret=(PrinterStatus)Convert.ToInt32(printer.Properties["PrinterStatus"].Value);
return ret;
}

调用示例:

MessageBox.Show(GetPrinterStat("\\\\192.168.0.88\\Samsung SCX-4x16 Series").ToString());

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=352678

补充:System.Windows.Forms.MessageBox.Show(printer.Properties["WorkOffline"].Value.ToString());

可以获取打印机是否离线.
没测试过

16,472

社区成员

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

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

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