DetailPage-MSS-KB

Microsoft small business knowledge base

Article ID: 293086 - Last Review: February 27, 2014 - Revision: 3.0

This article was previously published under Q293086
This article has been archived. It is offered "as is" and will no longer be updated.

On This Page

SUMMARY

In some situations, you may want to programmatically close the Internet Explorer window that hosts your Microsoft Visual Basic ActiveX document. This article demonstrates a mechanism that can accomplish this.

MORE INFORMATION

The CloseWindow sub procedure in the following code sample uses the SendMessage function to send a SC_CLOSE message to the Internet Explorer window, which immediately closes the Internet Explorer instance.

Keep in mind that the recommended method to close a Visual Basic document is to navigate the Internet Explorer instance away from the Visual Basic document to another resource.

Step-by-Steps Example

  1. Create a new ActiveX Document DLL project in Visual Basic.
  2. On the Project menu, click References, select Microsoft Internet Controls, and then click OK.
  3. Paste the following code into the User Document code window:
    Option Explicit
    
    
    Private Declare Function SendMessage _
              Lib "user32" Alias "SendMessageA" _
              (ByVal hwnd As Long, _
              ByVal wMsg As Long, _
              ByVal wParam As Long, _
              lParam As Long) _
              As Long
    
    
    Private Sub CloseWindow()
        
        Dim Handle As Long
        Dim ie As InternetExplorer
        
        Const NILL = 0&
        Const WM_SYSCOMMAND = &H112
        Const SC_CLOSE = &HF060&
        
        Set ie = UserDocument.Parent
        
        '   Send the message.
        Handle = SendMessage(ie.hwnd, WM_SYSCOMMAND, SC_CLOSE, NILL)
    
    End Sub
    					
  4. Call the CloseWindow procedure whenever you want to close the Internet Explorer window.

REFERENCES

For additional information, click the article number below to view the article in the Microsoft Knowledge Base:
177238  (http://support.microsoft.com/kb/177238/EN-US/ ) How To Hyperlink in UserDocuments
For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:
http://msdn.microsoft.com/ie/ (http://msdn.microsoft.com/ie/)

http://support.microsoft.com/iep (http://support.microsoft.com/iep)

APPLIES TO
  • Microsoft Internet Explorer 4.0 128-Bit Edition
  • Microsoft Internet Explorer 4.01 Service Pack 2
  • Microsoft Internet Explorer 4.01 Service Pack 1
  • Microsoft Internet Explorer 5.0
  • Microsoft Internet Explorer 5.01
  • Microsoft Internet Explorer (Programming) 5.01 SP1
  • Microsoft Internet Explorer 5.5
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic 6.0 Enterprise Edition
  • Microsoft Visual Basic 5.0 Professional Edition
  • Microsoft Visual Basic 6.0 Professional Edition
Keywords: 
kbnosurvey kbarchive kbhowto kbactivedocs KB293086
Share
Additional support options
Ask The Microsoft Small Business Support Community
Contact Microsoft Small Business Support
Find Microsoft Small Business Support Certified Partner
Find a Microsoft Store For In-Person Small Business Support