A few days ago I posted a way to shell any application from within MB. I got
some positive response and Jaques was kind enough to elaborate on it and
post it on his outstanding web site. Some people said yes that is great now
I can Shell an application but how do I close it. This is a bit more
difficult because the function to close a Shelled application lies in the
Shell.dll which is not 32 bit compliant hence useless to MB. However if you
know what you are Shelling which you do since you Shelled it you know what
it's Caption will be. You can grab an applications handle based solely on
it's Caption. The trick is in knowing what vbNullstring really means. It
doesn't mean "" that is a string with two ASCII characters in it.
vbNullString is simply a pointer to vbNullCharacter and vbNullCharacter is
in fact 0. So the function in VB requires a String however from MB the
variable is an integer = to 0. Now for the example. This will shut down
Excel after you have Shelled a new Excel workbook. You could omit the close
statement and simply capture the handle to use later to close it down also.
Enough wind here it is.
 
'---------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
------------------
include "mapbasic.def"
include "menu.def"
include "icons.def"
 
 
 
Define WM_CLOSE &H10 
 

Declare sub Main
Declare Sub Close_r
Declare Function CloseProgram( Caption As String ) As Logical
 
Declare Function SendMessage Lib "C:\WINNT\SYSTEM32\user32.dll" Alias
"SendMessageA" (ByVal hwnd As Integer, ByVal wMsg As Integer, ByVal wParam
As Integer, ByVal lParam As Integer) As Integer 
Declare Function FindWindow Lib "C:\WINNT\SYSTEM32\user32.dll" Alias
"FindWindowA" (ByVal lpClassName As Integer, ByVal lpWindowName As String)
As Integer
 
Sub Main
Create Buttonpad "Close" as
    Pushbutton calling Close_r
    HelpMsg "\nCloses Shelled New Excel Workbook and Excel application"
                icon 102
Show
End Sub
 
Sub Close_r
Dim Closed1 As Logical
Dim Caption As String
Caption = "Microsoft Excel - Book1"
Closed1 = CloseProgram(Caption)
End Sub
 
Function CloseProgram( Caption As String ) As Logical
Dim lngWin As Integer 
Dim Su_cc As Integer
Dim lpClassName As Integer
lpClassName = 0
lngWin = FindWindow( lpClassName, Caption)
 

If lngWin = 0 Then 
 Note "0"
Else
 Su_cc = SendMessage(lngWin, WM_CLOSE, 0, 0)
End If
 

End Function 

'---------------------------------------------------------------------------
----------------------------------------------------------------------------
----------------------------------------------------------------------------
-----------------
 
 
If you haven't done so yet and you are a MB developer check out Jaques's
site. It's http://www.paris-pc-gis.com/mb_r/mbr_start.htm
<http://www.paris-pc-gis.com/mb_r/mbr_start.htm> 
It has been of tremendous help to me in my endeavors.

Reply via email to