Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Just to let you know...what a great site you have. I posted a pretty generic question yesterday and have had 8 responses already, anyway thanks again and keep up the good work..."

Geography

Where in the world do Tek-Tips members come from?

Intercept Print to File dialog box - SendDlgItemMessage

jackied (Programmer)
16 Sep 04 5:32
Hello.
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.

Thanks
Jackie

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)
      DoEvents
   End If
End Sub

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close