News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

printing a file on my printer

Started by allynm, October 29, 2009, 02:30:19 AM

Previous topic - Next topic

allynm

Hi RuiLoureiro -

Just downloaded it.  I had to grade a bunch of homework assignments, so I'm a bit slow catching up with you.

I'll let you know shortly.

I'm assuming you figured out how to do multiple pages using DrawText??

Regards,

Mark

allynm

Hi again RuiLoureiro-

Well, I tried it.  Maybe I'm doing something wrong.  But, when I open the GetPrinter DC menuitem and press OK I get a message that says I need to pick a font.  But, it doesn't actually let me choose a font.  The Choose File menuitem opens up a listview box the way I would expect and appears to let me select a file.  When I use the Print Text menuitem, my printer starts up and but it doesn't print the file I selected it just runs a page thru my Laser Jet and stops.  It stops OK after passing one page thru the printer drive.

Printer8 zip file only had the .exe so I don't have any thoughts or questions about the asm file.

Please let me know you received this.  I will be happy to help in any way I can. 

Mark

RuiLoureiro

Quote from: allynm on November 01, 2009, 04:48:13 PM
I'm assuming you figured out how to do multiple pages using DrawText??

Hi Mark,
             the answer is no. I am using TextOut to do the work

              Please download the new Printer8.
              1.  when the prog starts you should choose the printer. ok ? no ?
              2. now goto Choose File menuiten and choose an .asm or .rc file (dont choose .exe or .obj etc. doesnt work)
              3. now goto Test Printer and choose Print Test. Doesnt print the file you choose ?
                  In my comp it prints correctly. After the first page you may choose to cancel the printing.
               4. After the printing you nedd  Get Printer DC again before choose another file etc. because i delete DC
              If it works correctly i can give you the all files (exe & asm) if you want.   
Thanks
Rui               

allynm

Hi RuiLoureiro-

I get partway through and then it fails.  I am getting a MessageBox labeled "Test 5" and the message says "Estou acqui".   Can't close the box....

I will keep trying until we get this thing fixed...

Regards,
Mark

RuiLoureiro

Quote from: allynm on November 01, 2009, 05:44:11 PM
I get partway through and then it fails.  I am getting a MessageBox labeled "Test 5" and the message says "Estou acqui".   Can't close the box....

I will keep trying until we get this thing fixed...

Mark,    yes but download the last Printer8 i posted
Rui

allynm

Hi RuiLoreiro :

IT WORKED!!  Got multiple pages of MichaelW's PrintTextFile asm file.  It looks as if you've nailed the solution.

I'm very curious about how Printer8 works.  Is it only good for asm files?

Congratulations,

Mark

RuiLoureiro

Quote from: allynm on November 01, 2009, 06:06:12 PM
Hi RuiLoreiro :
IT WORKED!!  Got multiple pages of MichaelW's PrintTextFile asm file.  It looks as if you've nailed the solution.
I'm very curious about how Printer8 works.  Is it only good for asm files?
Mark,
           Ok thanks. It is to print Text Files: each line end in CRLF (return linefeed).
           But Printer8 has one problem: doesnt convert TABS. but Printer9 does.
           Now you can see what i did in Printer8 (asm file)
;................................................................................................................
PrintText           proc     

                    mov     _PageNumber, 0

                    cmp     _hpdc, 0
                    jne     short @F
                    ret

@@:                 mov     ebx, offset _bufferTxt
                    cmp     dword ptr [ebx - 4], 0
                    jne     short @F
                    ret
                   
@@:                 mov    _di.cbSize, SIZEOF _di
                    mov    _di.lpszDocName, offset _DocTitle
                    mov    _di.lpszOutput, NULL
                    mov    _di.fwType, NULL
                    ;
                    invoke  StartDoc, _hpdc, addr _di
                    cmp     eax, 0
                    jg      short @F
                    ret
                   
@@:                 call    PrintPage
                    jnc     short @B
                    ;
                    ; Remove
                    ;   
                    invoke   DeleteObject, _hpFont
                    ;
                    invoke   DeleteDC, _hpdc   
                    mov      _hpdc, 0

                    ; »»»»»»»»»»»»»»»»»»»
                    ; Destroy text buffer
                    ; »»»»»»»»»»»»»»»»»»
                    mov     ebx, offset _bufferTxt
                    mov     dword ptr [ebx - 4], 0

                    ret
PrintText           endp
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
PrintPage           proc
                    LOCAL   LinCor:DWORD, MaxLin:DWORD
                    ;
                    invoke  StartPage, _hpdc
                    cmp     eax, 0
                    jg      short @F
                    ;
                    invoke  EndDoc, _hpdc
                    stc
                    ret

@@:                 mov     MaxLin, 49             ;_mLines
                    mov     LinCor, 2

                    inc     _PageNumber
                    invoke  CnvToRcl, _PageNumber, addr _PageNum

                    invoke  RclRclCpy, addr _MsgPage, addr _PageBuf 
                    invoke  RclRclAdd, addr _PageNum, addr _PageBuf 

                    invoke  TextPrint, addr _PageBuf, 1, 95

                    ;
_start:             call    GetNxtLin
                    jnc     short @F
                    ;
                    ; Fim
                    ;
                    invoke  EndPage, _hpdc
                    invoke  EndDoc, _hpdc                   
                    stc
                    ret
                    ;                     
@@:                 invoke  TextPrint, edi, LinCor, 4
                    ;
                    inc     LinCor
                    ;
                    sub     MaxLin, 1
                    jnz     short _start
                    ;
@@:                 invoke  EndPage, _hpdc
                    cmp     eax, 0
                    jg      short @F
                    ;
                    invoke  EndDoc, _hpdc
                    stc
                    ret
                    ;
@@:                 clc
                    ret
PrintPage           endp
; ««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
TextPrint           proc    pTxt:DWORD, Lin:DWORD, Col:DWORD

                    mov     ebx, pTxt
                    cmp     dword ptr [ebx - 4], 0
                    jne     short @F
                    clc
                    ret
                   
@@:                 invoke  GetTextMetrics, _hpdc, addr _tm
                    ;
                    mov     ecx, _tm.tmHeight
                    mov     eax, Lin
                    sub     eax, 1
                    mul     ecx                 
                    mov     _PosPrnY, eax
                    ;
                    ;
                    ;
                    mov     ecx, _tm.tmAveCharWidth
                    mov     eax, Col
                    sub     eax, 1
                    mul     ecx
                    mov     _PosPrnX, eax

                    invoke  TextOut, _hpdc, _PosPrnX, _PosPrnY, ebx, [ebx - 4]
                    clc
                    ret
TextPrint           endp

;.................................................................................................................
Thanks again
Rui

MichaelW

Quote
MichaelW,
This is to you: can i use DrawTextEx to print more than one page. How ?

Hi Rui,

I seem to recall doing that at some point, but I don't remember the details and I can't find the code, and since my printer is out of ink, I can't test any printer code until I get a new cartridge.
eschew obfuscation

hutch--

Here is a test app to run the DLL. I tweaked the DLL so it loaded the rich edit 2 library and tweaked the display page width so it should display OK.

Just run the small test app PrintMe.exe, pick a file to print and you should be in business.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

jj2007

Quote from: RuiLoureiro on November 01, 2009, 01:58:14 PM
Hi JJ,
        Why not to open a new topic. Try Printer8 and say something ok ? Thanks

Hi Rui,

I tried Printer8, latest version from reply #36, and it gives error A2005:symbol redefinition : INVALID_SET_FILE_POINTER
When I comment this one out, it assembles (but very slowly, for whatever reason).
The exe shows the print dialog, but I see nothing happen afterwards. I run Win XP SP2.

Jochen

P.S.: I integrated my RichText print routine now in the TinyRTF thread. It works now with PageSetupDlg instead of PrintDlg - an example PDF containing the proc is included.

allynm

To Hutch -

Wow!  Very cool indeed.  Thanks also for sending the asm files along with the executable.  As you may recall, I am trying to understand how all this stuff works, and only by studying code can this happen.

You and RuiLoureiro and MichaelW have been really great tutors.  I wish I had something that would be of equal usefulness to contribute.

What I want to do is integrate in the printing capability with a bigger Windows program that reads some parameters for a supply chain management program and prints out the results.  I want to use common dialog box to collect the input information.  Trying to work out a nice way with the text edit box to get the parameters.

Thanks again.
Mark Allyn

RuiLoureiro

#41
note:  this editor doesnt work well. The caret jumps above and below
       when i write at the bottom of this box. i cannot see the text
       where the caret is
       
Hi all
       1. This was my first quick attempt to write something like it.
          I only need printing strings line X, column Y and page by page
          and not text stuff tah ends in CRLF.
          To print text files i use QE (Hutch editor);
         
       2. I did it to help Mark because he doesnt want to use QuickEditor, NotePad,
          MS Word, etc. to print text files. As far as i understood he wants to
          learn how to do it, APIs to use etc. as a GUI app.

Hi MichaelW,
                Thank you the same.
               
Hi Jochen,
           1. Thank you for reply;
           2. «it gives error A2005:symbol redefinition»

               My windows.inc doenst have INVALID_SET_FILE_POINTER
               this is why i put INVALID_SET_FILE_POINTER equ 0FFFFFFFFh
           
           3. «When I comment this one out, it assembles
               (but very slowly, for whatever reason)»

                I defined the buffers in the .data section.
                This may be the reason why it assembles very slow
               
                ; »»»»»»»»»»»
                ; File Buffer
                ; »»»»»»»»»»» 
;                dd MAXBUFSIZE
;                dd 0
;_bufferTxt      db MAXBUFSIZE dup(0)
;                db 0               
                ; »»»»»»»»»»»»»»»»»»»»»
                ; File Buffer Formatted
                ; »»»»»»»»»»»»»»»»»»»»»
;                dd 0                            ; -20 CorRegLst
;                dd 0                            ; -16 EndRegLst
;                dd MAXCOLSIZE4                  ; -12 LenRegLst
;                dd MAXLINSIZE                   ;  -8 MaxRegLst
;                dd 0                            ;  -4 First String length
;_bufferFrm      db MAXLINSIZE dup ( MAXCOLSIZE4 dup (0) )
;                db 0
               
             4. «The exe shows the print dialog, but I see nothing happen afterwards.»

                 See reply #32

                Could you test my Printer10 example, please ?
                Thanks again

Hi Mark,
             See Printer10. Try Test Printer -> Print Text.
             Now it alloc memory for 100 pages, 50 lines/page and 117 colums.
             It convert TABS too.
             It seems to work correctly for me but iam quite sure it has bugs.
             It is an attempt to help you. If something runs wrong, please tell me.

             Files below Printer10.zip (inc, exe, asm) & rsrc.zip

Hutch: Thanks for your PrintMe. I read it and learned some things :U           
RuiLoureiro

allynm

Hi RuiLoureiro -

Just picked up your new posting.  I will download and run Printer 10 just as you suggest.

You understand exactly what I'm trying to do!  I suppose it's a little crazy of me to get this involved in the printing process, but it really is the only way to learn how to do it.

Thank you,
Mark Allyn

jj2007

Printer10 works fine, result attached. The font is a bit high but otherwise no problems.

RuiLoureiro

Quote from: jj2007 on November 02, 2009, 09:50:43 PM
Printer10 works fine, result attached. The font is a bit high but otherwise no problems.

Jochen,
             Thank you for reply. i would say «... seems works fine ... »
             Thank you for your comment «The font is a big high ... » !
Rui  :thumbu