Desktop windows come to foreground when using modal dialogs

A

Alex

Whenever my C# add-in displays a modal dialog, once the user dismisses it, the Z-order of the desktop windows briefly changes so it seems like all the other application window flicker on top of Word then disappear behind it again.

Is there a reason for this behaviour and a way to disable it?


Best wishes,
Alex.
 
P

Peter Huang [MSFT]

Hi

Based on my test, I can not reproduce the problem.
So how did you show the modal dialog?
When you show the modal dialog, is word the foregroud window?
Did the problem persists with all the other windows, e.g. notepad, vs.net
IDE, IE... or just certain ones?

If I have any misunderstanding, please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

Alex

Hello Peter,

Peter Huang" said:
Based on my test, I can not reproduce the problem.
So how did you show the modal dialog?

From inside Word, using _CommandBarButtonEvents_ClickEventHandler()
that invokes a function that does form.ShowDialog() where "form" is a Windows Form.
When you show the modal dialog, is word the foregroud window?

I believe so.
Did the problem persists with all the other windows, e.g. notepad, vs.net
IDE, IE... or just certain ones?

I am not sure I undersand.
This is a Word add-in that displays a Windows Form modally as a response to a Word CommandBarButton Event.
Running on Win2K (latest service packs etc.) and Word 2003.


Best wishes,
Alex.
 
P

Peter Huang [MSFT]

Hi

Based on my test, when the addin lauched it will create a commandbarbutton,
after the button is click, it will show a winform modal.
fm.ShowDialog.
But now the form is still in front of the word window, after I close the
modal winform, now the word window will be the foregroud window, no other
windoe will be in front of it.
(BTW: when in the test, I open another windows to try reproduce the
problem, e.g. notepad, vs.net ide, outlook...)
I can not reproduce the problem.

So I think that may specified to your machine, did the problem occur at
another machine.
Also you may try to open a notepad only and open the word to see if the
problem persists.
And you can test to simplify the addin code to create a commandbutton and
atttach click event only, commment out other code to see if that may help
to isolate the problem.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

Alex

Hello Peter,

Peter Huang" said:
So I think that may specified to your machine, did the problem occur at
another machine.

It seemed to be a problem with the way I was making my form a child of Word.
Got it working.
Sorry to have bothered you.


Best wishes,
Alex.
 
A

Alex

It seemed to be a problem with the way I was making my form a child of Word.
Got it working.

No, it turned out to be something different.
Even with the suspect code removed, we are still getting the problem.
And this is not just my machine - we have this on all the machines (physical and VM) that we run the code on.


Best wishes,
Alex.
 
P

Peter Huang [MSFT]

Hi Alex,

Have you tried the steps I posted in my last post?
1. simplified the code similar as below
Dim wdApp As Word.Application
Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnBeginShutdown
Dim cmBar As Office.CommandBar
Dim cbb As Office.CommandBarButton
Debug.WriteLine("OnBeginShutdown")
Try
cmBar = wdApp.CommandBars("Test")
cbb = cmBar.FindControl(, , "TestTag", , )
Catch ex As Exception
Debug.WriteLine(ex.ToString())
End Try
If Not cbb Is Nothing Then
cbb.Delete()
End If
If Not cmBar Is Nothing Then
cmBar.Delete()
End If
Marshal.ReleaseComObject(cbb)
Marshal.ReleaseComObject(cmBar)
cbb = Nothing
cmBar = Nothing
End Sub
Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnAddInsUpdate
Debug.WriteLine("OnAddInsUpdate")
End Sub
Dim WithEvents cbb As Office.CommandBarButton
Public Sub OnStartupComplete(ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnStartupComplete
Debug.WriteLine("OnStartupComplete")
Dim cmBar As Office.CommandBar
If MsgBox("Do you want Create Toolbar?", MsgBoxStyle.YesNo) =
MsgBoxResult.Yes Then
cmBar = wdApp.CommandBars.Add("Test", , , True)
cmBar.Visible = True
cmBar.Position = MsoBarPosition.msoBarTop
cbb =
cmBar.Controls.Add(Office.MsoControlType.msoControlButton, , , , True)
cbb.Caption = "TestBar"
cbb.FaceId = 17
cbb.Tag = "TestTag"
Debug.WriteLine("Create Toolbar Complete")
End If
Marshal.ReleaseComObject(cmBar)
cmBar = Nothing
End Sub
Public Sub OnDisconnection(ByVal RemoveMode As
Extensibility.ext_DisconnectMode, ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnDisconnection
Debug.WriteLine("OnDisconnection")
If Not RemoveMode = ext_DisconnectMode.ext_dm_HostShutdown Then
OnBeginShutdown(custom)
End If
End Sub
Public Sub OnConnection(ByVal application As Object, ByVal connectMode
As Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef custom
As System.Array) Implements Extensibility.IDTExtensibility2.OnConnection
wdApp = DirectCast(application, Word.Application)
Debug.WriteLine("OnConnection")
If Not connectMode = ext_ConnectMode.ext_cm_Startup Then
OnStartupComplete(custom)
End If
End Sub

Private Sub cbb_Click(ByVal Ctrl As
Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean)
Handles cbb.Click
Dim fm As New Form1
fm.ShowDialog()
' MsgBox("Test") ' I have tried msgbox/showdialog but I still can
not reproduce the problem
End Sub

2. Open the word and a notepad application
3. Now make the word as the foregroud application, and click the button, a
modal form will show
4. close "X" to close the modal form
5. and now the word is the foregroud application, the notepad will not be
the foregroud window

If I have any misunderstanding, please feel free to post here.
If you still have any concern, please post your simplified test code
together with the detailed reproduce steps for us to further research.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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