Develop and Download Open Source Software

Browse Subversion Repository

Annotation of /trunk/teraterm/teraterm/teraprn.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8331 - (hide annotations) (download) (as text)
Fri Oct 25 15:01:20 2019 UTC (4 years, 5 months ago) by yutakapon
File MIME type: text/x-c++src
File size: 16232 byte(s)
一部のWindowsバージョンで、印刷ダイアログにヘルプボタンが表示されないことがある問題を修正した。
1 doda 6806 /*
2     * Copyright (C) 1994-1998 T. Teranishi
3     * (C) 2007-2017 TeraTerm Project
4     * All rights reserved.
5     *
6 doda 6841 * Redistribution and use in source and binary forms, with or without
7     * modification, are permitted provided that the following conditions
8     * are met:
9 doda 6806 *
10 doda 6841 * 1. Redistributions of source code must retain the above copyright
11     * notice, this list of conditions and the following disclaimer.
12     * 2. Redistributions in binary form must reproduce the above copyright
13     * notice, this list of conditions and the following disclaimer in the
14     * documentation and/or other materials provided with the distribution.
15     * 3. The name of the author may not be used to endorse or promote products
16     * derived from this software without specific prior written permission.
17 doda 6806 *
18 doda 6841 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
19     * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20     * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21     * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
22     * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23     * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24     * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25     * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26     * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27     * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 doda 6806 */
29 maya 3227
30     /* TERATERM.EXE, Printing routines */
31     #include "teraterm.h"
32     #include "tttypes.h"
33     #include <commdlg.h>
34     #include <stdio.h>
35 zmatsuo 7936 #include <crtdbg.h>
36 maya 3227
37     #include "ttwinman.h"
38     #include "commlib.h"
39     #include "ttcommon.h"
40     #include "ttlib.h"
41 zmatsuo 7290 #include "win16api.h"
42 maya 3227
43     #include "tt_res.h"
44 zmatsuo 7528 #include "tmfc.h"
45 maya 3227 #include "prnabort.h"
46    
47     #include "teraprn.h"
48    
49 zmatsuo 7936 #ifdef _DEBUG
50     #if defined(_MSC_VER)
51     #define new ::new(_NORMAL_BLOCK, __FILE__, __LINE__)
52 maya 3227 #endif
53 zmatsuo 7936 #endif
54 maya 3227
55     static PRINTDLG PrnDlg;
56    
57     static HDC PrintDC;
58 zmatsuo 7527 static LOGFONTA Prnlf;
59 maya 3227 static HFONT PrnFont[AttrFontMask+1];
60     static int PrnFW, PrnFH;
61     static RECT Margin;
62     static COLORREF White, Black;
63     static int PrnX, PrnY;
64     static int PrnDx[256];
65     static TCharAttr PrnAttr;
66    
67     static BOOL Printing = FALSE;
68     static BOOL PrintAbortFlag = FALSE;
69    
70     /* pass-thru printing */
71 maya 4031 static char PrnFName[MAX_PATH];
72 zmatsuo 7290 static HANDLE HPrnFile = INVALID_HANDLE_VALUE;
73 maya 3227 static char PrnBuff[TermWidthMax];
74     static int PrnBuffCount = 0;
75    
76     static CPrnAbortDlg *PrnAbortDlg;
77     static HWND HPrnAbortDlg;
78    
79     /* Print Abortion Call Back Function */
80 zmatsuo 7933 static BOOL CALLBACK PrnAbortProc(HDC PDC, int Code)
81 maya 3227 {
82 maya 3392 MSG m;
83 maya 3227
84 maya 3392 while ((! PrintAbortFlag) && PeekMessage(&m, 0,0,0, PM_REMOVE))
85     if ((HPrnAbortDlg==NULL) || (! IsDialogMessage(HPrnAbortDlg, &m))) {
86     TranslateMessage(&m);
87     DispatchMessage(&m);
88     }
89 maya 3227
90 maya 3392 if (PrintAbortFlag) {
91     HPrnAbortDlg = NULL;
92     PrnAbortDlg = NULL;
93     return FALSE;
94     }
95     else {
96     return TRUE;
97     }
98 maya 3227 }
99    
100 yutakapon 8331 static UINT_PTR CALLBACK PrintHookProc(HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam)
101     {
102     return 0;
103     }
104    
105 maya 3227 HDC PrnBox(HWND HWin, PBOOL Sel)
106     {
107 maya 3392 /* initialize PrnDlg record */
108     memset(&PrnDlg, 0, sizeof(PRINTDLG));
109     PrnDlg.lStructSize = sizeof(PRINTDLG);
110     PrnDlg.hwndOwner = HWin;
111 yutakapon 8331 PrnDlg.Flags = PD_RETURNDC | PD_NOPAGENUMS | PD_SHOWHELP | PD_ENABLEPRINTHOOK;
112 maya 3392 if (! *Sel) {
113 yutakapon 5196 PrnDlg.Flags = PrnDlg.Flags | PD_NOSELECTION; /* when there is nothing select, gray out the "Selection" radio button */
114     } else {
115     PrnDlg.Flags = PrnDlg.Flags | PD_SELECTION; /* when there is something select, select the "Selection" radio button by default */
116 maya 3392 }
117     PrnDlg.nCopies = 1;
118 yutakapon 8331 /*
119     * Windows NT�n���������A�����_�C�A���O���w���v�{�^�����\�����������A
120     * �v���V�[�W�����t�b�N�����B
121     */
122     PrnDlg.lpfnPrintHook = PrintHookProc;
123 maya 3227
124 maya 3392 /* 'Print' dialog box */
125     if (! PrintDlg(&PrnDlg)) {
126     return NULL; /* if 'Cancel' button clicked, exit */
127     }
128     if (PrnDlg.hDC == NULL) {
129     return NULL;
130     }
131     PrintDC = PrnDlg.hDC;
132     *Sel = (PrnDlg.Flags & PD_SELECTION) != 0;
133     return PrintDC;
134 maya 3227 }
135    
136     BOOL PrnStart(LPSTR DocumentName)
137     {
138 zmatsuo 7527 DOCINFOA Doc;
139 maya 3392 char DocName[50];
140 zmatsuo 7933 HWND hParent;
141 maya 3227
142 maya 3392 Printing = FALSE;
143     PrintAbortFlag = FALSE;
144 maya 3227
145 maya 3392 PrnAbortDlg = new CPrnAbortDlg();
146     if (PrnAbortDlg==NULL) {
147     return FALSE;
148     }
149     if (ActiveWin==IdVT) {
150 zmatsuo 7933 hParent = HVTWin;
151 maya 3392 }
152     else {
153 zmatsuo 7933 hParent = HTEKWin;
154 maya 3392 }
155 zmatsuo 7933 PrnAbortDlg->Create(hInst,hParent,&PrintAbortFlag,&ts);
156 maya 3392 HPrnAbortDlg = PrnAbortDlg->GetSafeHwnd();
157 maya 3227
158 maya 3392 SetAbortProc(PrintDC,PrnAbortProc);
159 maya 3227
160 zmatsuo 7527 Doc.cbSize = sizeof(Doc);
161 maya 3392 strncpy_s(DocName,sizeof(DocName),DocumentName,_TRUNCATE);
162     Doc.lpszDocName = DocName;
163     Doc.lpszOutput = NULL;
164     Doc.lpszDatatype = NULL;
165     Doc.fwType = 0;
166 zmatsuo 7527 if (StartDocA(PrintDC, &Doc) > 0) {
167 maya 3392 Printing = TRUE;
168     }
169     else {
170     if (PrnAbortDlg != NULL) {
171     PrnAbortDlg->DestroyWindow();
172     PrnAbortDlg = NULL;
173     HPrnAbortDlg = NULL;
174     }
175     }
176     return Printing;
177 maya 3227 }
178    
179     void PrnStop()
180     {
181 maya 3392 if (Printing) {
182     EndDoc(PrintDC);
183     DeleteDC(PrintDC);
184     Printing = FALSE;
185     }
186     if (PrnAbortDlg != NULL) {
187     PrnAbortDlg->DestroyWindow();
188     PrnAbortDlg = NULL;
189     HPrnAbortDlg = NULL;
190     }
191 maya 3227 }
192    
193     int VTPrintInit(int PrnFlag)
194     // Initialize printing of VT window
195     // PrnFlag: specifies object to be printed
196     // = IdPrnScreen Current screen
197     // = IdPrnSelectedText Selected text
198     // = IdPrnScrollRegion Scroll region
199     // = IdPrnFile Spooled file (printer sequence)
200     // Return: print object ID specified by user
201     // = IdPrnCancel (user clicks "Cancel" button)
202     // = IdPrnScreen (user don't select "print selection" option)
203     // = IdPrnSelectedText (user selects "print selection")
204     // = IdPrnScrollRegion (always when PrnFlag=IdPrnScrollRegion)
205     // = IdPrnFile (always when PrnFlag=IdPrnFile)
206 doda 6435 {
207 maya 3392 BOOL Sel;
208     TEXTMETRIC Metrics;
209     POINT PPI, PPI2;
210     HDC DC;
211     int i;
212     TCharAttr TempAttr = {
213     AttrDefault,
214     AttrDefault,
215     AttrDefaultFG,
216     AttrDefaultBG
217     };
218 maya 3227
219 maya 3392 Sel = (PrnFlag & IdPrnSelectedText)!=0;
220     if (PrnBox(HVTWin,&Sel)==NULL) {
221     return (IdPrnCancel);
222     }
223 maya 3227
224 maya 3392 if (PrintDC==0) {
225     return (IdPrnCancel);
226     }
227 maya 3227
228 maya 3392 /* start printing */
229     if (! PrnStart(ts.Title)) {
230     return (IdPrnCancel);
231     }
232 maya 3227
233 maya 3392 /* initialization */
234     StartPage(PrintDC);
235 maya 3227
236 maya 3392 /* pixels per inch */
237     if ((ts.VTPPI.x>0) && (ts.VTPPI.y>0)) {
238     PPI = ts.VTPPI;
239     }
240     else {
241     PPI.x = GetDeviceCaps(PrintDC,LOGPIXELSX);
242     PPI.y = GetDeviceCaps(PrintDC,LOGPIXELSY);
243     }
244 maya 3227
245 maya 3392 /* left margin */
246     Margin.left = (int)((float)ts.PrnMargin[0] / 100.0 * (float)PPI.x);
247     /* right margin */
248     Margin.right = GetDeviceCaps(PrintDC,HORZRES) -
249     (int)((float)ts.PrnMargin[1] / 100.0 * (float)PPI.x);
250     /* top margin */
251     Margin.top = (int)((float)ts.PrnMargin[2] / 100.0 * (float)PPI.y);
252     /* bottom margin */
253     Margin.bottom = GetDeviceCaps(PrintDC,VERTRES) -
254     (int)((float)ts.PrnMargin[3] / 100.0 * (float)PPI.y);
255 maya 3227
256 maya 3392 /* create test font */
257 zmatsuo 7527 memset(&Prnlf, 0, sizeof(Prnlf));
258 maya 3227
259 maya 3392 if (ts.PrnFont[0]==0) {
260     Prnlf.lfHeight = ts.VTFontSize.y;
261     Prnlf.lfWidth = ts.VTFontSize.x;
262     Prnlf.lfCharSet = ts.VTFontCharSet;
263     strncpy_s(Prnlf.lfFaceName, sizeof(Prnlf.lfFaceName), ts.VTFont, _TRUNCATE);
264     }
265     else {
266     Prnlf.lfHeight = ts.PrnFontSize.y;
267     Prnlf.lfWidth = ts.PrnFontSize.x;
268     Prnlf.lfCharSet = ts.PrnFontCharSet;
269     strncpy_s(Prnlf.lfFaceName, sizeof(Prnlf.lfFaceName), ts.PrnFont, _TRUNCATE);
270     }
271     Prnlf.lfWeight = FW_NORMAL;
272     Prnlf.lfItalic = 0;
273     Prnlf.lfUnderline = 0;
274     Prnlf.lfStrikeOut = 0;
275     Prnlf.lfOutPrecision = OUT_CHARACTER_PRECIS;
276     Prnlf.lfClipPrecision = CLIP_CHARACTER_PRECIS;
277     Prnlf.lfQuality = DEFAULT_QUALITY;
278     Prnlf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
279 maya 3227
280 zmatsuo 7527 PrnFont[0] = CreateFontIndirectA(&Prnlf);
281 maya 3227
282 maya 3392 DC = GetDC(HVTWin);
283     SelectObject(DC, PrnFont[0]);
284     GetTextMetrics(DC, &Metrics);
285     PPI2.x = GetDeviceCaps(DC,LOGPIXELSX);
286     PPI2.y = GetDeviceCaps(DC,LOGPIXELSY);
287     ReleaseDC(HVTWin,DC);
288     DeleteObject(PrnFont[0]); /* Delete test font */
289 maya 3227
290 maya 3392 /* Adjust font size */
291     Prnlf.lfHeight = (int)((float)Metrics.tmHeight * (float)PPI.y / (float)PPI2.y);
292     Prnlf.lfWidth = (int)((float)Metrics.tmAveCharWidth * (float)PPI.x / (float)PPI2.x);
293 maya 3227
294 maya 3392 /* Create New Fonts */
295 maya 3227
296 maya 3392 /* Normal Font */
297     Prnlf.lfWeight = FW_NORMAL;
298     Prnlf.lfUnderline = 0;
299 zmatsuo 7527 PrnFont[0] = CreateFontIndirectA(&Prnlf);
300 maya 3392 SelectObject(PrintDC,PrnFont[0]);
301     GetTextMetrics(PrintDC, &Metrics);
302     PrnFW = Metrics.tmAveCharWidth;
303     PrnFH = Metrics.tmHeight;
304     /* Under line */
305     Prnlf.lfUnderline = 1;
306 zmatsuo 7527 PrnFont[AttrUnder] = CreateFontIndirectA(&Prnlf);
307 maya 3227
308 doda 3666 if (ts.FontFlag & FF_BOLD) {
309 maya 3392 /* Bold */
310     Prnlf.lfUnderline = 0;
311     Prnlf.lfWeight = FW_BOLD;
312 zmatsuo 7527 PrnFont[AttrBold] = CreateFontIndirectA(&Prnlf);
313 maya 3392 /* Bold + Underline */
314     Prnlf.lfUnderline = 1;
315 zmatsuo 7527 PrnFont[AttrBold | AttrUnder] = CreateFontIndirectA(&Prnlf);
316 maya 3392 }
317     else {
318     PrnFont[AttrBold] = PrnFont[AttrDefault];
319     PrnFont[AttrBold | AttrUnder] = PrnFont[AttrUnder];
320     }
321     /* Special font */
322     Prnlf.lfWeight = FW_NORMAL;
323     Prnlf.lfUnderline = 0;
324     Prnlf.lfWidth = PrnFW; /* adjust width */
325     Prnlf.lfHeight = PrnFH;
326     Prnlf.lfCharSet = SYMBOL_CHARSET;
327 maya 3227
328 maya 3392 strncpy_s(Prnlf.lfFaceName, sizeof(Prnlf.lfFaceName),"Tera Special", _TRUNCATE);
329 zmatsuo 7527 PrnFont[AttrSpecial] = CreateFontIndirectA(&Prnlf);
330 maya 3392 PrnFont[AttrSpecial | AttrBold] = PrnFont[AttrSpecial];
331     PrnFont[AttrSpecial | AttrUnder] = PrnFont[AttrSpecial];
332     PrnFont[AttrSpecial | AttrBold | AttrUnder] = PrnFont[AttrSpecial];
333 maya 3227
334 maya 3392 Black = RGB(0,0,0);
335     White = RGB(255,255,255);
336     for (i = 0 ; i <= 255 ; i++) {
337     PrnDx[i] = PrnFW;
338     }
339     PrnSetAttr(TempAttr);
340 maya 3227
341 maya 3392 PrnY = Margin.top;
342     PrnX = Margin.left;
343 maya 3227
344 maya 3392 if (PrnFlag == IdPrnScrollRegion) {
345     return (IdPrnScrollRegion);
346     }
347     if (PrnFlag == IdPrnFile) {
348     return (IdPrnFile);
349     }
350     if (Sel) {
351     return (IdPrnSelectedText);
352     }
353     else {
354     return (IdPrnScreen);
355     }
356 maya 3227 }
357 zmatsuo 7291
358 maya 3227 void PrnSetAttr(TCharAttr Attr)
359     // Set text attribute of printing
360     //
361     {
362 maya 3392 PrnAttr = Attr;
363     SelectObject(PrintDC, PrnFont[Attr.Attr & AttrFontMask]);
364 maya 3227
365 maya 3392 if ((Attr.Attr & AttrReverse) != 0) {
366     SetTextColor(PrintDC,White);
367     SetBkColor( PrintDC,Black);
368     }
369     else {
370     SetTextColor(PrintDC,Black);
371     SetBkColor( PrintDC,White);
372     }
373 maya 3227 }
374    
375     void PrnOutText(PCHAR Buff, int Count)
376     // Print out text
377     // Buff: points text buffer
378     // Count: number of characters to be printed
379     {
380 maya 3392 int i;
381     RECT RText;
382     PCHAR Ptr, Ptr1, Ptr2;
383     char Buff2[256];
384 maya 3227
385 maya 3392 if (Count<=0) {
386     return;
387     }
388     if (Count>(sizeof(Buff2)-1)) {
389     Count=sizeof(Buff2)-1;
390     }
391     memcpy(Buff2,Buff,Count);
392     Buff2[Count] = 0;
393     Ptr = Buff2;
394 maya 3227
395 maya 3392 if (ts.Language==IdRussian) {
396     if (ts.PrnFont[0]==0) {
397     RussConvStr(ts.RussClient,ts.RussFont,Buff2,Count);
398     }
399     else {
400     RussConvStr(ts.RussClient,ts.RussPrint,Buff2,Count);
401     }
402     }
403 maya 3227
404 maya 3392 do {
405     if (PrnX+PrnFW > Margin.right) {
406     /* new line */
407     PrnX = Margin.left;
408     PrnY = PrnY + PrnFH;
409     }
410     if (PrnY+PrnFH > Margin.bottom) {
411     /* next page */
412     EndPage(PrintDC);
413     StartPage(PrintDC);
414     PrnSetAttr(PrnAttr);
415     PrnY = Margin.top;
416     }
417 maya 3227
418 maya 3392 i = (Margin.right-PrnX) / PrnFW;
419     if (i==0) {
420     i=1;
421     }
422     if (i>Count) {
423     i=Count;
424     }
425 maya 3227
426 maya 3392 if (i<Count) {
427     Ptr2 = Ptr;
428     do {
429     Ptr1 = Ptr2;
430 zmatsuo 7527 Ptr2 = CharNextA(Ptr1);
431 maya 3392 } while ((Ptr2!=NULL) && ((Ptr2-Ptr)<=i));
432     i = Ptr1-Ptr;
433     if (i<=0) {
434     i=1;
435     }
436     }
437 maya 3227
438 maya 3392 RText.left = PrnX;
439     RText.right = PrnX + i*PrnFW;
440     RText.top = PrnY;
441     RText.bottom = PrnY+PrnFH;
442 zmatsuo 7527 ExtTextOutA(PrintDC,PrnX,PrnY,6,&RText,Ptr,i,&PrnDx[0]);
443 maya 3392 PrnX = RText.right;
444     Count=Count-i;
445     Ptr = Ptr + i;
446     } while (Count>0);
447 maya 3227
448     }
449    
450     void PrnNewLine()
451     // Moves to the next line in printing
452     {
453 maya 3392 PrnX = Margin.left;
454     PrnY = PrnY + PrnFH;
455 maya 3227 }
456    
457     void VTPrintEnd()
458     {
459 maya 3392 int i, j;
460 maya 3227
461 maya 3392 EndPage(PrintDC);
462 maya 3227
463 maya 3392 for (i = 0 ; i <= AttrFontMask ; i++) {
464     for (j = i+1 ; j <= AttrFontMask ; j++) {
465     if (PrnFont[j]==PrnFont[i]) {
466     PrnFont[j] = NULL;
467     }
468     }
469     if (PrnFont[i] != NULL) {
470     DeleteObject(PrnFont[i]);
471     }
472     }
473 maya 3227
474 maya 3392 PrnStop();
475     return;
476 maya 3227 }
477    
478     /* printer emulation routines */
479     void OpenPrnFile()
480     {
481 maya 4031 char Temp[MAX_PATH];
482 maya 3227
483 maya 3392 KillTimer(HVTWin,IdPrnStartTimer);
484 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
485 maya 3392 return;
486     }
487     if (PrnFName[0] == 0) {
488 zmatsuo 7527 GetTempPathA(sizeof(Temp),Temp);
489     if (GetTempFileNameA(Temp,"tmp",0,PrnFName)==0) {
490 maya 3392 return;
491     }
492     HPrnFile = _lcreat(PrnFName,0);
493     }
494     else {
495     HPrnFile = _lopen(PrnFName,OF_WRITE);
496 zmatsuo 7290 if (HPrnFile == INVALID_HANDLE_VALUE) {
497 maya 3392 HPrnFile = _lcreat(PrnFName,0);
498     }
499     }
500 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
501 maya 3392 _llseek(HPrnFile,0,2);
502     }
503 maya 3227 }
504    
505     void PrintFile()
506     {
507 maya 3392 char Buff[256];
508     BOOL CRFlag = FALSE;
509     int c, i;
510     BYTE b;
511 maya 3227
512 maya 3392 if (VTPrintInit(IdPrnFile)==IdPrnFile) {
513     HPrnFile = _lopen(PrnFName,OF_READ);
514 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
515 maya 3392 do {
516     i = 0;
517     do {
518     c = _lread(HPrnFile,&b,1);
519     if (c==1) {
520     switch (b) {
521     case HT:
522     memset(&(Buff[i]),0x20,8);
523     i = i + 8;
524     CRFlag = FALSE;
525     break;
526     case LF:
527     CRFlag = ! CRFlag;
528     break;
529     case FF:
530     case CR:
531     CRFlag = TRUE;
532     break;
533     default:
534     if (b >= 0x20) {
535     Buff[i] = b;
536     i++;
537     }
538     CRFlag = FALSE;
539     break;
540     }
541     }
542     if (i>=(sizeof(Buff)-7)) {
543     CRFlag=TRUE;
544     }
545     } while ((c>0) && (! CRFlag));
546     if (i>0) {
547     PrnOutText(Buff, i);
548     }
549     if (CRFlag) {
550     PrnX = Margin.left;
551     if ((b==FF) && (ts.PrnConvFF==0)) { // new page
552     PrnY = Margin.bottom;
553     }
554     else { // new line
555     PrnY = PrnY + PrnFH;
556     }
557     }
558     CRFlag = (b==CR);
559     } while (c>0);
560     _lclose(HPrnFile);
561 maya 3227 }
562 maya 3392 HPrnFile = 0;
563     VTPrintEnd();
564 maya 3227 }
565 maya 3392 remove(PrnFName);
566     PrnFName[0] = 0;
567 maya 3227 }
568    
569     void PrintFileDirect()
570     {
571 zmatsuo 7933 HWND hParent;
572 maya 3227
573 maya 3392 PrnAbortDlg = new CPrnAbortDlg();
574     if (PrnAbortDlg==NULL) {
575     remove(PrnFName);
576     PrnFName[0] = 0;
577     return;
578     }
579     if (ActiveWin==IdVT) {
580 zmatsuo 7933 hParent = HVTWin;
581 maya 3392 }
582     else {
583 zmatsuo 7933 hParent = HTEKWin;
584 maya 3392 }
585 zmatsuo 7933 PrnAbortDlg->Create(hInst,hParent,&PrintAbortFlag,&ts);
586 maya 3392 HPrnAbortDlg = PrnAbortDlg->GetSafeHwnd();
587 maya 3227
588 maya 3392 HPrnFile = _lopen(PrnFName,OF_READ);
589 zmatsuo 7290 PrintAbortFlag = (HPrnFile == INVALID_HANDLE_VALUE) || ! PrnOpen(ts.PrnDev);
590 maya 3392 PrnBuffCount = 0;
591     SetTimer(HVTWin,IdPrnProcTimer,0,NULL);
592 maya 3227 }
593    
594     void PrnFileDirectProc()
595     {
596 maya 3392 int c;
597 maya 3227
598 zmatsuo 7290 if (HPrnFile==INVALID_HANDLE_VALUE) {
599 maya 3392 return;
600     }
601     if (PrintAbortFlag) {
602     HPrnAbortDlg = NULL;
603     PrnAbortDlg = NULL;
604     PrnCancel();
605     }
606 zmatsuo 7290 if (!PrintAbortFlag && (HPrnFile != INVALID_HANDLE_VALUE)) {
607 maya 3392 do {
608     if (PrnBuffCount==0) {
609     PrnBuffCount = _lread(HPrnFile,PrnBuff,1);
610     if (ts.Language==IdRussian) {
611     RussConvStr(ts.RussClient,ts.RussPrint,PrnBuff,PrnBuffCount);
612     }
613     }
614 maya 3227
615 maya 3392 if (PrnBuffCount==1) {
616     c = PrnWrite(PrnBuff,1);
617     if (c==0) {
618     SetTimer(HVTWin,IdPrnProcTimer,10,NULL);
619     return;
620     }
621     PrnBuffCount = 0;
622     }
623     else {
624     c = 0;
625     }
626     } while (c>0);
627 maya 3227 }
628 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
629 maya 3392 _lclose(HPrnFile);
630     }
631 zmatsuo 7290 HPrnFile = INVALID_HANDLE_VALUE;
632 maya 3392 PrnClose();
633     remove(PrnFName);
634     PrnFName[0] = 0;
635     if (PrnAbortDlg!=NULL) {
636     PrnAbortDlg->DestroyWindow();
637     PrnAbortDlg = NULL;
638     HPrnAbortDlg = NULL;
639     }
640 maya 3227 }
641    
642     void PrnFileStart()
643     {
644 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
645 maya 3392 return;
646     }
647     if (PrnFName[0]==0) {
648     return;
649     }
650     if (ts.PrnDev[0]!=0) {
651     PrintFileDirect(); // send file directry to printer port
652     }
653     else { // print file by using Windows API
654     PrintFile();
655     }
656 maya 3227 }
657    
658     void ClosePrnFile()
659     {
660 maya 3392 PrnBuffCount = 0;
661 zmatsuo 7290 if (HPrnFile != INVALID_HANDLE_VALUE) {
662 maya 3392 _lclose(HPrnFile);
663     }
664 zmatsuo 7290 HPrnFile = INVALID_HANDLE_VALUE;
665 maya 3392 SetTimer(HVTWin,IdPrnStartTimer,ts.PassThruDelay*1000,NULL);
666 maya 3227 }
667    
668     void WriteToPrnFile(BYTE b, BOOL Write)
669     // (b,Write) =
670     // (0,FALSE): clear buffer
671     // (0,TRUE): write buffer to file
672     // (b,FALSE): put b in buff
673     // (b,TRUE): put b in buff and
674     // write buffer to file
675     {
676 maya 3392 if ((b>0) && (PrnBuffCount<sizeof(PrnBuff))) {
677     PrnBuff[PrnBuffCount++] = b;
678     }
679 maya 3227
680 maya 3392 if (Write) {
681     _lwrite(HPrnFile,PrnBuff,PrnBuffCount);
682     PrnBuffCount = 0;
683     }
684     if ((b==0) && ! Write) {
685     PrnBuffCount = 0;
686     }
687 maya 3227 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26