Click to See Complete Forum and Search --> : FindWindowEx (I've Lost Sleep over This)
Rh0ads
Feb 26th, 2001, 03:33 PM
well i haven't lost sleep but it's driven me crazy. Okay here's some code (I'm using the program "Calculator" for an example):
dim a&
dimb&
a& = FindWindowEx(0&, 0&, "SciCalc", vbNullString)
b& = FindWindowEx(a&, 0&, "button", vbNullString)
in that code, how do i tell what button's handle will be in b&?
It will be the 1st button, but why not just specify what button you want? It will be a lot easier.
For example, use this to find the division button. (I marked my changes in red)
b& = FindWindowEx(a&, 0&, "button", "/")
Lord Orwell
Feb 26th, 2001, 11:34 PM
If for some reason, that doesn't work, this code, given the handle returned in your code, will return the caption of the handle.
Declare Function SendMessageByNum& Lib "user32" Alias "SendMessageA" (ByVal _
Hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam 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)
Public Const WM_GETTEXT = &HD
Public Const WM_GETTEXTLENGTH = &HE
Function GetTextFromWindow(WindowHandle As Long) As String
Dim buffer As String, Length As Long
Length& = SendMessageByNum(WindowHandle&, WM_GETTEXTLENGTH, 0&, 0&)
buffer$ = String(Length&, 0&)
Call SendMessageByString(WindowHandle&, WM_GETTEXT, Length& + 1, buffer$)
GetTextFromWindow$ = buffer$
End Function
If done properly, passing the final argument of FindwindowEx shouldn't cause a problem.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.