Hi all . I am trying to send a click to external button. The following code works if i use
instead of
However the value WinCap comes from combobox but needs to modifed before it used . The messagebox shows that replace function changed the data corectly but for some reason when i test it the button on external applicaton doesn't get clicked!! Messagebox shows value of WinCap and it is exact name of the window holding the button!! Could any one tell me why this strange thing happens and how to fix it? since i don't want to manually type the title of window each time.Looking forward for replies.Thanks
'WinCap = "Application session for david"
instead of
WinCap = "Application session for" & Replace(Combo1.Text, "- IT Department", "")
However the value WinCap comes from combobox but needs to modifed before it used . The messagebox shows that replace function changed the data corectly but for some reason when i test it the button on external applicaton doesn't get clicked!! Messagebox shows value of WinCap and it is exact name of the window holding the button!! Could any one tell me why this strange thing happens and how to fix it? since i don't want to manually type the title of window each time.Looking forward for replies.Thanks
Code:
Private Sub Command1_Click()
Dim iHnd As Long
On Error Resume Next
iHnd = FindWindow(WindowClass, Combo1.Text)
Dim WinCap As String
'WinCap = "Application session for david"
'unfortuenly the next line doesn't work
WinCap = "Application session for" & Replace(Combo1.Text, "- IT Department", "")
'MsgBox WinCap
iHnd = getAppSubForm("#32770", WinCap, "Button", 2) 'find button
PostMessage iHnd, WM_KEYDOWN, 32, 0 'send space to trigger button press
PostMessage iHnd, WM_KEYUP, 32, 0 'release space
End Sub
Private Function getAppSubForm(ByVal TargetWinClass As String, _
ByVal TargetWinCaption As String, ByVal TargetSubClass As String, _
ByVal TargetSubClassIndex As Integer) As Long
'set variables in module
mTargetWinClass = TargetWinClass
mTargetWinCaption = TargetWinCaption
mTargetSubClass = TargetSubClass
mTargetSubClassIndex = TargetSubClassIndex
'set variables for EnumWindows function
Dim lRet As Long
Dim lParam As Long
'Enum sub windows to get hnd for target
lRet = EnumWindows(AddressOf FindSubWinds, lParam)
'return target hnd
getAppSubForm = mSubFormHnd
End Function