Announcement

Collapse
No announcement yet.

Task/program close?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Task/program close?

    Hello! Who can help me?!
    How can current application (Process/Task) detect and close?
    ...definite Task terminate?

    Thank

  • #2
    I don't know if this is what you're looking for, but who knows. I use DDT. When the program ends, I call a sub called Quit().
    SUB Quit()
    DIALOG END hdlgmain
    DIALOG END hdlganotherone
    DIALOG END hdlganother
    DIALOG END hdlgetc
    END SUB
    I needed to destroy all the dialogs/windows (whatever) to really end the task. I'm sure the API way is different, but I'm a newbie and don't do that stuff yet!
    ~Todd
    Todd Wasson
    http://PerformanceSimulations.Com
    PowerBasic Racing Simulator (October 2007 clip - 15.1MB wmv file) http:http://www.performancesimulations.co...m-GenIV-12.wmv

    Comment


    • #3
      What exactly do you want to achieve, Alexander? You can always use TerminateProcess(), but it is not recommended as it can leave memory leaks and locked resources, etc.

      If you explain in more detail exactly what you want to do, then we may be able to help further.

      ------------------
      Lance
      PowerBASIC Support
      mailto:[email protected][email protected]</A>
      Lance
      mailto:[email protected]

      Comment


      • #4
        Originally posted by Lance Edmonds:
        What exactly do you want to achieve, Alexander? You can always use TerminateProcess(), but it is not recommended as it can leave memory leaks and locked resources, etc.

        If you explain in more detail exactly what you want to do, then we may be able to help further.

        e.g. I have as current task (Strg+Alt+Del):
        - Explorer
        - Internat
        - Systray
        - Rundll
        - Notify
        - TestPrg
        - ...
        I would like e.g. Tasks: Test PRG and Notify close...
        How can that make?


        Comment


        • #5
          Code:
          I need a similar thing.
          
          1 My DOS program shells to my Windows program.
          
          2 My Windows program needs to know when another
            Windows program has terminated.  I know the
            name of the program that I'm waiting for to
            terminate by pressing Ctrl+Alt+Del.
          [This message has been edited by Mike Doty (edited May 10, 2000).]

          Comment


          • #6
            Mike --
            there are many ways to terminate apps by program way.
            I don't think that termination similar Ctrl-Alt-Del is good solution, but if we talk about ways...
            Two days ago, when I debug a global hook (see Source code from), I encounted one method.
            I will demonstrate it on following sample.
            Spy-Dll
            Code:
               #Include "Win32Api.Inc"
            
               $HookFile = "C:\HookWnd.Id"
               Global hDlg As Long, hHook As Long, hInstDLL As Long
               Global TmpAsciiz As Asciiz * 256, ReadyToTerminate As Long
               Function LibMain(ByVal hInstance As Long, ByVal fwdReason As Long, _
                  ByVal lpvReserved As Long) Export As Long
                   Select Case fwdReason
                     Case %DLL_PROCESS_ATTACH:
                        GetModuleFileName(GetModuleHandle(ByVal %Null), TmpAsciiz, _
                           SizeOf(TmpAsciiz)
                        If LCase$(Right$(TmpAsciiz, 12)) = "\notepad.exe" Or _
                           LCase$(Right$(TmpAsciiz, 12)) = "\winword.exe" Or _
                           LCase$(Right$(TmpAsciiz, 12)) = "\wordpad.exe" Then _
                           ReadyToTerminate = %True
                        hInstDLL = hInstance: LibMain = 1
                     Case %DLL_PROCESS_DETACH: LibMain = 1
                  End Select
               End Function
            
               Function HookProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) Export As Long
                  Function = CallNextHookEx(ByVal hHook, ByVal nCode, ByVal wParam, ByVal lParam)
                  If hDlg = 0 Then Open "C:\HookWnd.Id" For Input Shared As #1: _
                     Input #1, hDlg, hHook: Close #1
                  If IsWindow(hDlg) = %False Then
                     FreeLibrary hInstDll ' Normal termination of DLL, when Spy exe is finished
                  Else
                     If ReadyToTerminate And wParam = &H91 Then _
                        FreeLibraryAndExitThread hInstDll, 0 Else _
                        PostMessage hDlg, %WM_USER + 1, wParam, lParam
                 End If
               End Function
            
               Function SetHookKbdWindow Alias "SetHookKbdWindow" (hWnd As Long) Export As Long
                  hHook = SetWindowsHookEx (%WH_KEYBOARD, _
                          CodePtr(HookProc), ByVal hInstDLL, ByVal 0)
                  Open $HookFile For Output As #1: Print #1, hWnd, hHook;: Close
               End Function
            
               Function UnHookKbdWindow Alias "UnHookKbdWindow" Export As Long
                  UnhookWindowsHookEx hHook: Kill $HookFile
               End Function
            Spy-Exe
            Code:
               #Compile Exe
               #Dim All
               #Register None
               #Include "Win32Api.Inc"
            
               Declare Function SetHookKbdWindow Lib "Hook.Dll" _
                  Alias "SetHookKbdWindow" (hWnd As Long) As Long
               Declare Function UnHookKbdWindow Lib "Hook.Dll" _
                  Alias "UnHookKbdWindow" As Long
            
               CallBack Function DlgProc
                  Static Id As Long
                  Select Case CbMsg
                     Case %WM_INITDIALOG
                        SetHookKbdWindow CbHndl
                     Case %WM_DESTROY
                        UnHookKbdWindow
                     Case %WM_USER + 1
                        Incr Id
                        SetWindowText CbHndl, "KbdHook Id = " + Str$(id)
                        Control Set Text CbHndl, 101, _
                          "WParam =" + Hex$(CbWparam) + _
                          " LParam =" + Hex$(CbLparam) + _
                          " at " + Time$
                        Function = 1: Exit Function
                  End Select
               End Function
            
               Function PbMain()
                  Local hDlg As Long
                  Dialog New 0, "", 0, 0, 200, 40, %WS_SYSMENU, %WS_EX_TOPMOST To hDlg
                  Control Add Label, hDlg, 101, "", 5, 5, 200, 12
                  Dialog Show Modal hDlg Call DlgProc
               End Function
            Compile Dll and start Exe. From this moment, if you will press a "Scroll Lock" key in Winword, Wordpad or Notepad, this app will be cancelled without pardons.

            Of course, in your case technique could be other, but global hook is not bad for such purpose.





            ------------------

            Comment

            Working...
            X