'*
'* Copyright (C) 2016 CADCAM-Services Franz Reiter (franz.reiter@cadcam.co.at)
'*
'* This program is free software; you can redistribute it and/or modify
'* it under the terms of the GNU General Public License as published by
'* the Free Software Foundation; either version 2 of the License, or
'* (at your option) any later version.
'*
'* This program is distributed in the hope that it will be useful,
'* but WITHOUT ANY WARRANTY; without even the implied warranty of
'* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'* GNU General Public License for more details.
'*
'*
' send file to printer; MS-Windows.
' compile with vbc MS_print.vb
' start with MS_print <fNam>

 
Imports System.Printing
Imports System.Drawing.Printing
Imports System.Runtime.InteropServices

Module Module1


'=========================================================
  Sub Main(ByVal cmdArg() As String)
'=========================================================
    Dim opd As New System.Windows.Forms.PrintDialog
    Dim odoc As New System.Drawing.Printing.PrintDocument
    'Dim rph As New RawPrinterHelper ' needs friendclass RawPrinterHelper .. ??

    System.Console.WriteLine ("MS_print ..")
    

    ' First paramter must be filename

    'Dim ps As New LocalPrintServer()  - no support under .net


    If Ubound(cmdArg) < 0 then
      MsgBox ("ERROR: First paramter must be filename ..",,)
      End
    End If


    'System.Console.WriteLine(opd.PrinterSettings.PrinterName)


    ' init & show printerDialog
    'opd.ShowHelp = True
    'opd.AllowPrintToFile = True

    'odoc.DocumentName = cmdArg(0)
    'odoc.PrinterSettings.PrintFileName = cmdArg(0)

    if odoc.PrinterSettings.isValid then
      System.Console.WriteLine (" .. settings OK ..")
    Else
      MsgBox ("ERROR printersettings.",,)
      End
    End If

    'opd.Document = odoc
    'opd.PrinterSettings = odoc.PrinterSettings

    opd.PrinterSettings.PrintFileName = cmdArg(0)
    opd.PrinterSettings.FromPage = 1
    opd.PrinterSettings.ToPage = 1

    if opd.PrinterSettings.isValid then
      System.Console.WriteLine (" .. settings OK ..")
    Else
      MsgBox ("ERROR printersettings.",,)
      End
    End If

    If opd.ShowDialog = Windows.Forms.DialogResult.OK then
      'do_print__ (opd.PrintToFile, cmdArg(0))
      'odoc.Print ()
      'rph.SendFileToPrinter(opd.PrinterSettings.PrinterName, cmdArg(0))
    End If

  End Sub


'=========================================================
  Sub do_print__(PrintToFile As Boolean, fNam as String)
'=========================================================

    System.Console.WriteLine ("print " & fNam)
    System.Console.WriteLine ("  printToFile = " & PrintToFile)

    'odoc.Print ()
 
  End Sub


End Module

' EOF
