From 49a09415cdbbfa925a95e42115ef107aed7d0aa7 Mon Sep 17 00:00:00 2001 From: Pepa Rokos Date: Wed, 8 Mar 2017 14:43:53 +0100 Subject: [PATCH] Added POS printer support in Windows. --- shop/receiptgenerator.cpp | 46 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/shop/receiptgenerator.cpp b/shop/receiptgenerator.cpp index daeafa4..cd62dfd 100644 --- a/shop/receiptgenerator.cpp +++ b/shop/receiptgenerator.cpp @@ -5,6 +5,11 @@ #include #include +#ifdef _WIN32 +#include +#include +#endif + const QString ReceiptGenerator::DIACRITIC = "ÂâÁáÄäĂ㥹ĆćČčÇçĎďĐđÉéËëĚěĘęÍíÎîĹ弾ŁłŃńŇňÓóÖöÔôŐőŔŕŘřŚśŠšŞşŤťŢţÚúÜüŮůŰűÝýŹźŽžŻż"; const QString ReceiptGenerator::NON_DIACRITIC = "AaAaAaAaAaCcCcCcDdDdEeEeEeEeIiIiLlLlLlNnNnOoOoOoOoRrRrSsSsSsTtTtUuUuUuUuYyZzZzZz"; @@ -43,7 +48,48 @@ void ReceiptGenerator::save() void ReceiptGenerator::print() { +#ifdef _WIN32 + SettingsService srvShopSettings("SHOP"); + ShopSettingsPtr shopSettings = srvShopSettings.loadSettings(); + QString printer = shopSettings->output(); + + HANDLE hPrinter; + DOC_INFO_1 docInfo; + DWORD dwJob; + DWORD dwBytes; + BOOL bStatus = FALSE; + + if (OpenPrinter((LPWSTR)printer.toStdWString().c_str(), &hPrinter, NULL)) + { + docInfo.pDocName = L"Uctenka"; + docInfo.pOutputFile = NULL; + docInfo.pDatatype = L"RAW"; + + dwJob = StartDocPrinter(hPrinter, 1, (LPBYTE)&docInfo); + if (dwJob > 0) + { + if (!StartPagePrinter(hPrinter)) + { + ClosePrinter(hPrinter); + return; + } + QByteArray data = generate(); + BOOL bPrinted = WritePrinter(hPrinter, (LPBYTE)data.data(), data.length(), &dwBytes); + EndPagePrinter(hPrinter); + EndDocPrinter(hPrinter); + + if (!bPrinted) + { + DWORD dwErr = GetLastError(); + int i = 1; + } + } + } + + ClosePrinter(hPrinter); +#else save(); +#endif } QString ReceiptGenerator::outputFile() const