Al Smith
Nov 6th, 2000, 06:45 PM
Hi,
I'm using EnumChildWindows and SendMessage to supply the password to Lotus Notes. (Code below) This works 9 times out of 10, but at times the SendMessage errors out with a subscript out of range. The EnumChildProc function seems to exit before all child windows are enumerated. I'm wondering if the parent window isn't fully loaded when the enum process starts.
Questions:
Does this seem to be the case?
If so, is there a way to tell if the parent is fully loaded?
If not what else might be causing this?
Note: the DoEvents placed throughout the code was an attempt to stop this.
Thanks,
Al.
Option Explicit
Dim lHwnd() As Long
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
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
Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lparam As Any) As Long
Declare Function EnumChildWindows Lib "user32" _
(ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lparam As Long) 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
Const WM_SETTEXT = &HC
Const WM_LBUTTONDOWN = &H201
Const WM_LBUTTONUP = &H202
Function EnumChildProc(ByVal hWnd As Long, ByVal lparam As Long) As Long
Static winnum As Integer
winnum = winnum + 1
ReDim Preserve lHwnd(winnum)
lHwnd(winnum) = hWnd
EnumChildProc = 1
End Function
Sub Main()
Start_Lotus
Find_Password_Window
Enter_Password
Click_OK
End Sub
Sub Start_Lotus()
Call ShellExecute(0&, "Open", "c:\lotus\notes\notes.exe", "", "", 1)
DoEvents
End Sub
Sub Find_Password_Window()
Dim retval As Long
ReDim lHwnd(1)
Do Until lHwnd(0) <> 0
lHwnd(0) = FindWindowEx(0, 0, vbNullString, "Enter Password")
DoEvents
Loop
retval = EnumChildWindows(lHwnd(0), AddressOf EnumChildProc, 0)
DoEvents
End Sub
Sub Enter_Password()
Dim sText As String
sText = "myPassword"
Call SendMessage(lHwnd(6), WM_SETTEXT, Len(sText), ByVal sText) 'subscript out of range at times
DoEvents
End Sub
Sub Click_OK()
Call PostMessage(lHwnd(7), WM_LBUTTONDOWN, 0, 0)
Call PostMessage(lHwnd(7), WM_LBUTTONUP, 0, 0)
End Sub
I'm using EnumChildWindows and SendMessage to supply the password to Lotus Notes. (Code below) This works 9 times out of 10, but at times the SendMessage errors out with a subscript out of range. The EnumChildProc function seems to exit before all child windows are enumerated. I'm wondering if the parent window isn't fully loaded when the enum process starts.
Questions:
Does this seem to be the case?
If so, is there a way to tell if the parent is fully loaded?
If not what else might be causing this?
Note: the DoEvents placed throughout the code was an attempt to stop this.
Thanks,
Al.
Option Explicit
Dim lHwnd() As Long
Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hWnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
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
Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lparam As Any) As Long
Declare Function EnumChildWindows Lib "user32" _
(ByVal hWndParent As Long, ByVal lpEnumFunc As Long, ByVal lparam As Long) 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
Const WM_SETTEXT = &HC
Const WM_LBUTTONDOWN = &H201
Const WM_LBUTTONUP = &H202
Function EnumChildProc(ByVal hWnd As Long, ByVal lparam As Long) As Long
Static winnum As Integer
winnum = winnum + 1
ReDim Preserve lHwnd(winnum)
lHwnd(winnum) = hWnd
EnumChildProc = 1
End Function
Sub Main()
Start_Lotus
Find_Password_Window
Enter_Password
Click_OK
End Sub
Sub Start_Lotus()
Call ShellExecute(0&, "Open", "c:\lotus\notes\notes.exe", "", "", 1)
DoEvents
End Sub
Sub Find_Password_Window()
Dim retval As Long
ReDim lHwnd(1)
Do Until lHwnd(0) <> 0
lHwnd(0) = FindWindowEx(0, 0, vbNullString, "Enter Password")
DoEvents
Loop
retval = EnumChildWindows(lHwnd(0), AddressOf EnumChildProc, 0)
DoEvents
End Sub
Sub Enter_Password()
Dim sText As String
sText = "myPassword"
Call SendMessage(lHwnd(6), WM_SETTEXT, Len(sText), ByVal sText) 'subscript out of range at times
DoEvents
End Sub
Sub Click_OK()
Call PostMessage(lHwnd(7), WM_LBUTTONDOWN, 0, 0)
Call PostMessage(lHwnd(7), WM_LBUTTONUP, 0, 0)
End Sub