![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
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. |
Ads |
#2
|
|||
|
|||
![]()
I thought it may be worth mentioning that this is a UserForm as
opposed to an Outlook custom form. |
#3
|
|||
|
|||
![]()
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. |
#4
|
|||
|
|||
![]()
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) |
#5
|
|||
|
|||
![]()
Excellent JP - thanks a lot.
"J.P." wrote: 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. |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Disable the window update of IE7 | Roy[_2_] | Outlook Express | 5 | January 14th 08 10:08 PM |
How do you make the reminder window appear on top of other window. | JR | Outlook - Calandaring | 2 | February 8th 07 08:41 PM |
OE6 new message window opens behind main window. | [email protected] | Outlook Express | 2 | August 14th 06 10:09 PM |
When is a Modal UserForm 'Semi-Modal'...? | David OShea | Outlook and VBA | 3 | March 15th 06 11:59 AM |
Distribution list window dosn't show the same as in contact window | Rose | Outlook - Using Contacts | 5 | February 26th 06 10:17 PM |