Re: External Form Values?
My guess would be that you used the FindWindow API to get a handle to the topmost window of the application and the the FindWindowEx API to find the handles of the username and passwords fields, then the SendMessage API to set values into those fields etc.
Re: External Form Values?
Thank you. This does help somewhat. I used a program that upon putting my cursor over the field (submit button, text box) it would give me the variables name or value. And from there I would use something like textBox = 'johnny' AIMtextbox = textBox. I hope this helps clarify what I was talking about a little. Thanks again and please let me know if you have any further suggestions.
Re: External Form Values?
What Doogle was getting at I believe, is that VB cannot do this without APIs.
1. You have to locate the top-level target window. Which means you have to have some information about that window, like it's caption, class name, handle or something else that would allow you to a) determine if it's even present and b) distinguish it from other similar windows
2. Then you'd have to search its children, grand children, etc until you found the specific target window(s) you are looking for. Again, these must be distinguishable either by class name, ID (not all windows have IDs), caption, or something else
3. If the target windows are textboxes, then you'd use SetWindowText or SendeMessage APIs to populate the textboxes. In order to use those APIs, you need the target hWnd, which is why the 1st two steps must be completed successfully.
Now your app you were talking about, did most of this stuff behind the scenes. On the GUI, sure you may have just had to enter a little information, including what to set the textbox values at, but behind the GUI is where the above logic and APIs would have been used.
You can search this forum for more help, using terms like: remote click or control another app
Re: External Form Values?
Thanks for your help yall. I was looking for the handles of other windows and the program with a GUI that identifies these handles. I found a link to said program in this site. Yall have been very helpful, thanks again.
Re: External Form Values?
I was putting a simple example together
Program 1:
Code:
Option Explicit
Private Sub cmdLogon_Click()
If txtUsername.Text = "Username" And txtPassword.Text = "Password" Then
MsgBox "Logon Successful"
End If
End Sub
Private Sub cmdLogon_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Debug.Print "Mouse Down"
End Sub
Private Sub cmdLogon_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
Debug.Print "Mouse Up"
End Sub
Private Sub Form_Load()
txtUsername.Text = ""
txtPassword.Text = ""
Me.Caption = "Doogles Folly"
End Sub
Just a Form with a couple of textboxes (txtUsername, txtPassword) and a commandbutton (Caption = Logon)
Program2
Code:
Option Explicit
Private Const WM_SETTEXT As Long = &HC&
Private Const BM_CLICK As Long = &HF5&
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
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 Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Sub cmdSend_Click()
Dim lngMain As Long
Dim lngChild As Long
Dim lngReturn As Long
lngMain = FindWindow(vbNullString, "Doogles Folly")
If lngMain <> 0 Then
lngChild = FindWindowEx(lngMain, 0&, vbNullString, "txtUsername")
If lngChild <> 0 Then
SendMessage lngChild, WM_SETTEXT, 0&, ByVal "Username"
CloseHandle lngChild
lngChild = FindWindowEx(lngMain, 0&, vbNullString, "txtPassword")
If lngChild <> 0 Then
SendMessage lngChild, WM_SETTEXT, 0&, ByVal "Password"
CloseHandle lngChild
lngChild = FindWindowEx(lngMain, 0&, vbNullString, "Logon")
If lngChild <> 0 Then
SendMessage lngChild, BM_CLICK, 0&, 0&
' SendMessage lngChild, BM_CLICK, 0&, 0&
CloseHandle lngChild
End If
End If
End If
CloseHandle lngMain
End If
End Sub
The idea being that you run Program1 and then Program2 which populates the two textboxes and clicks the CommandButton in Program1.
The interesting thing I found is that the BM_CLICK message causes MouseDown and MouseUp events for the CommandButton but the _Click event is not triggered. Sending BM_CLICK twice does cause the _Click event to trigger.
I guess there's a reason for that - but I don't know what it is :)
Re: External Form Values?
Quote:
Originally Posted by
Doogle
...The interesting thing I found is that the BM_CLICK message causes MouseDown and MouseUp events for the CommandButton but the _Click event is not triggered. Sending BM_CLICK twice does cause the _Click event to trigger.
I guess there's a reason for that - but I don't know what it is :)
P.S. I fiind it more reliable to send the parent a WM_Command message with a BN_CLICKED submessage. Requires a bit more code:
1. Get target handle of button
2. Get its Parent: GetParent API
3. Get button's control ID: GetWindowLong API with GWL_ID parameter
4. SendMessage or SendMessageTimeOut API to parent:
SendMessage buttonParentHWnd, WM_COMMAND, BtnCtrlID, ByVal BtnHWnd
Regarding failure with BM_CLICK, here's what MSDN says
Quote:
If the button is in a dialog box and the dialog box is not active, the BM_CLICK message might fail. To ensure success in this situation, call the SetActiveWindow function to activate the dialog box before sending the BM_CLICK message to the button.
Edited: Why are you using CloseHandle? It isn't appropriate for FindWindow/FindWindowEx. FindFirstFile, sure.
Re: External Form Values?
Quote:
Originally Posted by
LaVolpe
Edited: Why are you using CloseHandle? It isn't appropriate for FindWindow/FindWindowEx. FindFirstFile, sure.
You're absolutely right. Just my age,I think :)