Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I need to print Word Documents and MS Projects, without showing them. These are standard templates that just need to be printed and mailed to clients

 


  Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal _
       hwnd As IntPtr, ByVal lpOperation As String, ByVal lpFile As String, _
       ByVal lpParameters As String, ByVal lpDirectory As String, _
       ByVal nShowCmd As Integer) As Integer

   Public Function PrintFromShell(ByVal sFile As String) As Integer
       'use the shell command to print 
       Dim NewProcess As Process = New Process
       Dim hHandle As System.IntPtr
       Dim i As Integer
       Dim proc As Process

       proc.GetProcesses(Environment.MachineName)
       For Each proc In proc.GetProcesses
           If proc.ProcessName = Application.ProductName Then
               hHandle = proc.Handle
              
               Exit For
           End If
       Next

       i = ShellExecute(hHandle, "print", _
           sFile, vbNullString, sGlobTemplates, 0)

       Return i
   End Function

 

This words, but it shows the document as it prints it. I tried setting constant SW_Hide=0 but of course got the same result

 

Any idea what the new SW_Hide value in .Net should be?

Read the Fovean Chronicles

Because you just can't spend your whole day programming!

Posted
If you are using .Net why don't you use the System.Diagnostics.Process class? It will be much easier than calling into ShellExecute.

 

It wouldn't print at all

 

I am assuming process(sFile, "Print") - probably got that wrong

Read the Fovean Chronicles

Because you just can't spend your whole day programming!

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...