#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;
}
#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;
}
