Microsoft KB Archive/192913

= PRB: EnableModeless Causes Events to Fire Late =

Article ID: 192913

Article Last Modified on 12/11/2003

-

APPLIES TO


 * Microsoft Visual C++ 5.0 Enterprise Edition
 * Microsoft Visual C++ 6.0 Enterprise Edition
 * Microsoft Visual C++ 5.0 Professional Edition
 * Microsoft Visual C++ 6.0 Professional Edition
 * Microsoft Visual C++ 6.0 Standard Edition
 * Microsoft Visual InterDev 1.0 Standard Edition
 * Microsoft Visual J++ 1.0 Standard Edition
 * Microsoft Visual J++ 1.1 Standard Edition
 * Microsoft Visual Studio 97 Service Pack 3

-



This article was previously published under Q192913



SYMPTOMS
While automating the Developer Studio environment (MSDev.exe), events do not occur when expected. For example, the BeforeBuildStart event might not fire before the start of a build.



CAUSE
Developer Studio is visible and the Application.EnableModeless property is set to False.



RESOLUTION
If Application.EnableModeless must be False, set Application.Visible to False to receive events at the time they actually happen. Otherwise, keep Application.EnableModeless set to True.



STATUS
This behavior is by design.



MORE INFORMATION
The purpose of EnableModeless is to minimize user interface messages from Developer Studio while a macro or add-in is displaying a modal dialog box. EnableModeless should be set to False before invoking a modal dialog box, and set to True after dismissing the dialog box. The object model stores events while EnableModeless is False, and fires them when it is set to True. Under normal conditions, EnableModeless should be set to True.

The following Visual Basic subroutine demonstrates the problem. Call CheckBuildEvents with the name of a workspace that includes at least one buildable project. Before you can run the sample code, you must set a reference to the Visual Studio object model.

 From the Project menu, click References.

For Visual Studio 97, click:

 Visual Studio 97 Shared Objects -and-

 Visual Studio 97 Project System

For Visual Studio 6.0, click:

 Visual C++ Shared Objects -and-

</li> Visual C++ Project System</li></ul> </li> Click OK.</li></ol>

Sample Code
Private WithEvents DevSt As DSSharedObjects.Application Private Sub CheckBuildEvents(strWksp As String) Dim cfg As DSProjectSystem.Configuration

' Create a new instance of DevStudio. Set DevSt = New DSSharedObjects.Application DevSt.Visible = True  ' Developer Studio must be invisible for ' EnableModeless. DevSt.EnableModeless (False) Debug.Print "Opening Workspace "; strWksp DevSt.Documents.Open strWksp cfg = DevSt.ActiveProject.Configurations.Item(1) Debug.Print "Starting build: "; cfg DevSt.RebuildAll cfg Debug.Print "Closing workspace "; strWksp DevSt.ExecuteCommand "WorkspaceClose" DevSt.EnableModeless (True)  ' Events occur here if DevStudio is                                    ' visible. DevSt.Quit End Sub Private Sub DevSt_BeforeBuildStart Debug.Print ">BeforeBuildStart" End Sub Private Sub DevSt_BuildFinish(ByVal nErr As Long, ByVal nWrn As Long) Debug.Print ">BuildFinish: nErr ="; nErr; "; nWrn ="; nWrn End Sub For example, if you have a workspace named MyWksp.dsw with one project named MyProj, the following Visual Basic subroutine call CheckBuildEvents "MyWksp.dsw" produces the following output in the debug window: <pre class="fixed_text">  Opening Workspace MyWksp.dsw Starting build: MyProj - Win32 Release Closing Workspace MyWksp.dsw >BeforeBuildStart >BuildFinish: nErr = 0; nWrn = 0 Now modify the subroutine, changing the following line DevSt.Visible = True ' Developer Studio must be invisible for ' EnableModeless. to the following: DevSt.Visible = False Rerunning the test correctly produces the following output: <pre class="fixed_text">  Opening Workspace MyWksp.dsw

Starting build: MyProj - Win32 Release >BeforeBuildStart >BuildFinish: nErr = 0; nWrn = 0 Closing Workspace MyWksp.dsw

<div class="references_section">