Displaying word app on top

Posted on 2011-10-21
Last Modified: 2012-05-12
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:


Thanks in advance.

Question by:joex
    LVL 38

    Expert Comment

    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&)


    Author Comment


    What if more than one window is opened for word - is there a way to find out the window name?
    LVL 38

    Accepted Solution


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Article by: Rob
    Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
    I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
    The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
    The viewer will learn how to back up with the free utility from runtime software, DriveImageXML using Windows 7. Download DriveImageXML from Open folder where it was saved: Start installation by double clicking the install scrip…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now