I am trying to print to a PRN file from Crystal.
I have set up a PCL printer with FILE: as the port.
I have selected this printer in my Crystal template.
When I print it, a "Print to File" dialog box appears.
I am trying to programmatically add the OuputFile name and click OK.
I found this code (below) on FreeVBCode.com (http://www.freevbcode.com/ShowCode.asp?ID=2836
When I step through it, the SendDlgItemMessage step appears to work but the OutputFile text box remains blank. The SendMessage for clicking the OK button works.
I also attempted FindWindowEx and was able to find the text box, but again was unable to send a message to it. Someone also suggested EnumChildWindows, but I could not work out how to do that.
Any suggestions welcome. Please supply examples of any API call as I am struggling with the parameters.
A suggestion of how to print to file programmatically from Crystal without using the Print To File dialog would also solve my problem.
Intercept Print to File dialog box from VB and complete it.
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 = "D:\REPORTSERVER\test.prn"
iii = SendDlgItemMessage(hwnd, 1152, WM_SETTEXT, 0, aFile)
iii = SendMessage(hwnd, WM_SHOWWINDOW, 0, 0)
lObjhWnd = FindWindowEx(hwnd, 0, "Button", "OK")
iii = SendMessage(lObjhWnd, BM_CLICK, 0, 0)