none
How to make Word Spell Check window the window on top of all others? Works with Word 2007 but not Word 2010 RRS feed

  • Question

  • I have an application that opens Word and Word's Spell checker via an Ole object.  In Word 2007 on an XP machine, the spell check window is the top window; i.e. it is displayed on top of my application window.  This is good since the user can see it!

    But in Word 2010 (32 bit) on a Windows 7 machine the spell check window is underneath my application window and the user can't see it.  Is there a way for me to make the Spell check window the top window?  Perhaps an application property?

    I can make the spell check window be on top if I make Word visible and normal or maximized.  But we prefer for the user to just see the Spell check window.  So currently my app does the following:

    lole_Spell.Application.Visible = FALSE
    lole_Spell.Application.WindowState = 2

    and with these settings I am having no luck.  Any suggestions??

    Monday, March 21, 2011 9:49 PM

Answers

  • Hi Tom,  I just figured this out an hour or two ago.  I had to find the handle of the Word document (hwndWordWindow) that I created via the ole object and then SetForegroundWindow(hwndWordWindow), SetActiveWindow(hwndWordWindow) and BringWindowToTop(hwndWordWindow).

    The ole object is created in a PowerBuilder application.  Do you still want me to send the code to you?

    Thanks, Janice

    Thursday, March 24, 2011 7:52 PM
  • Here's what I did to solve the problem. This is Powerscript. I have removed error checking to shorten the snippet.

    Long    ll_Hwnd, ll_HwndWasActive  
    String  ls_Null 
    String  ls_WindowTitle

    // Windows API constant for getting the next window                      
    Int     li_GW_HWNDNEXT = 2     


    SetNull (ls_Null)

    // Get handle of top window
    ll_Hwnd = FindWindowA ( ls_Null, ls_Null ) 

    // Loop through all windows and compare window
    // title to what you are looking for
    DO WHILE ll_Hwnd <> 0        
       ls_WindowTitle = Space (200)

       GetWindowTextA ( ll_Hwnd, ls_WindowTitle, li_Buff )
       IF Not ISNull(ls_WindowTitle) THEN
          IF Pos ( UPPER(ls_WindowTitle), UPPER('Title of Window you are looking for') ) > 0 THEN
             SetForegroundWindow((ll_Hwnd))
             SetActiveWindow(ll_Hwnd)
             BringWindowToTop(ll_Hwnd)
          END IF
       END IF 
       ll_Hwnd = GetWindow( ll_Hwnd, li_GW_HWNDNEXT )
    LOOP

    • Marked as answer by janicej45 Tuesday, March 29, 2011 9:03 PM
    Tuesday, March 29, 2011 9:02 PM

All replies

  • Hi janice45,

    Thanks for posting in the MSDN Forum.

    Would you please tell me where I can get your Ole object to repoduce your issue?

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, March 24, 2011 12:27 PM
    Moderator
  • Hi Tom,  I just figured this out an hour or two ago.  I had to find the handle of the Word document (hwndWordWindow) that I created via the ole object and then SetForegroundWindow(hwndWordWindow), SetActiveWindow(hwndWordWindow) and BringWindowToTop(hwndWordWindow).

    The ole object is created in a PowerBuilder application.  Do you still want me to send the code to you?

    Thanks, Janice

    Thursday, March 24, 2011 7:52 PM
  • Hi janicej45,

    I’m glad to hear you solve your issue. It will be very beneficial for other community members who have similar questions to see how you have dealt with your issue if you can show the snippet on the forum.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by janicej45 Tuesday, March 29, 2011 8:57 PM
    • Unmarked as answer by janicej45 Tuesday, March 29, 2011 9:02 PM
    Monday, March 28, 2011 6:03 AM
    Moderator
  • Here's what I did to solve the problem. This is Powerscript. I have removed error checking to shorten the snippet.

    Long    ll_Hwnd, ll_HwndWasActive  
    String  ls_Null 
    String  ls_WindowTitle

    // Windows API constant for getting the next window                      
    Int     li_GW_HWNDNEXT = 2     


    SetNull (ls_Null)

    // Get handle of top window
    ll_Hwnd = FindWindowA ( ls_Null, ls_Null ) 

    // Loop through all windows and compare window
    // title to what you are looking for
    DO WHILE ll_Hwnd <> 0        
       ls_WindowTitle = Space (200)

       GetWindowTextA ( ll_Hwnd, ls_WindowTitle, li_Buff )
       IF Not ISNull(ls_WindowTitle) THEN
          IF Pos ( UPPER(ls_WindowTitle), UPPER('Title of Window you are looking for') ) > 0 THEN
             SetForegroundWindow((ll_Hwnd))
             SetActiveWindow(ll_Hwnd)
             BringWindowToTop(ll_Hwnd)
          END IF
       END IF 
       ll_Hwnd = GetWindow( ll_Hwnd, li_GW_HWNDNEXT )
    LOOP

    • Marked as answer by janicej45 Tuesday, March 29, 2011 9:03 PM
    Tuesday, March 29, 2011 9:02 PM
  • Hi there

    Could you please also post the declarations of those local external functions (I am using powerbuilder as well).

     

    THANK YOU SOOOO MUCH!!!

    Friday, April 15, 2011 4:37 PM
  • Sorry it took me so long to get back to you.  I have been out of town

    The declarations are as follows:

    FUNCTION uInt FindWindowA(string szClass,  string szName) LIBRARY "user32.dll" alias for "FindWindowA;Ansi"
    FUNCTION uInt GetWindow(long hwnd,  long lnextwindow) LIBRARY "user32.dll"
    FUNCTION uInt GetWindowTextA(long hwnd,  ref string titleText, long nMaxCount) LIBRARY "user32.dll" alias for "GetWindowTextA;Ansi"
    FUNCTION boolean BringWindowToTop(long hwnd) LIBRARY "user32.dll"
    FUNCTION boolean SetForegroundWindow(long hwnd) LIBRARY "user32.dll"
    FUNCTION uInt SetActiveWindow(long hwnd) LIBRARY "user32.dll"

    Tuesday, April 26, 2011 11:00 PM
  • Hello janice45.

    Thanks for your answer but, I'm still not clear with it.

    If you call the spellchecker like this:

     

    lole_Spell.ActiveDocument.CheckSpelling()

     

    In what position do you call that snippet with the local external functions? Before or after that line?

    Thanks in advance!

     

     

    Tuesday, May 24, 2011 9:22 PM
  •  Since the spell check window is the window that you are trying to bring to the top, it has to be open. So you would call the snippet after you have called the spell checker. 
    Wednesday, May 25, 2011 1:57 AM
  • A late answer, but I just want to point out for other people with the same problem:

    The problem your describing is caused by windows version not outlook version. The behavior of popping up windows has been changed by Bill since windows 7 and forward. (someone had the idea that users shouldn't be bothered by popping up windows).

    As for SetForeGroundWindow() api functions and alike: they don´t work if the window that executes them to show another window, is not on the foreground itself at that moment.

    https://msdn.microsoft.com/en-us/library/windows/desktop/ms633539(v=vs.85).aspx

    HTH.

    • Edited by MiguelLe Sunday, December 6, 2015 10:54 AM
    Sunday, December 6, 2015 10:52 AM