News:

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

how to print in masm

Started by ossama, December 04, 2007, 02:40:53 PM

Previous topic - Next topic

ossama

hello,
say that i have a list view in details view, with text/icons in items and subitems.
the question is how to print it in A4 format (using real or virtual printer)?

thank you in advance

donkey

Bill Craven sent this to me once (or I sent it to him can't remember which but it is in a folder with his name on my machine) you can use it as an example to build a print routine. Actually now that I think of it the commenting and label names look alot like NaN's so he may have wrote it ??? At any rate here it is...

Note: MASM syntax

LinePrint MACRO pstring:REQ

  mov eax, LINE_WIDTH
  add yP, eax

  invoke lstrlen, pstring
  invoke TextOut, PD.hDC, COLUMN_1, yP, pstring, eax

  mov eax, LINE_WIDTH
  add yP, eax

ENDM

Do_Print PROC hWnd:DWORD, wParam:DWORD, lParam:DWORD
LOCAL memdc :DWORD
LOCAL hbmp :DWORD
LOCAL bmp :BITMAP

; Initialize the Print Dialog
; --===============================================
mov yP, 0 ; Start of page..

jmp @F
FontMS        db "MS Sans Serif",0
@@:

; Initialize the Print Dialog
; --===============================================
mov PD.lStructSize, SIZEOF PD
mov eax,hWnd
mov PD.hwndOwner, eax
mov eax,hInstance
mov PD.hInstance, eax
mov PD.Flags, PD_RETURNDC                  ; Return Users DC choices

; Show the Print Dialog Box!
; --===============================================
invoke PrintDlg, offset PD
cmp eax, FALSE
je Done

; IF you specify the PD_RETURNDC value in the Flags member of the PRINTDLG structure and the user
; selects Print To File from the Print dialog box, you can use the DC returned in the hDC member
; of the structure to generate output, but only after you prepare the file for output by specifying
; the name of the file in the lpszOutput member of the DOCINFO structure and calling the StartDoc function.

; Check Get the Printed X+Y extence..
; --===============================================
invoke GetDeviceCaps, PD.hDC, HORZRES
shr eax, 1
mov COLUMN_2, eax                                    ; 2 columns per page
invoke GetDeviceCaps, PD.hDC, VERTRES
shr eax, 6
mov LINE_WIDTH, eax                                  ; 64 Lines / page
mov eax,LINE_WIDTH
mov COLUMN_1,eax

; Create A Printer Font..
; --===============================================
invoke lstrcpy, addr LF.lfFaceName, addr FontMS
mov eax,LINE_WIDTH
mov LF.lfHeight,eax
mov LF.lfWeight, 600
invoke CreateFontIndirect, ADDR LF
mov pFont, eax

; Set up the Document Info Structure
; --===============================================
mov DOC.cbSize, SIZEOF DOC
mov DOC.lpszDocName, offset DocTitle
mov DOC.lpszOutput, NULL
mov DOC.fwType, NULL

; Start the Doc..
; Ensures proper print order of pages..
; --===============================================
invoke StartDoc, PD.hDC, offset DOC

; Start the Page..
; Prepares the printer driver to accept data.
; --===============================================
invoke StartPage, PD.hDC

; Load a Printer Font..
; --===============================================
invoke SelectObject, PD.hDC, pFont

; Print the lines here
; --===============================================
jmp @F
; This is an example
  szTestMessage db "This is a test",0
  szTestMessage2 db "This is a test2",0
@@:

LinePrint OFFSET szTestMessage
LinePrint OFFSET szTestMessage2

invoke CreateCompatibleDC,PD.hDC
mov memdc,eax
invoke LoadBitmap,hInstance,10000
mov hbmp,eax
invoke SelectObject,memdc,hbmp
push eax
invoke GetObject,hbmp,SIZEOF bmp,ADDR bmp

invoke BitBlt,PD.hDC,0,0,bmp.bmWidth,bmp.bmHeight,memdc,0,0,SRCCOPY

pop eax
invoke SelectObject,memdc,eax
invoke DeleteDC,memdc
invoke DeleteObject,hbmp

; Do the End of Page (feed out the paper)
; --===============================================
invoke EndPage, PD.hDC
invoke EndDoc, PD.hDC
invoke DeleteDC, PD.hDC

Done:
ret
Do_Print ENDP


Donkey
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

Draakie

NAN's source for sure

You could also have a look at a full featured print package XXXControls / XXXRichedit see
an example used in my proggie ...http://www.masm32.com/board/index.php?topic=5880.0
Does this code make me look bloated ? (wink)

ossama

thank you very much , i will take o a deep look in these source codes. :U

donkey

Quote from: Draakie on December 05, 2007, 08:02:21 AM
NAN's source for sure

Yup, it was NaN's I found a post-it in one of my projects that identified it as his, too much source and too short a memory...

Donkey
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable