Microsoft KB Archive/254929

From BetaArchive Wiki
Knowledge Base

Article ID: 254929

Article Last Modified on 8/15/2005


  • Microsoft Visual Basic for Applications 1.0

This article was previously published under Q254929


This article contains sample Visual Basic for Applications code that shows how to hide the Visio application window by using the ShowWindow API. NOTE: For a sample add-on that uses the ShowWindow API, see PrintIt1.exe. The following file is available for download from the Microsoft Download Center:

For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:

119591 How to Obtain Microsoft Support Files from Online Services

Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file.


Sample code

The following sample code hides the Visio application window and, after a short pause, restores it. Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. Place the following code in a new module:

'Set ShowWindow API constants.
Public Const SW_HIDE = 0
Public Const SW_RESTORE = 1

'Declare ShowWindow API. 
Public Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long

Place the following code in the "ThisDocument" module:

Public Sub Hide()
   Dim i As Integer
   Dim VisioHandle As Long
   'Get a Visio handle. 
   VisioHandle = Visio.Application.WindowHandle32
   'Call the ShowWindow API to hide the Visio application window.
   Call ShowWindow(VisioHandle, SW_HIDE)
   For i = 1 To 2000
      Debug.Print i
   Next i
   'Call the ShowWindow API to restore the Visio application window.
   Call ShowWindow(VisioHandle, SW_RESTORE)
End Sub

You can also use the ShowWindow API to minimize and maximize the Visio application window. The following example sets the ShowWindow API constants so that your Visual Basic for Applications code can control the state of the Visio application window:

(Optional) Place the following code in a new module: Public Const SW_HIDE = 0
Public Const SW_NORMAL = 1
Public Const SW_MAXIMIZE = 3
Public Const SW_SHOW = 5
Public Const SW_MINIMIZE = 6
Public Const SW_RESTORE = 9
Public Const SW_SHOWDEFAULT = 10

For more information about the ShowWindow API, refer to the Windows API documentation at the following Microsoft Web site:

Keywords: kbdownload kbdtacode kbfile kbgraphxlink kbhowto kburl KB254929