Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

FindWindow API function

261 views
Skip to first unread message

Victor Eldridge

unread,
Jun 18, 2002, 4:21:28 AM6/18/02
to
Hi People,

In need to use the FindWindow API function to return a hWnd handle to the
window that Word is currently running in. I am unsure of two things...

1\ In Office 2000, Word's class name is "OpusApp".
Is it the same name in Word 97 ?

2\ The second argument for FindWindow requires a string containing the
text that appears in the Caption of the application's window.
I am currently using code below, however my knowledge of Word is
somewhat limited. Could someone please tell me if I can rely on the
following code to always return the exact string ? In Word 97 too ?

TIA,
Vic Eldridge

Sub CaptionString()
Dim CaptionString As String
If Application.ActiveWindow.Caption = "" Then
CaptionString = Application.Caption
Else
CaptionString = Application.ActiveWindow.Caption & _
" - " & Application.Caption
End If
MsgBox CaptionString
End Sub


Victor Eldridge

unread,
Jun 18, 2002, 5:00:17 AM6/18/02
to
I've just revised my little macro to allow for the possibility of zero
documents being open. It seems a bit long-winded just to do something as
simple as returning the window's caption. Am I missing something here ?

Sub CaptionString()

Dim CaptionString As String

If Application.Windows.Count > 0 Then


If Application.ActiveWindow.Caption = "" Then
CaptionString = Application.Caption
Else
CaptionString = Application.ActiveWindow.Caption & _
" - " & Application.Caption
End If

Else
CaptionString = Application.Caption
End If

MsgBox CaptionString

End Sub


"Victor Eldridge" <v...@ultratrace.com.au> wrote in message
news:3d0f...@news.bekkers.com.au...

ibby

unread,
Jun 18, 2002, 10:08:58 AM6/18/02
to
Hi Victor,

> In need to use the FindWindow API function to return a hWnd handle to the
> window that Word is currently running in. I am unsure of two things...
>
> 1\ In Office 2000, Word's class name is "OpusApp".
> Is it the same name in Word 97 ?

Yes

> 2\ The second argument for FindWindow requires a string containing the
> text that appears in the Caption of the application's window.
> I am currently using code below, however my knowledge of Word is
> somewhat limited. Could someone please tell me if I can rely on the
> following code to always return the exact string ? In Word 97 too ?

You don't need to specify the second argument for FindWindow - you can use:

hwnd_Word = FindWindow("OpusApp", vbNullString)


--
Hope this helps.
ibby

Please post replies or follow-ups to the **newsgroup** so that participants
may benefit or contribute.

Victor Eldridge

unread,
Jun 18, 2002, 10:01:37 PM6/18/02
to
Thanks for the info ibby.

FindWindow("OpusApp", vbNullString) appears to return a handle to the most
recently activated instance, which is exactly what I need.

The word "Opus" sounds intriguing doesn't it ?
I wonder what the story is behind that...

"ibby" <ib...@bigpond.net.au> wrote in message
news:usDaVGtFCHA.2280@tkmsftngp12...

Guy Gallo

unread,
Jun 19, 2002, 12:18:23 PM6/19/02
to
If I'm remembering correctly, OPUS was the code name for the first beta of
Word.

"Victor Eldridge" <v...@ultratrace.com.au> wrote in message

news:3d10...@news.bekkers.com.au...

Victor Eldridge

unread,
Jun 19, 2002, 10:37:11 PM6/19/02
to

The name of the lead designer's pet cat perhaps ?

Heeeeeere Opus, Opus Opus Opus, Heeeeeere Opus...


"Guy Gallo" <noEmailATmsn.com> wrote in message
news:Oe6UZz6FCHA.2652@tkmsftngp13...

0 new messages