forked from Discriminator/PDW
-
Notifications
You must be signed in to change notification settings - Fork 0
/
printer.cpp
165 lines (142 loc) · 3.28 KB
/
printer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
//
// Printer.cpp
//
#include <windows.h>
#include <commctrl.h>
#include <mmsystem.h>
#include <stdio.h>
#include <commdlg.h>
#include <string.h>
#include <time.h>
#include "headers\resource.h"
#include "headers\PDW.h"
#include "headers\slicer.h"
#include "headers\toolbar.h"
#include "headers\gfx.h"
#include "headers\initapp.h"
#include "headers\sigind.h"
#include "headers\decode.h"
#include "headers\sound_in.h"
#include "headers\printer.h"
PRINTDLG printdlg;
DOCINFO docinfo;
int printOK = 1;
HWND PrtCancel_hDlg = NULL;
// Print out buffer,
// Seperate each line if '\n' is detected.
//
void PrintBuffer(LPSTR lpBuffer)
{
TEXTMETRIC tm;
LPSTR s;
int i, copies;
int prtX = 0; // current X output location
int prtY = 0; // current Y output location
/* initialize PRINTDLG struct */
PrintInit(&printdlg, ghWnd);
if (!PrintDlg(&printdlg)) return;
docinfo.cbSize = sizeof(DOCINFO);
docinfo.lpszDocName = "Print...";
docinfo.lpszOutput = NULL;
docinfo.lpszDatatype = NULL;
docinfo.fwType = 0;
StartDoc(printdlg.hDC, &docinfo);
/* get text metrics for printer */
GetTextMetrics(printdlg.hDC, &tm);
printOK = 1;
SetAbortProc(printdlg.hDC, (ABORTPROC) AbortFunc);
PrtCancel_hDlg = CreateDialog(ghInstance, "PrCancel", ghWnd, (DLGPROC) KillPrint);
for (copies=0; copies<printdlg.nCopies; copies++)
{
StartPage(printdlg.hDC);
prtX = 0;
prtY = 0;
i=0;
s = lpBuffer;
while (((*s) && (i < 15000)))
{
if (*s == '\n')
{
prtX = 0;
prtY += tm.tmHeight + tm.tmExternalLeading;
s++;
continue;
}
if (((*s != ' ') && ((*s < 0x21) || (*s > 0x7E))))
{
s++;
continue;
}
TextOut(printdlg.hDC, prtX, prtY,(LPSTR)s, 1);
prtX += tm.tmAveCharWidth + tm.tmExternalLeading;
s++;
i++;
}
EndPage(printdlg.hDC);
}
if (printOK)
{
if (PrtCancel_hDlg) DestroyWindow(PrtCancel_hDlg);
EndDoc(printdlg.hDC);
}
DeleteDC(printdlg.hDC);
}
/* Initialize PRINTDLG structure. */
void PrintInit(PRINTDLG *printdlg, HWND hwnd)
{
printdlg->lStructSize = sizeof(PRINTDLG);
printdlg->hwndOwner = hwnd;
printdlg->hDevMode = NULL;
printdlg->hDevNames = NULL;
printdlg->hDC = NULL;
printdlg->Flags = PD_RETURNDC | PD_NOSELECTION | PD_NOPAGENUMS | PD_HIDEPRINTTOFILE;
printdlg->nFromPage = 0;
printdlg->nToPage = 0;
printdlg->nMinPage = 0;
printdlg->nMaxPage = 0;
printdlg->nCopies = 1;
printdlg->hInstance = NULL;
printdlg->lCustData = 0;
printdlg->lpfnPrintHook = NULL;
printdlg->lpfnSetupHook = NULL;
printdlg->lpPrintTemplateName = NULL;
printdlg->lpSetupTemplateName = NULL;
printdlg->hPrintTemplate = NULL;
printdlg->hSetupTemplate = NULL;
}
/* Printer abort function. */
BOOL CALLBACK AbortFunc(HDC hdc, int err)
{
MSG message;
while (PeekMessage(&message, NULL, 0, 0, PM_REMOVE))
{
if (!IsDialogMessage(PrtCancel_hDlg, &message))
{
TranslateMessage(&message);
DispatchMessage(&message);
}
}
return printOK;
}
/* Let user kill print process. */
LRESULT CALLBACK KillPrint(HWND hdwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
CenterWindow(hdwnd);
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDCANCEL:
printOK = 0;
DestroyWindow(PrtCancel_hDlg);
PrtCancel_hDlg = NULL;
return 1;
}
break;
}
return 0;
}