网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
01月31日漏签0天
c++吧 关注:651,459贴子:2,117,900
  • 看贴

  • 图片

  • 吧主推荐

  • 游戏

  • 2回复贴,共1页
<<返回c++吧
>0< 加载中...

打印功能求助

  • 只看楼主
  • 收藏

  • 回复
  • zbrying
  • ,
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
最近在学习C++,在打印这碰到点问题,求大佬帮审审代码,看问题出在哪。
我想在程序中调用打印机打印一段文字,但是连接打印机后运行程序,打印机的准备灯会一闪一闪的,但是并不真正打印。已排除打印机本身问题。楼下上代码


  • zbrying
  • ,
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include <iostream>
#include <windows.h>
#include <string>
#include <tchar.h>
using namespace std;
#define PRINTER_NAME "Samsung SCX-3400 Series"
// 程序的主函数
int main_bak()
{
string hello = "!!! Hello Printer !!!\f";
HANDLE hPrinter = NULL;
DOC_INFO_1 DocInfo;
DWORD dwJob;
DWORD dwBytesWritten = 0L;
if (OpenPrinter((LPTSTR)_T(PRINTER_NAME), &hPrinter, NULL)) {
cout << "printer opened" << endl;
DocInfo.pDocName = (LPTSTR)_T("My Document");
DocInfo.pOutputFile = NULL;
DocInfo.pDatatype = (LPTSTR)_T("RAW");
dwJob = StartDocPrinter(hPrinter, 1, (LPBYTE)&DocInfo);
if (dwJob != 0) {
cout << "Print job open" << endl;
if (StartPagePrinter(hPrinter)) {
cout << "Page started" << endl;
// Send the data to the printer.
if (WritePrinter(hPrinter, (void*)hello.c_str(), hello.length(), &dwBytesWritten)) {
if (dwBytesWritten == hello.length()) { cout << "Message sent to printer" << endl; }
}
cout << "Page Closed" << endl;
}
// Inform the spooler that the document is ending.
EndDocPrinter(hPrinter);
cout << "Print job open" << endl;
}
else {
cout << "Could not create print job" << endl;
}
// Close the printer handle.
ClosePrinter(hPrinter);
cout << "printer closed" << endl;
}
else {
cout << "Could not open Printer" << endl;
}
cout << "done";
//-----------------------------------------------
return 0;
}


2026-01-31 20:33:23
广告
不感兴趣
开通SVIP免广告
  • zbrying
  • ,
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
回复一下嘛,如果我这个打印方式不对,给我个别的例子也行,要积分的也可以啊


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 2回复贴,共1页
<<返回c++吧
分享到:
©2026 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示