Hello,
As a part of my project, I need to print Active application in Vb.net. For example, if web browser is currently active Application then it should print that web page. It can be done by simulating Key Press (Ctrl + P without actually pressing it) or using Print library. This application is triggered by Shortcut using AutoHotKey, So this process runs in background. Here is code..
Public Class Class1
Public Shared Sub Main()
Dim filePath As String = "C:\Users\AG\Desktop\SCaptur.png"
CMD.ToPDFCreator()
CMD.PrintDocument()
CMD.ChangeBack()
End Sub
End Class
Public NotInheritable Class CMD
#Region " Methods "
Public Shared Function ToPDFCreator()
Dim p As Process = New Process()
Dim pi As ProcessStartInfo = New ProcessStartInfo()
pi.Arguments = " " + "/C" + " " + "RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n" + " " + "PDFCreator"
pi.FileName = "cmd.exe"
p.StartInfo = pi
p.Start()
End Function
Public Shared Function PrintDocument()
System.Windows.Forms.SendKeys.Send("^P")
End Function
Public Shared Function ChangeBack()
Dim p As Process = New Process()
Dim pi As ProcessStartInfo = New ProcessStartInfo()
pi.Arguments = " " + "/C" + " " + "RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n" + " " + """" + "HP DeskJet" + """"
pi.FileName = "cmd.exe"
p.StartInfo = pi
p.Start()
End Function
#End Region
End Class
This code show error:
SendKeys cannot run inside this application because the application is not handling Windows messages. Either change the application to handle messages, or use the SendKeys.SendWait method.
Can any one tell me, How to resolve this issue?
Is there any other method to print active application?