Function to Print the Contents of a Dialog

Ideas for new features & functions

Moderators: JRL, Dorian Ellis

Function to Print the Contents of a Dialog

Postby JRL » Wed Aug 31, 2011 1:59 am

This was discussed a year ago HERE but things sometimes get overlooked if they're not in the proper place.

Is there any chance of getting a built in print function that could print the contents of the working area of a dialog and provide a few controls for size, location and orientation for example? Or just as good, is there any way to use a library function or vbscript to print a dialog. The problem I have with the methods described in the above mentioned thread are that there are no controls for even simple choices such as portrait vs landscape.
JRL
Automation Wizard
 
Posts: 2760
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Postby JRL » Fri May 18, 2012 6:07 am

Here is a concept using HTA. Still not perfect but provides the standard windows print dialog box so that some controls are available such as portrait vs landscape and number of copies.

The "Print" subroutine should be usable as-is for most dialog boxes. You just need to put a print button in your dialog then set up a dialog handler to call the "Print" subroutine when the print button is selected. The dialog handler needs to have three parameters. The name of the dialog being printed, the name of the print button (or any other object you might choose to use). The third and last parameter is an optional "1" if you want the print process to autocomplete printing to the default printer rather than displaying the standard windows print dialog.

You will probably find that there is header and footer information printing along with the dialog. The header and footer are from Internet Explorer. hta is tied to IE and you can control the header and footer contents via Internet Explorer > File > Page Setup...

Hope this makes sense and that someone finds it useful.

Code: Select all
Dialog>Dialog1
object Dialog1: TForm
  Left = 356
  Top = 101
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  BorderStyle = bsDialog
  Caption = 'PrintConcept'
  ClientHeight = 263
  ClientWidth = 439
  Color = clWhite
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 441
    Height = 265
    Caption = 'Panel1'
    Color = clOlive
    ParentBackground = False
    TabOrder = 0
    object MSButton1: tMSButton
      Left = 178
      Top = 203
      Width = 75
      Height = 25
      Caption = 'Print'
      TabOrder = 2
      DoBrowse = False
      BrowseStyle = fbOpen
    end
    object Panel2: TPanel
      Left = -1
      Top = 2
      Width = 185
      Height = 41
      Caption = 'Panel2'
      TabOrder = 0
    end
    object Panel3: TPanel
      Left = 252
      Top = 220
      Width = 185
      Height = 41
      Caption = 'Panel3'
      TabOrder = 1
    end
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,,OnClose,Quit
                                          //Usage:
                                          //Print(dialog name,Print button name,0/1 autocomplete)     
AddDialogHandler>Dialog1,msButton1,OnClick,Print(Dialog1,msButton1,0)

Show>Dialog1,res1

SRT>Quit
  DeleteFile>%PrintConcepthtafile%
  KillProcess>mshta.exe
  Exit>0
END>Quit

SRT>Print
If>Xoffset={"Xoffset"}
Dialog>BorderSizeFinderDialog
object BorderSizeFinderDialog: TForm
  object Button1: TButton
    Left = 0
    Top = 0
  end
end
EndDialog>BorderSizeFinderDialog
EndIf
  Let>WIN_USEHANDLE_hold=WIN_USEHANDLE
  SetDialogProperty>%Print_var_1%,%Print_var_2%,Visible,False
  Let>WIN_USEHANDLE=1
    GetWindowPos>BorderSizeFinderDialog.handle,Dx,Dy
    GetWindowPos>BorderSizeFinderDialog.button1.handle,Bx,By
    Let>Xoffset=%Bx%-%Dx%
    Let>Yoffset=%By%-%Dy%
    GetWindowPos>%Print_var_1%.handle,WinX,WinY
    GetWindowSize>%Print_var_1%.handle,WinW,WinH
  Let>WIN_USEHANDLE=WIN_USEHANDLE_hold
  ScreenCapture>{%WinX%+%Xoffset%},{%WinY%+%Yoffset%},{%WinX%+%WinW%-%Xoffset%},{%WinY%+%WinH%-%Xoffset%},%temp_dir%PrintConcept.bmp
  SetDialogProperty>%Print_var_1%,%Print_var_2%,Visible,True
  Let>PrintConcepthtafile=%temp_dir%PrintConceptimage.hta
  IfFileExists>%file1%
    DeleteFile>%file1%
  EndIf

  WriteLn>%PrintConcepthtafile%,wres,<title>~PrintConcept~</title>
  WriteLn>%PrintConcepthtafile%,wres,<HTA:APPLICATION
  WriteLn>%PrintConcepthtafile%,wres,BORDER="none"
  WriteLn>%PrintConcepthtafile%,wres,SCROLL="no"
  WriteLn>%PrintConcepthtafile%,wres,INNERBORDER="no"/>
  WriteLn>%PrintConcepthtafile%,wres,<img src="%temp_dir%PrintConcept.bmp"  width="%WinW%" height="%WinH%">
  WriteLn>%PrintConcepthtafile%,wres,<script>window.resizeTo(%WinW%, %WinH%);window.moveTo(-32000, 0)</script>
  Let>Rp_Wait_hold=Rp_Wait
  Let>Rp_Wait=0
  Run>mshta.exe %PrintConcepthtafile%
  Let>Rp_Wait=Rp_Wait_hold
  WaitWindowOpen>~PrintConcept~
  SetFocus>~PrintConcept~
  Wait>0.5
  Press Ctrl
    Send>p
  Release Ctrl
  Let>WF_TYPE_hold=WF_TYPE
  Let>WF_TYPE=0
  WaitWindowOpen>Print
  SetFocus>Print
  Let>WF_TYPE=WF_TYPE_hold
 
  If>Print_var_3=1
    Wait>0.5
    Press ALT
    Send>p
    Release ALT
  EndIf
END>Print
JRL
Automation Wizard
 
Posts: 2760
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa


Return to Enhancement Suggestions

Who is online

Users browsing this forum: No registered users and 0 guests