1

I'm quite new to this and have been fumbling my way through creating an excel document that communicates with one of our external applications.

I've been through a tutorial of using FindWindowEX to find the specific buttons/boxes of this application and have managed to successfully insert text into one of the forms.

I hit a roadblock when trying to "click" a button, and i think the problem is that the application i'm trying to communicate with doesnt have unique class names.

enter image description here

From the picture you can see that almost everything is called "WindowsForms10.Window.8.app.0.2004eee"

Which means that i can insert text into the very first and only text box but can't dive any deeper to get hold of the buttons which i need to "click" in order to search.

Current code is as follows: I don't need to open the application as it is always up from startup.

Sub Runapplication()


DoEvents
Hwindow2 = FindWindow(vbNullString, "General Account Enquiry")


'Account Number
Account_Number = FindWindowEx(Hwindow2, 0&, "WindowsForms10.EDIT.app.0.2004eee", vbNullString)
Accountnumber = ThisWorkbook.Sheets("Sheet1").Range("A1")

Call SendMessageByString(Account_Number, WM_SETTEXT, 0, Accountnumber)


DoEvents


Account1 = FindWindow(vbNullString, "csEditAccount")
Account = FindWindowEx(Hwindow2, 0&, "WindowsForms10.Window.8.app.0.2004eee", vbNullString)

'Call EnableWindow(Account, True)
Call SendMessage(Account, WM_LBUTTONDOWN, 0, ByVal 0&)


End Sub

I have all the constants/declrations

Public Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" ( _
            ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Public Declare PtrSafe Function CloseWindow Lib "user32" (ByVal hWnd As Long) As Long

Public Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" ( _
            ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
            lParam As Any) As Long

Public Declare PtrSafe Function SendMessageByString Lib "user32" Alias "SendMessageA" ( _
            ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
            ByVal lParam As String) As Long

 Public Declare PtrSafe 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


Public Declare PtrSafe Function FindWindowEx Lib "user32" _
            Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, _
            ByVal lpsz1 As String, ByVal lpsz2 As String) As Long

Public Declare PtrSafe Function EnableWindow Lib "USER32.dll" ( _
            ByVal hWnd As Long, _
            ByVal fEnable As Long) As Long


            Public Const SW_NORMAL As Long = 1
            Public Const WM_CLOSE As Long = &H10
            Public Const BM_CLICK As Long = &HF5
            Public Const WM_KEYUP As Long = &H101
            Public Const WM_SETTEXT = &HC
            Public Const LB_FINDSTRING = &H18F
            Public Const WM_LBUTTONDOWN = &H201

Any help would be greatly appreciated, i almost went insane yesterday scouring the internet trying to find an answer to this problem,

Thank you!

6
  • 1
    EnumChildWindows can help, but you have more information available in your image than you claim to have. You have caption (text) content, the class (EDIT, STATIC, BUTTON, etc.). I can see you have a button which is labeled Get Acct... with an HWND of 000107A0, for instance. Commented Aug 9, 2017 at 2:03
  • Hi Ken, yeh i was hoping that i could somehow incorporate the handle or any other information into the "findwindowex" and that was mostly what i spent my hours searching for yesterday but didn't come up with anything other than a vague hint that findwindowEX may not be what i should be using. Commented Aug 9, 2017 at 2:07
  • Does your Windows 8 app implement IAccessible? You can execute an IAccessible. Commented Aug 9, 2017 at 2:13
  • "WindowsForms10.Window.8.app.0.2004eee" is the parent one, can you try to edit one of the child objects, Also try to use the Instr(WindowsForms10.Window.8.app.0.2004eee) so that it will search for the part of the text provided and not the word itself. Thanks (Please note that i am not an expert in this, but i want to know what will be the output) Commented Aug 9, 2017 at 6:12
  • I'm not quite sure how to implement the Instr that you mentioned Nishit? The Main problem that i'm having is that in order to navigate to the "Get Accnt" window, i have to navigate from the parent window "General account Enquiry" class: WindowsForms10.EDIT.app.0.2004eee, and then to a child window which has the exact same class name in order to get to the button "Get Acct" Commented Aug 9, 2017 at 7:24

1 Answer 1

1

Whilst I sympathise that many windows have the same class, isn't the case that the window you want to manipulate (mimic click) will always appear in the same place in a sequence. So if you wanted to hit the third button then won't it always be the third button. Even if buttons carry the same class as textboxes and so actually the one you wanted was the 8th in a superset of buttons and textboxes then it will still always be 8th.

So just enumerate through (using EnumChildWindows) until you find your target.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Meaden, i think this is definitely the route to go with, i'm gonna have to do some searching to figure out exactly how to pull it off, but thank you for the direction

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.