Thanks, but the Titels are fully equal.
Will FindWindow give me the handles of two apps with identical title?
Regards
Peter
> Thanks, but the Titels are fully equal.
> Will FindWindow give me the handles of two apps with identical title?
I'm 99% sure.....if the title bar caption is all you have (IOW, you're
passing a null for the classname) and 2 or more windows have the same
caption, FindWindow arbitrarily picks one.
Regardless, FindWindow returns *a* Long. Just one value. So there's no
POSSIBLE way it could provide you with hWnds for TWO windows (and it returns
a handle to a window, not an app).
You'll need to use EnumWindows (assuming you only need to enumerate
top-level windows).
On a personal note, I'm always baffled as to WHY people need their program
to send keystrokes to another app. To me, that just reeks of suspicion. You
say you need to send an F5 keystroke, and F5 is *usually* Refresh. But quite
honestly, we have no way of knowing if you're telling the truth. Your
thinking could be "I'll just ask about sending an *innocent* keystroke", but
then once you know how, you could send any keystrokes you want (that could
do harm). This is precisely why questions such as yours are usually ignored
and why you're really not getting any replies. I'm not saying your intent is
to send malicious keystrokes...I'm just saying it's a touchy subject and one
that most of us won't help with. If an app is intended to interact with, or
be controlled by, another program, then it's going to expose a means to do
that via (usually) COM and there's no need to send it keystrokes.

Signature
Mike
Microsoft MVP Visual Basic
Peter - 28 Aug 2008 06:53 GMT
Thanks Mike!
I understand your thoughts about that but in my case I defenitely want to
send an innocent keystroke.
If you are interested here are more details about what I want to do. Perhaps
you can even recommend a better solution for me:
On the PC there will be running upto two Internet Explorer Windows, each
browses a web-based email client which is MS Outlook webaccess.
The difference between them is that they show different email accounts. So
both are identical apps with identical window titles but different
content(different inboxes).
The Window Title string of these windows is: "Microsoft Outlook Web Access -
Microsoft Internet Explorer"
The reason why I want to send F5 periodically to these apps is to invoke a
browser refresh operation(as you have already assumed). This is required
because otherwise Outlook webaccess will expire its inactivity
timer(20Minutes) and it would be required to logon again by entering
domain,username and password.
So the VB app should prevent to relogon every 20Minutes and update the
screen for new incoming emails, my idea was to use the refresh function and
the easiest way would be to periodically send F5 to these two windows.
If you can recommend any other solution then please let me know.
Be aware that these two IE apps can not be started by the VB app, they must
run completely independet and it could even be that the user starts only one
of them or even none. So the VB app must detect which one of them(or both)
are running and then send F5 to them periodically.
By the way, do you have a sample code what parameters I must pass to
SendMessage to send the F5 keystroke to these Windows once I have the
handle?
Regards
Peter
>> Thanks, but the Titels are fully equal.
>> Will FindWindow give me the handles of two apps with identical title?
[quoted text clipped - 23 lines]
> going to expose a means to do that via (usually) COM and there's no need
> to send it keystrokes.
MikeD - 28 Aug 2008 14:20 GMT
> Thanks Mike!
>
[quoted text clipped - 17 lines]
> screen for new incoming emails, my idea was to use the refresh function
> and the easiest way would be to periodically send F5 to these two windows.
> If you can recommend any other solution then please let me know.
> By the way, do you have a sample code what parameters I must pass to
> SendMessage to send the F5 keystroke to these Windows once I have the
> handle?
Sorry. I've been writing Windows apps since 1992 and have never had a need
to send keystrokes to another app, so I don't have any kind of example I
could provide you.
I don't know much about administering Outlook Web Access (perhaps its done
via Exchange Server), but I believe the logging out due to inactivity is
something the administrator sets up. The 20 minutes might be a default, but
I believe it can be turned off or made shorter or longer. If the admin
hasn't done that, he/she probably wants it that way and wouldn't be too
happy if you (or anybody) tries to circumvent it. It's just a personal
opinion, but I don't think what you're trying to do is a good idea. First,
at least talk to whomever administers your email and ask if this can be
changed. That would be my recommendation for an alternative solution that
you asked about. <g>
Another problem you could run into is: if your app is being deployed, are
all users going to be using IE? If not, the title bar caption is going to be
different (it won't include "Microsoft Internet Explorer).

Signature
Mike
Microsoft MVP Visual Basic
Steph - 28 Aug 2008 21:12 GMT
> So the VB app should prevent to relogon every 20Minutes and update the
> screen for new incoming emails, my idea was to use the refresh function
> and the easiest way would be to periodically send F5 to these two windows.
> If you can recommend any other solution then please let me know.
If you want to refresh IE, it's a Usenet FAQ
(ask mainly on Adv. Win2 api forum
news://194.177.96.26/comp.os.ms-windows.programmer.win32)
expvb - 29 Aug 2008 02:18 GMT
Some IE based browsers have auto refresh features. Here is one of them which
is free:
http://www.avantbrowser.com
It can auto refresh every 1,2,5,10, and 15 minutes.
Another solution:
http://www.download.com/AutoRefresher-for-IE/3000-12777_4-10062693.html
More:
http://www.google.com/search?num=100&q=IE+Addon+auto+refresh
Peter - 29 Aug 2008 06:14 GMT
Thanks!!!
That sounds promising.
I will try them out.
Regards
Peter
> Some IE based browsers have auto refresh features. Here is one of them
> which is free:
[quoted text clipped - 10 lines]
>
> http://www.google.com/search?num=100&q=IE+Addon+auto+refresh
Vinchenzo vinç - 28 Aug 2008 22:19 GMT
>> Thanks, but the Titels are fully equal.
>> Will FindWindow give me the handles of two apps with identical title?
>
> I'm 99% sure.....if the title bar caption is all you have (IOW, you're
> passing a null for the classname) and 2 or more windows have the same
> caption, FindWindow arbitrarily picks one.
Hi Mike,
FindWindow doesn't pick one window arbitrarily, it returns the first top-level window that match with the specified classname and/or title, starting the search from the top of the ZOrder in the desktop childwindows.
FindWindowEx works in the same way, but you can 'continue' the search from each match, for example:
'************
Dim hWndMatch As Long
hWndMatch = FindWindowEx(0, 0, vbNullString, "A Caption")
While hWndMatch <> 0
Debug.Print hWndMatch
hWndMatch = FindWindowEx(0, hWndMatch, vbNullString, "A Caption")
Wend
'************
EnumWindows too, in the callback function you are recieving the handles "sorted" from the top to the bottom top-level window under the desktop.
> On a personal note, I'm always baffled as to WHY people need their program
> to send keystrokes to another app. To me, that just reeks of suspicion. You
[quoted text clipped - 8 lines]
> be controlled by, another program, then it's going to expose a means to do
> that via (usually) COM and there's no need to send it keystrokes.
Absolutely agree, Peter should *find* the solution instead of *ask* for it.

Signature
Regards
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
( ! ) Preceding answers in Google:
http://groups.google.com/group/microsoft.public.vb.winapi
( i ) Temperance in the forum:
http://www.microsoft.com/communities/conduct/default.mspx
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -