Hey, I reciently did a first time hack at making a print function for a program im working on.. Surprisingly i got it going the first time.. but my problem is while the text formating on one printer looks good.. when i use the same code on another, the text is 2x the size as the first...?? So this tells me i need to find the printer's x and y max bits per page somehow and scale my text accordingly.. but how?? Where is this info found??

Here is my existing code...
Do_Print PROTO :DWORD,:DWORD,:DWORD


COLUMN_1 equ 100
COLUMN_2 equ 2100
LINE_WIDTH equ 100

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

add yP, LINE_WIDTH

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

add yP, LINE_WIDTH

ENDM

PrintTitle MACRO string:REQ
LOCAL szMessage

.data
szMessage BYTE string, 0
.code

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

add yP, 2*LINE_WIDTH

ENDM


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

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

.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

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

; 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.

; 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


Thanx again...

:alright:
NaN
Posted on 2001-07-28 13:11:11 by NaN
Surprised now one caught this one.. the answer is EZ.. just didnt see it at first... I was hunitng for an API or a sturcture to say the X and Y extence of the printer im using...

The answer is in basic GUI theory... I have a hDC to my printer... so i need to check it for ITS x and y extence... Two calls to GetDeviceCaps and its all fixed...

Here is the proper code, that will suport on any printer...



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


If you can use it.. Enjoy!

:alright:
NaN
Posted on 2001-07-28 16:25:39 by NaN