I've tried a few solutions with SetParent and SetWindowLong... and I'm
stumped. Any help would be greatly, immensely even, apperciated.
Here's what I've done in the UserForm_Activate() event (closest I
could find to a form load event).
hwnd = FindWindow("ThunderDFrame", Me.Caption)
If (hwnd <> 0) Then
'SetParent hwnd, FindWindow("rctrl_renwnd32", vbNullString)
SetWindowLong hwnd, GWL_HWNDPARENT, FindWindow("rctrl_renwnd32",
vbNullString)
SetForegroundWindow hwnd
Else
MsgBox "Couldn't find the window handle to fix the outlook modal
dialog bug!", vbInformation, Me.Caption
End If
The commented SetParent() call causes the code to hang.
I know that I'm getting the right window handles as well by checking
against the results of GetWindowText() on the handles.
J.P. - 05 Feb 2008 20:52 GMT
After two days of messing with this I've found a solution to my
problem. Here it is for anyone else who runs into this issue:
Added this public method to my form and called it before the Show
method:
Public Sub FixModalDialogBug()
' Make sure the outlook window is disabled while this dialog is open
Dim hwnd As Long
hwnd = FindWindow("ThunderDFrame", Me.Caption)
If (hwnd <> 0) Then
SetWindowLong hwnd, GWL_HWNDPARENT, FindWindow("rctrl_renwnd32",
vbNullString)
SetForegroundWindow hwnd
Else
MsgBox "Couldn't find the window handle to fix the outlook modal
dialog bug!", vbInformation, Me.Caption
End If
' Center this dialog over the outlook window
CenterMeOverOutlook
End Sub
Public Sub CenterMeOverOutlook()
Dim olWidth, olHeight As Integer
olWidth = Outlook.Application.ActiveExplorer().Width
olHeight = Outlook.Application.ActiveExplorer().Height
Me.Left = (olWidth / 2) - (Me.Width / 2)
Me.Top = (olHeight / 2) - (Me.Height / 2)
End Sub
You need these declarations for the win32 api calls:
Private Declare Function SetForegroundWindow Lib "user32" _
(ByVal hwnd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetWindowLong Lib "user32" Alias
"SetWindowLongA" _
(ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
As Long
Private Const GWL_HWNDPARENT = (-8)