Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Outlook / Programming Forms / May 2008

Tip: Looking for answers? Try searching our database.

modal dialog, center outlook window, disable outlook window

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
J.P. - 05 Feb 2008 16:08 GMT
I've developed a custom form that it is triggered from a button click
where the button is tied to a custom macro. The form is being loaded
from the macro code. With that said, I'm getting unexpected/
unacceptable behavior from the form.

1. Even though the dialog is a modal dialog, the outlook window is
still active when the dialog is being shown. The window still remains
on top of the outlook window even if focus is shifted to the main
outlook window. This is a problem because the actions the macro
performs are dependent on the items selected in outlook at the time
the button was clicked so I do not want the selections to be changed
'by accident' due to the user clicking around.

2. I have the form set to start at the center of the parent but it
does not. I am working on a dual monitor system and the dialog always
opens on the second monitor even if I have the main outlook window on
the primary display.

I think the problem is that I am not setting the form's parent
properly (actually, I'm not setting it all because I'm having trouble
finding out how to do this properly through code period). Here's some
sample code of what I'm doing (from within a class module method):

Dim frmTest as New FormTest

' set some form properties before display
frmTest.Foo = "bar"
frmTest.Baz = "foo"

frmTest.Show vbModal

TIA,
J.P.
J.P. - 05 Feb 2008 19:09 GMT
I thought it may be worth mentioning that this is a UserForm as
opposed to an Outlook custom form.
J.P. - 05 Feb 2008 20:13 GMT
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)
NJS - 02 May 2008 02:38 GMT
Excellent JP - thanks a lot.

> I've developed a custom form that it is triggered from a button click
> where the button is tied to a custom macro. The form is being loaded
[quoted text clipped - 29 lines]
> TIA,
> J.P.

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.