how do you automate checking for application window focus?

D

Daniel Kim

Hello

I'm using VS .NET, automating Word via C++ typelibrary. (but it's similar to the VB automation

I've basically set up a OnTimer call that checks the application object (pointer to the running Word application) every 3 seconds to see if it's still there, etc

Now, the problem is that I want to check to see if the word application that I'm automating has the focus or not. I want my dialog box (which assists the user to automate word) to come to the very top of the window Z order every time the Word application gets focus... Is there any way I can check this through automation? I don't think ActiveWindow property works, since it will still return something even if the Word Application does not have input focus

I would really appreciate any help in this

Thank you.
 
W

WenJun Zhang[MSFT]

Thanks for posting in the group.

I have reviewed your thread and currently I am finding somebody who
could help you on it. We will post back in this newsgroup as soon as
possible.
If there is anything unclear, please feel free to post in this group
and we will follow up here.

Thanks & have a nice day,

WenJun Zhang
Microsoft Online Support
This posting is provided "AS IS" with no warranties, and confers no
rights.
Get Secure! - www.microsoft.com/security
 
P

Peter Huang

Hi

Thanks for your quickly reply!

Thanks for posting in the community.

First of all, I would like to confirm my understanding of your issue.

From your description, I understand that you have an windows application
developped using VC++(unmanaged) to automation Word.Application.
And you hope the window application reside above the word application all
the time.
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

Have you tried to handle the WindowActivate event of Word.Application, when
the word was activated this event will be fired?

Please apply my suggestion above and let me know if it helps resolve your
problem.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

Andrew Cushen

Daniel-

I don't know how if this is the best method when using
VS .NET, but I would approach this by using the Win32 API
call GetForegroundWindow() and interrogating the
foreground window's caption using GetWindowText(), passing
it the window handle you retrieved with GetForegroundWindow
(), to see if the caption ends with "Microsoft Word".

Hope that helps,

-Andrew
=========================================
-----Original Message-----
Hello,

I'm using VS .NET, automating Word via C++ typelibrary.
(but it's similar to the VB automation)
I've basically set up a OnTimer call that checks the
application object (pointer to the running Word
application) every 3 seconds to see if it's still there,
etc.
Now, the problem is that I want to check to see if the
word application that I'm automating has the focus or
not. I want my dialog box (which assists the user to
automate word) to come to the very top of the window Z
order every time the Word application gets focus... Is
there any way I can check this through automation? I
don't think ActiveWindow property works, since it will
still return something even if the Word Application does
not have input focus.
 
D

Daniel Kim

Thank you for the suggestions... As for the suggestion of catching the
WindowActivate event, I was trying to stay away from making event
handlers... because currently, the software only talks TO Word application,
it doesn't respond to what Word does. In order for me to have this two-way
communication, that means I need to set up a whole another interface, right?
So if possible, I wanted to see if I could query the Word App and see if
it's the top window.

I will try the GetForegroundWindow and see if it's a Word App... Is there
anyway I can get the window handler from LPDISPATCH so that I can compare
without doing a "caption text comparison"?

But if that doesn't work, I guess I need to look into catching events from
Word. Is that hard? I haven't done it yet.

--Daniel
 
E

Eric Lawrence [MSFT]

You can also use the WindowClass instead of the Caption text, but the effect
is basically the same.

--
Thanks,

Eric Lawrence
Program Manager
Assistance and Worldwide Services

This posting is provided "AS IS" with no warranties, and confers no rights.
 
P

Peter Huang

Hi Daniel,

Thanks for your quickly reply!

Here is two KB aritcles may help you.
HOW TO: Handle Word Events by Using Visual C++ .NET and MFC
http://support.microsoft.com/?id=309294

We can use the FindWindow to obtain the window handle when automation word.
Base on my experience, I think we can not get the windows handle from the
LPDISPATCH interface.

HOWTO: Obtain the Window Handle for an Office Automation Server by Using
Visual C# .NET
http://support.microsoft.com/?id=302295

Please make a try and let me know if this help you.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top