Results 1 to 26 of 26

Thread: calc.exe

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Talking

    I am adding a button to allow user to lauch the calculator (calc.exe). How can I determine in VB that CALC.exe has been shutdown, so I can display some form immediatly after?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  2. #2
    Hyperactive Member barrk's Avatar
    Join Date
    Sep 2000
    Location
    My own little world
    Posts
    274

    Check to see if the handle still exists

    Hwnd !

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Explain please...

    How would I go about doing that? A constant timer or something?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  4. #4
    Guest
    Add the following to a Form with a Timer.
    Code:
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    
    Private Sub Form_Load()
        Timer1.Interval = False
    End Sub
    
    Private Sub Timer1_Timer()
        
        Dim hApp As Long
        hApp = FindWindowEx(0, 0, "SciCalc", "Calculator")
        
        If hApp <> 0 Then
            myForm.Show 1
            Timer1.Enabled = False
        End If
        
    End Sub

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Thank everyone

    Megatron:

    It works great. You had given me code to disable min and max of a form. Could I (or how would I) do this to the CALC.exe? Also, how would I center it on the screen?

    I know I'm a bother, but please help...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    please?

    Can't some help? I want to center calc.exe in the screen and also disable the min and max buttons. CFan this be done?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    OK What about automation?

    Can I use the calculator in my program? I want to lauch at the user descretion and close, but make it look like part of my app. I this possible? I promise I'll stop asking the same question...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  8. #8
    Member
    Join Date
    Oct 1999
    Location
    Richmond, Virginia
    Posts
    41
    Sorry man, but I don't think that is possible.
    TheLeeMan



  9. #9
    Guest
    Use this:

    [code]
    Private Declare Function OpenProcess Lib "Kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
    Private Declare Function GetExitCodeProcess Lib "Kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long
    Private Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)
    Const STILL_ACTIVE = &H103
    Const PROCESS_QUERY_INFORMATION = &H400

    'JobtoDo - Program to run


    Sub Shell32Bit(ByVal JobToDo As String)

    Dim hProcess As Long
    Dim RetVal As Long
    'The next line launches JobToDo as icon,

    'captures process ID
    hProcess = OpenProcess(PROCESS_QUERY_INFORMATION, False, Shell(JobToDo, 1))

    Do

    'Get the status of the process
    GetExitCodeProcess hProcess, RetVal

    'Sleep command recommended as well as DoEvents
    DoEvents: Sleep 100

    'Loop while the process is active
    Loop While RetVal = STILL_ACTIVE
    'App has been unloaded
    Form2.Show
    End Sub


    Usage

    Private Sub Command1_Click()
    Call Shell32Bit("C:\Windows\Calc.exe")
    End Sub

  10. #10

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441
    s1t1e1v1e,Matthew Gates:

    Thanks for all your help. One last question on this subject, is there a way to make calc.exe not be moveable ie fixed in the center of the screen and not allow user to move it around. The centering code from s1t1e1v1e worked great.

    Guys, any ideas?


    Really appreciate you guys on this task...
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  11. #11
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    hey, give my class a try, download it from
    http://www.geocities.com/despotez/WH/

    It can do all these tasks pretty easily.

    here are the functions and properties:

    Code:
    AlwaysOnTop      > Sets the specified window (by hWnd) always on top or not.
    Caption          > Sets or gets the caption of a specified window or control (by hWnd).
    Click            > Click the specified window (by hWnd) at a specified point.
    CloseWindow      > Closes the specified window (by hWnd).
    Enabled          > Enable or Disable the specified window (by hWnd) or get it's status.
    FindWin          > This gets the hWnd of a window by it's caption or classname.
    FindWinEx        > This gets the hWnd of any child window or control by it's caption or classname.
    FlashWin         > This flashes the specified window by a specified time.
    GetAllWindows    > This gets all open windows in an array (pass it a variant).
    GetMetrics       > This gets the Rectangle of the window (top, left, right, bottom) in a RECT.
    GetMousePos      > This gets the coordinates of the mousecursor in a POINTAPI.
    GetWinProperties > This gets the properties (left, top, width, height, classname, caption) from a window (by hWnd).
    GetWndClassName  > This gets the classname from a window or control.
    MouseDown        > This pushes down (and hold) the specified mousebutton on the point where the mouse is.
    MouseUp          > This triggers the MouseUp event to release the MouseDown (MouseDown + MouseUp = Click)
    Move             > This is used to move and/or resize a window or control.
    Redraw           > This is used to Redraw (refresh) a specified window (it triggers the PAINT method for that form)
    SetFocus         > This sets the focus (it's sets it to the foreground) to a specified window (by hWnd).
    SetMousePos      > This sets the mousecursor to the specified coordinates.
    ShowMouse        > This shows or hides the mousecursor.
    SwapMouse        > This Swaps the mousebuttons or restores them.
    Visible          > This makes the window visible/invisible or checks the state (visible or invisible).
    WinFromPoint     > This gets the hWnd of the window or control currently under the mousepointer.
    If you think you'll like it just give it a try, it makes window handling easy!
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  12. #12

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Damn !!!

    You have alot ties into that class, but, since I am still fairly new to all this, how would I use it to stop calc.exe from being dragged(moved) around the screen?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  13. #13
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    hmm... I haven't implemented a 'Clip form' function.

    Maybe you can subclass (setwindowlong, windowproc?) the window and when you receive a Resize/paint message reset the windows position with CLASS.Move

    or (sloppy way) you can just set a timer to 1 and keep setting the pos of the window, but it sucks...

    have fun.
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  14. #14
    Fanatic Member
    Join Date
    Feb 2000
    Location
    The Netherlands
    Posts
    715
    Jop, in vb you can only subclass your own program.
    Oetje
    oetje@home.nl
    93606776
    Visual Basic 6, Windows 2000

    Never pet a burning dog

  15. #15

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    oetje or anyone

    I have it that calc.exe look like part of my program.

    It came out exactly how I'd hoped (except for the moving around problem I mentioned before). If anyone has any ideas please post !!!

    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  16. #16
    Guest

    Re: Thank everyone

    Originally posted by James Stanich
    Megatron:

    It works great. You had given me code to disable min and max of a form. Could I (or how would I) do this to the CALC.exe? Also, how would I center it on the screen?

    I know I'm a bother, but please help...
    Yes, you can do it to Calc (or any other Window for that matter). The following will disable the Minimizing of Calc.
    Code:
    Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
    Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long
    Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
    Private Const MF_BYPOSITION = &H400&
    
    Private Sub Form_Load()
        Dim hApp As Long
        hApp = FindWindowEx(0, 0, "SciCalc", vbNullString)
        RemoveMenu GetSystemMenu(hApp, 0), 3, MF_BYPOSITION
    End Sub

  17. #17
    New Member
    Join Date
    Nov 2000
    Posts
    6
    I found that if the user changes the mode to scientific calculator, it resets all of the restrictions. this code will compensate. just add a timer, named tmrCalc, with an interval of 50 and disable it. Remove the code I gave you earlier

    This will completely solve your problem, and will even
    give you control of what happens when they close it. it's relatively simple.


    Module Code Required:

    Code:
    make a new module with this code.
    
    Option Explicit
    
    Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
    Declare Function MoveWindow Lib "user32.dll" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
    Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, lpRect As RECT) As Long
    
    Declare Function GetSystemMenu Lib "user32" _
    (ByVal hwnd As Long, ByVal bRevert As Long) As Long
    
    Declare Function GetMenuItemCount Lib "user32" _
    (ByVal hMenu As Long) As Long
    
    Declare Function DrawMenuBar Lib "user32" _
    (ByVal hwnd As Long) As Long
    
    Declare Function RemoveMenu Lib "user32" _
    (ByVal hMenu As Long, ByVal nPosition As Long, _
    ByVal wFlags As Long) As Long
    Public Const MF_BYPOSITION = &H400&
    Public Const MF_REMOVE = &H1000&
    Type RECT
        left As Long
        top As Long
        right As Long
        bottom As Long
    End Type

    Form Code Required:

    Code:
    Option Explicit
    
    Private Sub cmdCalc_Click()
        cmdCalc.Enabled = False
        Shell "c:\windows\calc.exe", vbNormalFocus
        tmrCalc.Enabled = True
        tmrCalc_Timer
    End Sub
    
    Private Sub tmrCalc_Timer()
        Dim hSysMenu As Long
        Dim nCnt As Long
        Dim r As RECT
        
        Dim hwnd As Long
        Dim retval As Long
        hwnd = FindWindow(CLng(0), "Calculator")
        If hwnd = 0 Then
            tmrCalc.Enabled = False
            cmdCalc.Enabled = True
            Me.SetFocus
            MsgBox "You have closed the Calculator", vbOKOnly
        Else
            GetWindowRect hwnd, r
            MoveWindow hwnd, (((Screen.Width / Screen.TwipsPerPixelX) - (r.right - r.left)) / 2), (((Screen.Height / Screen.TwipsPerPixelY) - (r.bottom - r.top)) / 2), (r.right - r.left), (r.bottom - r.top), 1
            hSysMenu = GetSystemMenu(hwnd, False)
        
            If hSysMenu Then
                nCnt = GetMenuItemCount(hSysMenu)
                
                If nCnt Then
                    Dim x As Integer
                    For x = 2 To 9
                        RemoveMenu hSysMenu, nCnt - x, _
                        MF_BYPOSITION Or MF_REMOVE
                    Next x
                    
                    DrawMenuBar hwnd
                End If
            End If
        End If
    End Sub




    Also, as a nifty little tip, you can put it -inside- your window. You might even want to do that.. you can adjust the code as needed if so.

    Code:
    Declare Function SetParent Lib "user32.dll" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long 
    
    SetParent FindWindow(CLng(0), "Calculator"), Me.hwnd


    I deleted my prior code post, which was rendered obsolete with this one.

    [Edited by s1t1e1v1e on 11-16-2000 at 04:41 PM]

  18. #18
    New Member
    Join Date
    Nov 2000
    Posts
    6

    one last little thing

    I have an unrelated question of my own.

    http://forums.vb-world.net/showthrea...threadid=40230

  19. #19
    Addicted Member jcouture100's Avatar
    Join Date
    Aug 1999
    Location
    Omaha, NE. USA
    Posts
    141
    To expand on s1t1e1v1e's nifty little tip.
    Put a Picture Box on your form where you want the
    calculator to appear and set use the SetParent
    call to show the calculator in the picture box.

    You can then set the visible property of the picture box
    to True or False at will to show or hide the calculator
    on your form without having to hide the rest of your form.

    Code:
        lngCalcHwnd = FindWindow(CLng(0), "Calculator") 
        
        If hWnd = 0 Then ' could not find the window
            MsgBox "Calculator application not found."
        Else
            SetParent lngCalcHwnd, Picture1.hWnd
        End If
    To Show or Hide the calculator in the picture box...
    Code:
    Private Sub cmdShowHide_Click()
        If Picture1.Visible = True Then
            Picture1.Visible = False
        Else
            Picture1.Visible = True
        End If
    End Sub
    John Couture

  20. #20

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Hey...

    Everyone, thanks for your support.

    s1t1e1v1e : The code you supplied does everything (even that the user can't move the caculator), except when I instituted the last bit of code to apply a child affect, my close code (from a prior post by Megatron) does not work. It seems to lose that calc is indeed open. Any ideas as of why?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  21. #21
    Guest
    There's probably an error in finding the hWnd...Post your code and it will help us track down the error.

  22. #22

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441
    [code]

    hwnd = FindWindow(CLng(0), "Calculator")

    If hwnd = 0 Then

    frmContainer.BtnBar1.Visible = True

    tmrCalc.Enabled = False

    Exit Sub

    Else

    [end code]

    this is within a timer control, which basiclally is saying if it ain't open anymore, diplay my button menu and turn off the timer.

    If I leave off

    [code]

    SetParent FindWindow(CLng(0), "Calculator"), Me.hwnd

    when I call the SHELL everything works when I close it, but with this in place, it doesn't work.

    Any ideas?

    also,jcouture100

    Appreciate your support, but I am using a MDIform. Trying not to have such a large picturbox, but will keep in mind for future.

    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  23. #23

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    OK What about this

    You see if I leave ou the code, calc.exe is in the start menu(taskbar or whatever it ic called) as a seperate program. So if you click on my program, calc is hidden. Two ideas, neither of which I know how to do.

    One: Remove calc from the taskbar
    Two: Make calc always on top

    What ya think?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  24. #24

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Unhappy Guys...

    Also, if I use the code I prevoiusly posted, it also does not center and still allows user to move. Where am I losing it?
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

  25. #25
    New Member
    Join Date
    Nov 2000
    Posts
    6
    I didn't test that aspect yet. I'll see what I can do.

  26. #26

    Thread Starter
    PowerPoster
    Join Date
    Aug 2000
    Location
    IN SILENCE
    Posts
    6,441

    Small return

    s1t1e1v1e: Good point. I appreciate you continuing help. Thank you all for all your efforts on my probelm. I think I will just stick with the original way, and leave the child thing alone.

    Thanks all.
    Remaining quiet down here !!!

    BRAD HAS GIVEN ME THE ULTIMATIVE. I have chosen to stay....

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