CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2001
    Posts
    155

    What do i do?????

    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

  2. #2
    Join Date
    May 2001
    Location
    Russia
    Posts
    200

    Re: What do i do?????

    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)




    Andy Tower

  3. #3
    Join Date
    Apr 2000
    Posts
    737

    Re: What do i do?????

    refer http://vblib.virtualave.net, there should be a function ShutDownApp in vbSystem of the activeX DLL.

    HTH


  4. #4
    Join Date
    Feb 2001
    Location
    PA
    Posts
    163

    Re: What do i do?????

    This should work:
    Declare your run variable as an integer

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





  5. #5
    Join Date
    Feb 2001
    Location
    Stamford CT USA
    Posts
    2,167

    Re: What do i do?????

    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

    Good Luck,
    -Cool Bizs

  6. #6
    Join Date
    May 2001
    Posts
    155

    Re: What do i do?????

    Thanks every1.

    I got it working right

    now

    --Ant
    ------------------------------------------------------------------------------------------------------------------------
    Want Free Software?
    E-mail me @: [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured