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

Hello everyone:

I know the question I have has a very long history on the forum.  I have searched a number of previous posts on this subject.  Please don't tell me that I should seach the forum...I have.  I have looked at a lot of code you experts have contributed.  Still....

I have an ASCII file named "Mystuff.txt".  I would like to print this file with my trusty HP laserjet.  I'm not trying to do anything fancy, just print on the printer what I see on my screen.

BUT, I don't want to go thru Notepad to do it using the SHELL macro or its relatives. 

How do I INVOKE a Print dialog and have it print my little Mystuff file?  I spent a very rainy day in Pennsylvania messing around with Microsoft's suggestions on this, and have nothing to show for it but a sea of error messages....

Grateful, as always,

Mark Allyn, a pretty serious amateur professional newbie

BlackVortex

I don't have a printer so I can't help with definitive code, but until someone with firsthand knowledge comes, do you really want/need to show a print dialog for the user to select options ?

Try this :
PrintDlgEx function
http://msdn.microsoft.com/en-us/library/ms646942%28VS.85%29.aspx
This seems to just get the information, not do the actual printing.

For simpler printing I would first try to access a printer and get a handle with
OpenPrinter function
http://msdn.microsoft.com/en-us/library/dd162751%28VS.85%29.aspx

hutch--

Mark,

This is not exactly what you were after but it does print to a default printer correctly, its the complete code for a printing DLL complete with preview window and font settings. You call the DLL from this procedure,


; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

print_text proc lprTxt:DWORD,hParent:DWORD

    mrm prWnd,hParent                   ; copy parent address to global
    mrm prTxt,lprTxt                    ; copy text address to global

    invoke preview_win,prWnd

    ret

print_text endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤


This display of the DLL when it is called by an external app is in a richdit control set up for printing. You have cursor and page up and down navigation but no scroll bar. The guts of it are no joy but it does work OK on my HP Laser Jet and any of the PDF printer drivers I have installed.

I don't class it as a fully finished app but its close.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

RuiLoureiro

#3
Mark,
            Do you want to print using TextOut ? If yes you need to get a PrinterDC to use TextOut.
            To get a PrinterDC you need to invoke CreateDC but you need  DriverName and PrinterName ok ? To get this 2 names use GetDefaultPrinter, OpenPrinter and GetPrinter. With GetPrinter you have DriverName and PrinterName and then CreateDC and so on
RuiLoureiro

allynm

Hi Hutch, RuiLoureiro, and BlackVortex:

Thank you all for your help on this beginner problem.  I will try the Hutch DLL later today.  I bet it is pretty cool.  Hutch was right in thinking that I was trying to do more of the coding on my own--I'm trying bit by bit (literally!) to get the basics of the API's.  In Hutch's snippet there is this mrm instruction.  I have never seen it....what is it?  I can see what it does from the comments...

Coming on to RuiLoureiro, yes I wanted to do TextOut as you surmised.  I was recoding yesterday off a C program Microsoft posted on its developer site.  Got nowhere good.  I need to check, but I'm pretty sure that a couple of RuiLoureiro's API calls were not part of the MSFT program even though the model program used TextOut.

Thanks again,

Mark Allyn

jj2007

mrm is part of \masm32\macros\macros.asm

     mrm MACRO m1, m2
        mov eax, m2
        mov m1, eax
      ENDM

If it's not speed critical, m2m is usually shorter, and does not trash eax:

     m2m MACRO M1, M2
        push M2
        pop  M1
      ENDM

allynm

Hi JJ-

I was afraid of that!  I looked for a Macro on MASM32 Help before I posted my query but I didn't see it.

Thanks,
Mark Allyn

RuiLoureiro

Quote from: allynm on October 29, 2009, 02:01:49 PM
Coming on to RuiLoureiro, yes I wanted to do TextOut as you surmised.  I was recoding yesterday off a C program Microsoft posted on its developer site.  Got nowhere good.  I need to check, but I'm pretty sure that a couple of RuiLoureiro's API calls were not part of the MSFT program even though the model program used TextOut.
Hi Mark,
              AFAIK, all APIs are MSFT: GetDefaultPrinter, OpenPrinter, GetPrinter, CreateDC and TextOut.
             You need also: StartDoc, StartPage , ...TextOut...  ..., EndPage, EndDoc.

LATER: to get the printer device context you can use invoke PrintDlg. In this case you dont need to CreateDC etc
RuiLoureiro

MichaelW

The attachment is a small console app that prints a file on a user-selected printer. The file can be specified on the command line or just dropped on the EXE. I did not attempt to implement any sort of WYSIWYG, and depending on the font selection the printed text may be too small to reasonably read. In my limited testing the app worked OK, but since I'm not sure about multiple details errors in the code are likely.
eschew obfuscation

dedndave

cool Michael - thanks

btw - am i the only one who is reminded of Ruy Lopez when i see the "RuiLoureiro" nic ? - lol


RuiLoureiro

Quote from: dedndave on October 29, 2009, 04:34:53 PM
btw - am i the only one who is reminded of Ruy Lopez when i see the "RuiLoureiro" nic ? - lol
dedndave,
                 what about you ? Are you trying to play ? Iam not a kid dave. Yes you are the only one
RuiLoureiro

dedndave

don't get all upset
Ruy Lopez was a great chess player from the 1500's
the most popular chess opening used today is called the "Ruy Lopez"

RuiLoureiro

Ok dedndave,
                     now i understood the idea  :U
Rui


hutch--

For MArk,

There is an easy way to test the DLL I posted. Use QE and go to the directory that the DLL and code are in.

Select "Load Script" from the File menu.

Open the script "runprint.qse".

Open a file with QE.

Press F12.

The DLL should them display the text file ready to print.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

allynm

Hi Hutch -

Thanks for the tip.  I have a pretty open day today and I will give it a try.  I'm also going to try out MichaelW's code too. 

Mark Allyn