Filename in Edit(WM_EDIT) box in Download Diaglog window from website in VBA could be extracted by getwindowtext ?

Dear Expert,

I'am doing automation for download 100 files from one website, before
clicking save button after clicking download bar in the website, I would like
to see the filename is matched to my expect or not  before I  click the save button.
SO I try to read the filename in the download popup daiglog window's "Edit"(WM_Edit) box.
For example, the following simplify code, And I use SpY++ to check the download
diaglog  windows 's HWND and found "edit" box 's  HWND shown
on SPY++ too, but I could not extract the title name(it means the filename in edit box)
by getwindowtext with  getwindowtextlength. I can get the title of "button" class name
in the download popup dialog window but always failed to get the title of the "edit" (WM_EDIT)  classname
whose title name  should be same as  the default download  filename sent or provided   by the website

Sub test()
Dim hdlg as string
hdlg = findwinodw(vbnullstring, "Download files Window" ' That appears after clicking the
download bar in the webiste
hdlg2 =findwindowEx(hdlg, 0, "Edit", vbnullstring) ' There is edit box for users to change the filename
from the default filename  but it is failed  and hdlg2 alwayws is 0
debug.print Getwindowtextlength(hdgl2), but it also failed, it showed nothing
End Sub

PLease advise, what is wrong with the code, WHen I  test the "button" class name that is
okay I can get the title of "SAVE" with  debug.print but not for "Edit" class name
SPy++ show the title of the "Edit box" is same as filename in Edit box in the daiglog windows,
 it should be really easy to extract but it is fail and I hung up here.


LVL 13
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

That won't work simply because your not walking the chain deep enough. Example using the Control ID on (Windows XP)
Option Explicit

Private Const WM_GETTEXT = &HD

Private Declare Function FindWindowW Lib "user32" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
Private Declare Function SendDlgItemMessageW Lib "user32" (ByVal hDlg As Long, ByVal nIDDlgItem As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Public Function GetSavasFilename(ByVal szTitle As String) As String

  Dim hDlg As Long
  Dim cb As Long
  Dim Buffer(260 * 2) As Byte
  hDlg = FindWindowW(0, StrPtr(szTitle))
  If hDlg = 0 Then
    Exit Function
  End If
  cb = SendDlgItemMessageW(hDlg, &H47C, WM_GETTEXT, 260, VarPtr(Buffer(0)))
  GetSavasFilename = Left$(Buffer, cb)

End Function

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
duncanb7Author Commented:
it works fine and thanks for all of you to reply
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
VB Script

From novice to tech pro — start learning today.