Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can you close an ActiveX Document window programmatically with VB?

ActiveX and DLL Creation

Can you close an ActiveX Document window programmatically with VB?

by  MapMan  Posted    (Edited  )
You've developed an ActiveX Document either from scratch or used the ActiveX Document Migration Wizard. You look at your code or try to use the "End" command to close your application. Then you discover it doesn't work. How are you going to close that window, without relying on the "X" control at the top right of the screen?

Here's what you do:

[ol][li]Add the Microsoft Internet Controls to your project reference[/li][li]Add the following code to your ActiveX UserDocument code[/li]
Code:
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 CloseActXWindow()
   Dim hndHandle As Long
   Dim ieApp as InternetExplorer

   Const NILL = 0&
   Const WM_SYSCOMMAND = &H112
   Const SC_CLOSE = &HF060&

   Set ieApp = UserDocument.Parent

   'Call that actually closes the window
   hndHandle = SendMessage(ieApp, WM_SYSCOMMAND, _ 
               SC_CLOSE, NILL)
End Sub
[li]Then add
Code:
CloseActXWindow
to an Exit button on the user document[/ol]
I've been working with ActiveX documents for about a year and this has always perplexed me on how to do this. Hopefully, someone else will benefit from this chunk of code, too.

Good Luck,

MapMan [americanflag]
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top