Hello, I want to do something about the issue Printer by Win32 API in MASM32. and try to output some text to a printer.

I viewed the M$ MSDN, but there is only funtions detail.

So, I want to know if there are some snippets or description about the issue Printer.

Thank you .
Posted on 2005-07-25 23:40:37 by seasea
Are you asking: How do I Print?

Following code written by NaN.

Do_Print PROTO :DWORD,:DWORD,:DWORD


PrintFloat MACRO Q1:REQ, string:REQ
LOCAL szMessage

.data
szMessage      BYTE string, ":",0
.code
invoke FloatToStr2, Q1, addr POUT
invoke lstrlen, addr szMessage
invoke TextOut, PD.hDC, COLUMN_1, yP, addr szMessage, eax

invoke lstrlen, addr POUT
invoke TextOut, PD.hDC, COLUMN_2, yP, addr POUT, eax

mov eax, LINE_WIDTH
add yP, eax

ENDM

PrintMemText MACRO Mem:REQ, string:REQ
LOCAL szMessage

.data
szMessage      BYTE string, ":",0
.code

invoke lstrlen, addr szMessage
invoke TextOut, PD.hDC, COLUMN_1, yP, addr szMessage, eax

invoke lstrlen, addr Mem
invoke TextOut, PD.hDC, COLUMN_2, yP, addr Mem, eax

mov eax, LINE_WIDTH
add yP, eax


ENDM

PrintTitle MACRO string:REQ
LOCAL szMessage

.data
szMessage      BYTE string, 0
.code

mov eax, LINE_WIDTH
add yP, eax

invoke lstrlen, addr szMessage
invoke TextOut, PD.hDC, COLUMN_1, yP, addr szMessage, eax

mov eax, LINE_WIDTH
add yP, eax


ENDM


.data?
PD  PRINTDLG  <>
DOC DOCINFO  <>
LF  LOGFONT  <>

pFont        dd ?
yP            dd ?
POUT          db 50 dup (?)

COLUMN_1      dd ?
COLUMN_2      dd ?
LINE_WIDTH    dd ?


.data
DocTitle      db "Ground Grid Calculations",0

FontMS        db "MS Sans Serif",0

.code
Do_Print PROC hWnd:DWORD, wParam:DWORD, lParam:DWORD
LOCAL QTMP :QWORD
LOCAL BUG[12] :BYTE
LOCAL TEMP :DWORD

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

invoke SendMessage, h7001, CB_GETCURSEL, NULL, NULL
mov TEMP, eax
invoke SendMessage, h7001, CB_GETLBTEXT, TEMP, addr BUG

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

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

; 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
DPrintValD eax, "Max X"
shr eax, 1
mov COLUMN_2, eax                                    ; 2 columns per page
DPrintValD eax, "Colum space"
invoke GetDeviceCaps, PD.hDC, VERTRES
DPrintValD eax, "Max Y"
shr eax, 6
mov LINE_WIDTH, eax                                  ; 64 Lines / page
DPrintValD eax, "Line Width"
m2m COLUMN_1, LINE_WIDTH

; Create A Printer Font..
; --===============================================
invoke lstrcpy, addr LF.lfFaceName, addr FontMS
m2m LF.lfHeight, LINE_WIDTH
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 Needed Text...
; --===============================================
PrintTitle "Ground Grid Design Calculations"
PrintTitle "Conductor Values"
PrintFloat OutsideDistance, "Outside Ground Segment Length (m)"
PrintFloat InsideDistance,  "Inside Ground Segment Length (m)"
PrintFloat CondDistance,    "Inside Conductor Spacing (m)"
PrintFloat NumberOfRods,    "Number Of Ground Rods"
PrintFloat RodLength,      "Ground Rod Length (m)"
PrintFloat ConductorSize,  "Conductor Size (m)"
PrintMemText BUG,          "Conductor Type (IEEE)"

PrintTitle "Geometry Values"
PrintFloat Depth,          "Ground Grid Burried Depth (m)"
PrintFloat Perimeter,      "Ground Grid Perimeter (m)"
PrintFloat TotalArea,      "Ground Grid Total Area (m*m)"
PrintFloat TotalCondLength, "Ground Grid Total Conductor Length (m)"
PrintFloat TotalGroundRodLength, "Ground Grid Total Ground Rod Length (m)"
PrintTitle "Electrical Values"
PrintFloat VABase,          "VA Base (unused in Calculations)"
PrintFloat VoltBase,        "3P Voltage Value (V)"
PrintFloat MaxFaultTime,    "Max Fault Time (unused in Calculations)"
PrintFloat SurfaceResistivity, "Surface Resistivity (unused) (Ohm-m)"
PrintFloat UpperSoilResistivity, "Upper Soil Resistivity (Ohm-m)"
PrintFloat LowerSoilResistivity, "Lower Soil Resistivity (Ohm-m)"
PrintFloat ZReal,          "Summed Line Impedance  (Ohm)"
PrintFloat ZImag,          "Summed Line Impedance j(Ohm)"
PrintTitle "Calculations Rendered"
PrintFloat LT_Calc,        "'LT' Calculated Value (m)"
PrintFloat RG_Calc,        "'RG' Calculated Value (Ohm)"
PrintFloat ZL_Calc,        "'ZL' Calculated Impedance (Ohm)"
PrintFloat ILG_Calc,        "Line-Ground Calculated Current (A)"
PrintFloat GPR_Calc,        "'GPR' Calculated Value (V)"
PrintFloat KM_Calc,        "'KM' Calculated Value"
PrintFloat KI_Calc,        "'KI' Calculated Value"
PrintFloat EM_Calc,        "'E-Mesh' Calculated Value (V)"
PrintFloat KS_Calc,        "'KS' Calculated Value"
PrintFloat LS_Calc,        "'LS' Calculated Value"
PrintFloat ES_Calc,        "'ES' Calculated Value (V)"
PrintFloat THE_N,          "'N' Value In Calculations"
PrintTitle "Assigned Constraints"
WndTxt2Float h9001, QTMP
PrintFloat QTMP,            "GPR Assigned Limit (V)"
WndTxt2Float h9002, QTMP
PrintFloat QTMP,            "E-Mesh Assigned Limit (V)"
WndTxt2Float h9003, QTMP
PrintFloat QTMP,            "E-Step Assigned Limit (V)"
PrintTitle "Final Answer Calculations (Repeated from above)"
PrintFloat GPR_Calc,        "'GPR' Calculated Value (V)"
PrintFloat EM_Calc,        "'E-Mesh' Calculated Value (V)"
PrintFloat ES_Calc,        "'ES' Calculated Value (V)"

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

@ExitPrint:
ret
Do_Print ENDP
Posted on 2005-07-26 08:37:59 by JimmyClif
JimmyClif:

Oh, that's what I want!

Thank you.
Posted on 2005-07-26 08:42:43 by seasea