Ask Question Forum:
C
O
M
P
U
T
E
R
2
8
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Y-position of the mouse cursor
Attachment:===
How to find Java process window handler/ID/title in VBA

-My target data download website is Java Applet application in IE and it need user to mouse click
to the download bar to show-up small Java popup dowload window and enter a key of enter to comfirm
for each file save
-My project is I try to connect one data website page to download 500 huge exmaple.csv files in VBA
by IE.navigate and mouse-click simulation in order to download all files automatically without any
real hand mouse click. The problem is I need to click download bar in the data website page and
after-clicking the small Java popup window will be shown up. The issue is the time of shown-up the small
popup windows will be a little longer and vary so I need to put longer waiting time to solve the issue like
put Sleep(3000) before sendkeys {"enter") to confirm each file save that will waste a lot of time for waiting if download 500 files
I would like to know how to find out the small Java popup window process ID or handler so if it is
possible, I might put code to detect the small popup window process is ready or not. Once ready, go
to sendkeys to confirm each file save that will reduce the waiting time. Please revise the following
attached code area for my main download VBA code , loadfile() subroutine which is using
Sleep(3000) for waiting.
I tried to use Window API method to replace Sleep() like bGetwindows() subroutine code below
to get the window title and check whether the popup window is ready or not but it always report
the first data webpage and not foreground windows information. I use debug.print to print
out mystr variable, it report title of " *****-WIndows Internet Explorer" and not the one I want
that is "Download Trans.Log" Please view the Two windows image and be reminded the small Java windows
is forground windows of data website paga or on the top of webiste page by click the download bar in first
website page. Please ignore the screen capture stamp.
Next Method I tried to use API FindWindowsEX() but I am not familar with part and I need to do
some tuturial at this site http://www.downloadfreescript.com/source-code-detail-text/find-window-tutorial-part1-a-must-see-by-paul-zaczkowski-in-miscellaneous-visual-basic.htm
The Question:
1-Any good methed to Replace code of Sleep(3000) to reduce the waiting time ?
2- At bGetWindow_Click(), why it will debug.print the background window title instead of forground window
even use GetforgroundWindow in the VBA code ? it seems always report the parent process title
instead of child process. How to find out child process title or id ?
3- I have checked by Task Manage in windows, both is in process, Is it true API function could not
solve any Java Window issue ?
4- [ANyone know how to get Java application/process/windows title or ID in VBA ?
Please advise
Ducan
*************************************bGetwindow_Click()********************************
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Declare Function GetForegroundWindow Lib "user32" () As Long
Private Sub bGetWindow_Click()
Dim MyStr As String, AHwnd As Long
tWinName = "waiting..."
Do
AHwnd = GetForegroundWindow
MyStr = String(GetWindowTextLength(AHwnd) + 1, Chr$(0))
'Get the window's text
GetWindowText AHwnd, MyStr, Len(MyStr)
debug.print mystr
Loop Until Left(MyStr, 18) = "Download Trans.Log"
tWinName = Mystr
End Sub
*******loadfile() subroutine**************Option ExplicitPrivate Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPrivate Declare Function SetCursorPos Lib "user32" (ByVal X As Long, ByVal Y As Long) As LongPrivate Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As LongPrivate Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)Const MOUSEEVENTF_RIGHTDOWN = &H8Const MOUSEEVENTF_RIGHTUP = &H10Const MOUSEEVENTF_leftDOWN = &H2Const MOUSEEVENTF_leftUP = &H4Private Type POINTAPI X As Long Y As LongEnd TypePrivate Declare Function GetCursorPos Lib "user32" _(lpPoint As POINTAPI) As Long'**Win32 API User Defined TypesPrivate Type RECTLeft As LongTop As LongRight As LongBottom As LongEnd TypeSub loadfile(filename As String)Dim a, WScript As ObjectSet a = CreateObject("WScript.shell")Dim pt As POINTAPIDo until filename=""call downloadfile(filename) ' Go to connect first download website page that is no any issueSetCursorPos Range("b4"), Range("c4") 'Mouse simulate to click download popup windowSleep (30)Call leftDown 'Mouse simulate to click donwload bar to let download popup window will come outSleep (3000) 'Problem is here, I need to put longer waiting time to solve the problema.SendKeys "{enter}" ' Confirm to save the filescall checkfilesaved(filename) 'There is no any issue to check the file is saved or notloopEnd Sub
1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:30:31:32:33:34:35:36:37:38:39:40:41:
Attachment:Snap2.bmp
Finally it is solved that root cause is not related to Java or Parent/Child issue/
Actually it is related to sending enter too faster than the "Download Trans.log" popup
window comes out. Now it is okay using bGetwindow_click and put back those
setcursorpos and leftdown clikc in the loop that will help a lot . ANyway, think a lot
Private Sub bGetWindow_Click()
Dim MyStr As String, AHwnd As Long
tWinName = "waiting..."
Do
SetCursorPos Range("b4"), Range("c4") 'Mouse simulate to click download popup window
Sleep (30)
Call leftDown 'Mouse simulate to click donwload bar to let download popup window will come out
Sleep (3000)
AHwnd = GetForegroundWindow
MyStr = String(GetWindowTextLength(AHwnd) + 1, Chr$(0))
'Get the window's text
GetWindowText AHwnd, MyStr, Len(MyStr)
debug.print mystr
Loop Until Left(MyStr, 18) = "Download Trans.Log"
tWinName = Mystr
End Sub
Finally it is solved that root cause is not related to Java or Parent/Child issue/
Actually it is related to sending enter too faster than the "Download Trans.log" popup
window comes out. Now it is okay using bGetwindow_click and put back those
setcursorpos and leftdown clikc in the loop that will help a lot . ANyway, think a lot
Private Sub bGetWindow_Click()
Dim MyStr As String, AHwnd As Long
tWinName = "waiting..."
Do
SetCursorPos Range("b4"), Range("c4") 'Mouse simulate to click download popup window
Sleep (30)
Call leftDown 'Mouse simulate to click donwload bar to let download popup window will come out
Sleep (3000)
AHwnd = GetForegroundWindow
MyStr = String(GetWindowTextLength(AHwnd) + 1, Chr$(0))
'Get the window's text
GetWindowText AHwnd, MyStr, Len(MyStr)
debug.print mystr
Loop Until Left(MyStr, 18) = "Download Trans.Log"
tWinName = Mystr
End Sub
Finally it is solved that root cause is not related to Java or Parent/Child issue/
Actually it is related to sending enter too faster than the "Download Trans.log" popup
window comes out. Now it is okay using bGetwindow_click and put back those
setcursorpos and leftdown clikc in the loop that will help a lot . ANyway, think a lot
Private Sub bGetWindow_Click()
Dim MyStr As String, AHwnd As Long
tWinName = "waiting..."
Do
SetCursorPos Range("b4"), Range("c4") 'Mouse simulate to click download popup window
Sleep (30)
Call leftDown 'Mouse simulate to click donwload bar to let download popup window will come out
Sleep (3000)
AHwnd = GetForegroundWindow
MyStr = String(GetWindowTextLength(AHwnd) + 1, Chr$(0))
'Get the window's text
GetWindowText AHwnd, MyStr, Len(MyStr)
debug.print mystr
Loop Until Left(MyStr, 18) = "Download Trans.Log"
tWinName = Mystr
End Sub
Finally it is solved that root cause is not related to Java or Parent/Child issue/
Actually it is related to sending enter too faster than the "Download Trans.log" popup
window comes out. Now it is okay using bGetwindow_click and put back those
setcursorpos and leftdown clikc in the loop that will help a lot . ANyway, think a lot
Private Sub bGetWindow_Click()
Dim MyStr As String, AHwnd As Long
tWinName = "waiting..."
Do
SetCursorPos Range("b4"), Range("c4") 'Mouse simulate to click download popup window
Sleep (30)
Call leftDown 'Mouse simulate to click donwload bar to let download popup window will come out
Sleep (3000)
AHwnd = GetForegroundWindow
MyStr = String(GetWindowTextLength(AHwnd) + 1, Chr$(0))
'Get the window's text
GetWindowText AHwnd, MyStr, Len(MyStr)
debug.print mystr
Loop Until Left(MyStr, 18) = "Download Trans.Log"
tWinName = Mystr
End Sub
Finally it is solved that root cause is not related to Java or Parent/Child issue/
Actually it is related to sending enter too faster than the "Download Trans.log" popup
window comes out. Now it is okay using bGetwindow_click and put back those
setcursorpos and leftdown clikc in the loop that will help a lot . ANyway, think a lot
Private Sub bGetWindow_Click()
Dim MyStr As String, AHwnd As Long
tWinName = "waiting..."
Do
SetCursorPos Range("b4"), Range("c4") 'Mouse simulate to click download popup window
Sleep (30)
Call leftDown 'Mouse simulate to click donwload bar to let download popup window will come out
Sleep (3000)
AHwnd = GetForegroundWindow
MyStr = String(GetWindowTextLength(AHwnd) + 1, Chr$(0))
'Get the window's text
GetWindowText AHwnd, MyStr, Len(MyStr)
debug.print mystr
Loop Until Left(MyStr, 18) = "Download Trans.Log"
tWinName = Mystr
End Sub
Finally it is solved that root cause is not related to Java or Parent/Child issue/
Actually it is related to sending enter too faster than the "Download Trans.log" popup
window comes out. Now it is okay using bGetwindow_click and put back those
setcursorpos and leftdown clikc in the loop that will help a lot . ANyway, think a lot
Private Sub bGetWindow_Click()
Dim MyStr As String, AHwnd As Long
tWinName = "waiting..."
Do
SetCursorPos Range("b4"), Range("c4") 'Mouse simulate to click download popup window
Sleep (30)
Call leftDown 'Mouse simulate to click donwload bar to let download popup window will come out
Sleep (3000)
AHwnd = GetForegroundWindow
MyStr = String(GetWindowTextLength(AHwnd) + 1, Chr$(0))
'Get the window's text
GetWindowText AHwnd, MyStr, Len(MyStr)
debug.print mystr
Loop Until Left(MyStr, 18) = "Download Trans.Log"
tWinName = Mystr
End Sub
Finally it is solved that root cause is not related to Java or Parent/Child issue/
Actually it is related to sending enter too faster than the "Download Trans.log" popup
window comes out. Now it is okay using bGetwindow_click and put back those
setcursorpos and leftdown clikc in the loop that will help a lot . ANyway, think a lot
Private Sub bGetWindow_Click()
Dim MyStr As String, AHwnd As Long
tWinName = "waiting..."
Do
SetCursorPos Range("b4"), Range("c4") 'Mouse simulate to click download popup window
Sleep (30)
Call leftDown 'Mouse simulate to click donwload bar to let download popup window will come out
Sleep (3000)
AHwnd = GetForegroundWindow
MyStr = String(GetWindowTextLength(AHwnd) + 1, Chr$(0))
'Get the window's text
GetWindowText AHwnd, MyStr, Len(MyStr)
debug.print mystr
Loop Until Left(MyStr, 18) = "Download Trans.Log"
tWinName = Mystr
End Sub