0

I have seen a tutorial of how to set text to external application using API and I tried this code .. There is no error but it doesn't work as expected

Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal 
lpClassName As String, ByVal lpWindowName As String) 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 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 SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd 
As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" 
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam 
As String) As Long


Const SW_NORMAL = 1
Const WM_SETTEXT = &HC

Sub Test()
Dim x, hwnd As Long, TLogin As Long, subWindow As Long

'hwnd = FindWindow(vbNullString, "Untitled - Notepad")
x = ShellExecute(hwnd, "open", "C:\Program Files\Skype\Phone\Skype.exe", 0, 
0, SW_NORMAL)
If x = 2 Or x = 3 Then Exit Sub

Do
    DoEvents
    hwnd = FindWindow("TLoginForm", vbNullString)
Loop Until hwnd > 0

Application.Wait Now + TimeValue("00:00:03")

'First Try
'    TLogin = FindWindowEx(hwnd, 0&, "TLoginAppControl", vbNullString)
'    subWindow = FindWindowEx(TLogin, 0&, "Shell Embedding", vbNullString)
'    subWindow = FindWindowEx(subWindow, 0&, "Shell DocObject View", vbNullString)
'    subWindow = FindWindowEx(subWindow, 0&, "Internet Explorer_Server", vbNullString)
'    Call SendMessageByString(subWindow, WM_SETTEXT, 0, "HelloWorld")


'Second Try
'    TLogin = FindWindowEx(hwnd, 0&, "TLoginControlBar", vbNullString)
'    Call SendMessageByString(TLogin, WM_SETTEXT, 0, "HelloWorld")

'Third Try
TLogin = FindWindowEx(hwnd, 0&, "TNativeLoginControl", vbNullString)
Call SendMessageByString(TLogin, WM_SETTEXT, 0, "HelloWorld")
End Sub

In the code there are three tries but none of them enables me to set text to the skype name .. This is screenshot of Spy++ enter image description here

And when I used Spy++ to search for the desired window I got this and found that "HelloWorld" became a caption for this window .. but no clue for what's in this window enter image description here

braX
  • 11,506
  • 5
  • 20
  • 33
YasserKhalil
  • 9,138
  • 7
  • 36
  • 95
  • Can you include the tutorial link? – QHarr Oct 20 '18 at 20:11
  • I don't see the expected objects e.g. combobox within the class Windows.UI.Core.CoreWindow for text input. You may not of course have the same Windows tree as I have. – QHarr Oct 20 '18 at 20:15
  • Thanks a lot for reply. This is the link [link](https://www.youtube.com/watch?v=3oSaFMypTs4&list=PL6OYc4rwKjcNirRW9cX4N1_2VfDnMdnOs&index=4) – YasserKhalil Oct 20 '18 at 20:19
  • @QHarr I didn't see the combobox too. What is the solution in that case? – YasserKhalil Oct 20 '18 at 20:20
  • Not sure without seeing the tutorial. +1 for the question though. You sure this hasn't come up before on SO? – QHarr Oct 20 '18 at 20:24
  • See if there is something more like [this](https://stackoverflow.com/questions/5714542/finding-using-the-currently-active-chatbox-in-the-skype-client-thru-the-winapi) but for login. – QHarr Oct 20 '18 at 20:30
  • 3
    To automate a UI, use [UI Automation](https://learn.microsoft.com/en-us/dotnet/framework/ui-automation/ui-automation-overview). This is the only way to automate windowless controls, as in your use case. – IInspectable Oct 20 '18 at 21:09
  • Doesn't look that that window class would be expected to respond to such a message. And you can't know whether there are errors since you fail to check for them. Try reading the documentation to learn how errors are signaled for winapi functions. Why aren't you using UI Automation? – David Heffernan Oct 20 '18 at 21:10
  • Thanks a lot. I am new to all these stuff. What's UI? .. – YasserKhalil Oct 20 '18 at 21:11
  • You can use websearch to answer that – David Heffernan Oct 20 '18 at 21:28

0 Answers0