A couple of errors in your API declarations seem to be the problem. The
second ShowWindow param should be a Long not Integer.
Notice I changed the last SendMessage param to ByValue instead of ByRef.
You were passing a 0 which is interpreted as the memory location at
address ZERO.
Also remember that hWnds can be negative in WinNT or higher so the
standard check is against 0.
I have tested the code below and it works.
Option Compare Database
Option Explicit
Const WM_CLOSE = &H10
'Const SW_HIDE = 0
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As
Long)
'API use Phone Dialer to make call
Private Declare Function tapiRequestMake Call _
Lib "TAPI32.DLL " _
( _
ByVal DestAddress As String, _
ByVal AppName As String, _
ByVal CalledParty As String, _
ByVal Comment As String _
) _
As Long
'API find applcation by full caption
Private Declare Function FindWindow _
Lib "user32" _
Alias "FindWindow A" _
( _
ByVal lpClassName As String, _
ByVal lpWindowName As String _
) _
As Long
'API bring Window to foreground
Private Declare Function SetForegroundWi ndow _
Lib "user32" _
( _
ByVal hwnd As Long _
) _
As Long
'API set ShowWindow to hide window
Private Declare Function ShowWindow _
Lib "user32" _
( _
ByVal hwnd As Long, _
ByVal nCmdShow As Long _
)
'API send message to application
Private Declare Function PostMessage _
Lib "user32" _
Alias "PostMessag eA" _
( _
ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long _
) _
As Long
Private Function Hide_Window(App Caption As String)
Dim hwnd As Long
hwnd = FindWindow(vbNu llString, AppCaption)
If hwnd Then
Debug.Print hwnd
Debug.Print AppCaption
ShowWindow hwnd, 0
End If
End Function
Private Function Close_By_Captio n(AppCaption As String)
Dim hwnd As Long
hwnd = FindWindow(vbNu llString, AppCaption)
If hwnd <> 0 Then
'Bring to Front
SetForegroundWi ndow hwnd
'Close the app nicely
PostMessage hwnd, WM_CLOSE, 0&, 0&
End If
Exit_Here:
Exit Function
HandleErr:
Select Case Err.Number
Case Else
'modHandler.Log Err ("frm0Telephone "), ("Close_By_Capt ion")
End Select
Resume Exit_Here
End Function
Private Function CloseAPP(AppNam eOfExe As String, _
Optional KillAll As Boolean = False, _
Optional NeedYesNo As Boolean = True) _
As Boolean
Dim oProcList As Object
Dim oWMI As Object
Dim oProc As Object
CloseAPP = False
'create WMI object instance:
Set oWMI = GetObject("winm gmts:")
If IsNull(oWMI) = False Then
'create object collection of Win32 processes:
Set oProcList = oWMI.InstancesO f("win32_proces s")
'iterate through the enumerated collection:
For Each oProc In oProcList
'Debug.Print oProc.Name
'option to close a process:
If UCase(oProc.Nam e) = UCase(AppNameOf Exe) Then
NeedYesNo = False 'don't wan't msgbox
If NeedYesNo Then
If MsgBox("Kill " & oProc.Name & vbNewLine & "Are
you sure?", _
vbYesNo + vbCritical) = vbYes Then
oProc.Terminate (0)
CloseAPP = True
End If
Else
oProc.Terminate (0)
CloseAPP = True
End If
'continue search for more?
If Not KillAll And CloseAPP Then
Exit For 'oProc In oProcList
End If
End If
Next
Else
'report error
End If
Exit_Here:
Set oProcList = Nothing
Set oWMI = Nothing
Exit Function
HandleErr:
Select Case Err.Number
Case Else
'modHandler.Log Err ("frm0Telephone "), ("Close_APP" )
End Select
Resume Exit_Here
End Function
Private Sub Telephone_Numbe rs_DblClick(Can cel As Integer)
On Error GoTo HandleErr
Dim varDialWait As Variant
Dim varStart As Variant
Dim strDial As String
Dim lngRetVal As Long
Static blnDialing As Boolean 'prevent reentry into sub while dialing
DoEvents
blnDialing = False
If blnDialing Then Exit Sub
strDial = Me.TelNumber
lngRetVal = tapiRequestMake Call(Trim$(strD ial), "", "", "")
If lngRetVal = 0 Then
blnDialing = True
'varDialWait = DLookup("DialWa it", "tblPrefs")
'varDialWait = 8
Dim strMsg As String
Dim varReturn As Long, lngX As Long
strMsg = "You have 10 seconds to Pick up the Phone to Talk!" &
"..."
varReturn = SysCmd(acSysCmd InitMeter, strMsg, 10)
' Display message in status bar.
For lngX = 1 To 10
varReturn = SysCmd(acSysCmd UpdateMeter, lngX)
' Update meter.
Sleep 1000 ' sleep 1 second
Next lngX
varReturn = SysCmd(acSysCmd ClearStatus)
'For x = 1 To 6
'Me.statusbar = "...... 6 seconds to Pick up the Phone"
'varStart = Timer
'Do While Timer < varStart + varDialWait
' DoEvents
'Hide_Window ("Call Status") '<<=== this fails with Error
Number 49: Bad DLL calling convention
' Loop
End If
Exit_Here:
blnDialing = False
Close_By_Captio n ("Dialing") ' - works great
Close_By_Captio n ("Call Status") '- works great
Close_By_Captio n ("Phone Dialer") ' - does
'CloseAPP ("dialer.exe ")
Exit Sub
HandleErr:
Select Case Err.Number
Case 94 'Invalid Use of Null - if double-click on blank, open
dialer
Call Shell("c:\windo ws\dialer.exe", vbNormalFocus)
Exit Sub
Case Else
'modHandler.Log Err ("frm0Telephone "),
("Telephone_Num bers_DblClick")
End Select
Resume Exit_Here
End Sub
--
HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
"deko" <de**@hotmail.c om> wrote in message
news:eQ******** ***********@new ssvr29.news.pro digy.com...
If you do not have SPY++ send me a functioning MDB and I'll post the
Class name for the Dialog.
Hi Stephen,
It's on it's way...
Thanks!