Click to See Complete Forum and Search --> : What do i do?????


ant
May 29th, 2001, 03:13 PM
Take alook at this code first:


' This code is supposed to, when you select an item and click show, it should open calculator
' if you click calculator
Dim run as string
private Sub show_Click()
If List1.text = "Word Processor" then
Form2.Show
ElseIf List1.text = "Calculator" then
run = Shell("C:\WINDOWS\CALC.EXE", 1)
End If
End Sub
' That works
' This code is supposed to exit the program when you click on calculator
private Sub close_Click()
If List1.text = "Word Processor" then
Form2.Hide
ElseIf List1.text = "Calculator" then
End If
End Sub
' And then there's the rest
private Sub Exit_Click()
End
End Sub

private Sub Form_Load()
List1.AddItem "Word Processor"
List1.AddItem "Calculator"
End Sub
' My question is: how do you make it close calculator when you select it from the list box and 'click close?




--Ant

Tower
May 29th, 2001, 07:40 PM
Declare this

Const WM_DESTROY = &H2
Const WM_CLOSE = &H10

private Declare Function FindWindowA Lib "user32" (byval lpClassName as Any, byval lpWindowName as Any) as Integer
private Declare Function SendMessageA Lib "user32" (byval hWnd as Integer, byval wMsg as Integer, byval wParam as Integer, lParam as Any) as Long




For close Calculator

Dim hWnd&, Res&
hWnd = FindWindowA(vbNullString, "Calculator")
Res = SendMessageA(hWnd, WM_CLOSE, 0, 0)
Res = SendMessageA(hWnd, WM_DESTROY, 0, 0)

cksiow
May 30th, 2001, 06:41 AM
refer http://vblib.virtualave.net, there should be a function ShutDownApp in vbSystem of the activeX DLL.

HTH

Cubbie
May 30th, 2001, 08:31 AM
This should work:
Declare your run variable as an integer

' Activate the calculator
AppActivate run
' Close the Calculator
SendKeys "%{F4}, true"

coolbiz
May 30th, 2001, 12:21 PM
Add the following:

dim run as string
dim runid as long ' ID returned by Shell()
.
.

private Sub show_Click()
If List1.text = "Word Processor" then
Form2.Show
ElseIf List1.text = "Calculator" then
runid = Shell("C:\WINDOWS\CALC.EXE", 1) ' save the ID
End If
End Sub
.
.
.
private Sub close_Click()
If List1.text = "Word Processor" then
Form2.Hide
ElseIf List1.text = "Calculator" then
AppActivate runid
SendKeys "%{F4}, true"
End If
End Sub
....

-Cool Bizs

ant
May 30th, 2001, 01:41 PM
Thanks every1.

I got it working right

now

--Ant
------------------------------------------------------------------------------------------------------------------------
Want Free Software?
E-mail me @: cgeorge@thevortex.com