ComAdd-In Form displays behind Word app

P

Philip Levien

We have a ComAdd-In for Word, written in VB6. This runs
on Office2000/NT and OfficeXP/WinXP. If the user switches
to another application while a form is loading from the
ComAdd-In, the Form is hidden behind the Word application
window when the user reactivates Word, making it appear
that Word is frozen. Does anyone can help with some code
to ensure that the form is displayed in front of Word.
Thanks.
 
B

Balasubramanian Ramanathan

You can use the WIN API functions to make word as parent of your add-in
form...here is the helper code


Option Explicit

'API Function Declarations and Constants
Public Declare Function GetForegroundWindow Lib "user32" () As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA"
( _
ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA"
( _
ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As
Long
Public Declare Function GetClassName Lib "user32" Alias "GetClassNameA" ( _
ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As
Long) As Long

Public Const GWL_HWNDPARENT = (-8)
Public Const GWL_HINSTANCE = (-6)

Public Function SetNewParent(hwndChild As Long, hwndNewParent As Long) As
Long


Dim sClassName As String
Dim lCount As Long
sClassName = Space(255)
lCount = GetClassName(hwndNewParent, sClassName, Len(sClassName))
sClassName = UCase(Left(sClassName, lCount))

If sClassName = "OPUSAPP" Then
If hwndNewParent <> 0 Then
SetWindowLong hwndChild, GWL_HINSTANCE,
GetWindowLong(hwndNewParent, GWL_HINSTANCE)
SetNewParent = SetWindowLong(hwndChild, GWL_HWNDPARENT,
hwndNewParent)
End If
Else
SetNewParent = 0
End If

End Function



Hope this helps...

Thanks and Regars
 
L

Lynn

-----Original Message-----
We have a ComAdd-In for Word, written in VB6. This runs
on Office2000/NT and OfficeXP/WinXP. If the user switches
to another application while a form is loading from the
ComAdd-In, the Form is hidden behind the Word application
window when the user reactivates Word, making it appear
that Word is frozen. Does anyone can help with some code
to ensure that the form is displayed in front of Word.
Thanks.
.
 

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