Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

API to supply PrintToFile directory

Status
Not open for further replies.

Pica77

Programmer
Jan 18, 2002
3
0
0
US
Hello,
I have a VB app that saves to a file by printing to a printer defined as a "Print to File" printer. The problem is that Windows always displays a dialog box so the user can fill in the directory and filename to save to. Is there an API that will let me set the file save location in the code and prevent the dialog box from appearing?
Thanks,
 
you should be able to set this manually in the Printers window. Otherwise, look into writing to the registry, rather than using API's
 
Found this on

Private Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" (ByVal lpClassName As String, ByVal _
lpWindowName As String) As Long

Private Declare Function SendDlgItemMessage Lib "user32" _
Alias "SendDlgItemMessageA" (ByVal hDlg As Integer, ByVal _
nIDDlgItem As Long, ByVal Msg As Long, ByVal wParam As Long, _
ByVal lParam As Any) As Long

Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long _

Private Declare Function FindWindowEx Lib "user32" _ Alias "FindWindowExA" (ByVal hWnd1 As Long, _
ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As _
String) As Long

Const WM_SETTEXT = &HC
Const WM_SHOWWINDOW = &H18
Const WM_LBUTTONUP = &H202
Const WM_LBUTTONDOWN = &H201
Const BM_CLICK = &HF5


Dim aFile As String
Dim iii As Long
Dim hwnd As Long
Dim lObjhWnd As Long

hwnd = FindWindow(vbNullString, "Print To File")
If hwnd <> 0 Then
'Change according to what you need
aFile = &quot;D:\REPORTSERVER\OUTPUT\&quot; & _
Format(Now(), &quot;yymmddHhMmSs&quot;) & &quot;.rpt&quot;
iii = SendDlgItemMessage(hwnd, 1152, WM_SETTEXT, 0, aFile)
iii = SendMessage(hwnd, WM_SHOWWINDOW, 0, 0)
lObjhWnd = FindWindowEx(hwnd, 0, &quot;Button&quot;, &quot;OK&quot;)
iii = SendMessage(lObjhWnd, BM_CLICK, 0, 0)
DoEvents
End If
End Sub
 
this code doesn't work.
each time i launch it, it shows me an error message at the firrst line...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top