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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing an Adobe Acrobat Viewer window in VB6 1

Status
Not open for further replies.

CruiseMan

Programmer
Nov 17, 2006
29
US
I am using the following code to print a .pdf file to my default printer in VB6, which works correctly, but it leaves an empty Acrobat Viewer window open even after the application closes. Does anyone know how to force this window to close through code?
(OS: WinXP SP3)

code example:

Call ShellExecute(hWnd, "Print", "C:\MISC\Limits.pdf", "", "", 0)
 
If the Acrobat Viewer window has a predictable caption, something like;

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

Public Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Public Const WM_CLOSE = &H10
Public Const WM_CANCELMODE = &H1F

Sub QuitIt()

Dim TargHwnd as Long
Do
TargHwnd = FindWindow(0&, "The Window Caption")
If TargHwnd Then
PostMessage TargetHwnd, WM_CANCELMODE, 0, 0&
PostMessage TargetHwnd, WM_CLOSE, 0, 0&
End If
Loop While TargHwnd 'loop in case there is more than one of them

End Sub

... may do the trick
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top