Displaying word app on top

When running the attached scao.cpp file under XP, a word application is launched and appears on top.

However, when running on Windows 7, the word application is launched, but it does not appear on top.

To make the word app appear on top, it seems desirable to get the HWND for the MSWordApplication in the code (m_app).  The HWND could then be used to make a call to "::setForegroundWindow(HWND)".  However, it is unclear how to get the HWND for the MSWordApplication (see MSWord.h).

If the HWND was available, it seems like the setForegroundWindow call should follow  "m_app->Activate()".        The following comment was inserted to simplify finding this call:

//
//   HOW TO MAKE THE WORD APP APPEAR ON TOP?????
//


Thanks in advance.


Scao.cpp
Scao.h
MSWord.h
joexAsked:
Who is Participating?
 
puppydogbuddyConnect With a Mentor Commented:
0
 
puppydogbuddyCommented:
Try using the FindWindow by class name, then use the setForegroundWindow as you indicated in your post.


'Use the FindWindow API call to find a window of the specified class. Pass a long NULL pointer for the window name.  The class name for Word is "OpusApp"

Declare Function FindWindowByClass Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As Long) As Long

Dim hwnd As Long

'ClassName for Word: OpusApp

'Get the handle to the Word window.
hwnd = FindWindowByClass("OpusApp", 0&)

0
 
joexAuthor Commented:
Thanks.

What if more than one window is opened for word - is there a way to find out the window name?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.