News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

"Reverse engineering": Notepad's print preview

Started by NoCforMe, April 29, 2024, 07:43:33 AM

Previous topic - Next topic

jj2007

Quote from: NoCforMe on April 30, 2024, 06:05:51 AMThe idea is to show the print margins in relation to the page so one can set the margins accordingly.

optional: margins in mm, e.g. void PrintRtf(hMyEdit, 0, 20, 20, 15, 20)        ; left, top, right, bottom

The default values are ok for 99% of all cases. If not, test the margins with Notepad, and use them with your own program. The preview is not that precise anyway.

Printing images with PaintShop is a different use case: there you might need to center the image, or to make it much smaller than the default.

NoCforMe

Quote from: jj2007 on April 30, 2024, 06:10:29 AMThe default values are ok for 99% of all cases.
Except that since I'm "rolling my own here" (i.e., not using PrintSetupDlg()), the defaults are (0,0,0,0), so I need to be able to set reasonable margins. (When I print my code, for instance, if I use a 3-hole punch so I can put the pages in a notebook it punches through some of the text.)

Besides, I can't use that dialog because I'm using my own (non-standard) headers and footers.
Assembly language programming should be fun. That's why I do it.

jj2007

Quote from: NoCforMe on April 30, 2024, 06:14:49 AMnot using PrintSetupDlg()), the defaults are (0,0,0,0)

You are not obliged to use a dialog, and you are not obliged to use these defaults. This code does not use a dialog, it just tells you how many pages were printed:

GuiParas equ "Hello World", w500, h400, b LiteBlueGreen, icon Printer    ; width+height, background colour
include \masm32\MasmBasic\Res\MbGui.asm
  GuiControl MyEdit, "RichEdit", wCL$(), bcol LiteYellow, fcol Black, font -14    ; load file in commandline
Event Key
  .if CtrlVKey()==-VK_P
      MsgBox 0, Str$("%i pages printed", PrintRtf(hMyEdit, 0, 20, 20, 150, 20)), "PrintRtf:", MB_OK
  .endif
GuiEnd

PrintRtf(hMyEdit, 0, 20, 20, 150, 20)  ; handle, mode0=no dialog, left20, top20, right150, bottom20