Solved

SendKeys or SendMessage??

Posted on 2001-06-15
6
827 Views
Last Modified: 2008-03-17
I have a simple program which sends text to the user's default printer. The default printer is set to an Acrobat PDF writer. The problem is that when the data is sent to the printer, the printer prompts for an file name to save the file as. The default file name is fine. The only problem I am having is that I am unable to SendKeys or SendMessage to Acrobat's save dialog box to simply accept the default name by passing the ENTER key (or ALT-S would work too).

Please help as soon as possible.

Thank you,

-Keith
0
Comment
Question by:KeithAtWork
6 Comments
 
LVL 3

Expert Comment

by:jrspano
ID: 6196631
are there any settings you can send with your call to the printer?  like pdfprinter.print "filenamehere" ?  I am not familiar with the pdf writer, but i would bet that there are values you can pass to it to save to a certain place and not have it ask you where
0
 
LVL 18

Accepted Solution

by:
bobbit31 earned 300 total points
ID: 6196770
this should do it:

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
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Const WM_KEYDOWN = &H100
Private Const WM_KEYUP = &H101
Private Const VK_RETURN = &HD

Private Sub Command1_Click()

    Dim hWnd As Long
    Dim lRes As Long
   
    hWnd = FindWindowEx(0, 0, vbNullString, "Print")
    MsgBox hWnd
    lRes = SendMessage(hWnd, WM_KEYDOWN, VK_RETURN, 1)
    lRes = SendMessage(hWnd, WM_KEYUP, VK_RETURN, 1)
   
    MsgBox lRes
   
End Sub

note in the findwindowex call "Print" is the title of the window
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6196775
obviously you don't need to msgbox hWnd and lRes (for your testing, hWnd should be non-zero and lRes should be 0
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6196861
hearing...
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6196899
Update to version 4.0.5.0
I did this with OK results:
' Using pdf.ocx

Private Sub Form_Click()
With Pdf1
    .LoadFile "d:\iFtpSvc\ftpserv.pdf"
    .printWithDialog
End With
SendKeys "{ENTER}"
End Sub
0
 

Author Comment

by:KeithAtWork
ID: 6196950
Thanks for your quick response and help!

-Keith
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now