PowerBASIC Users Meeting Point
Program that won't close - Printable Version

+- PowerBASIC Users Meeting Point (https://pump.richheimer.de)
+-- Forum: User to User Discussions (https://pump.richheimer.de/forumdisplay.php?fid=3)
+--- Forum: PowerBASIC for Windows (https://pump.richheimer.de/forumdisplay.php?fid=4)
+--- Thread: Program that won't close (/showthread.php?tid=146)



Program that won't close - Giuseppe Belziti - 25.10.2026

I have a program that I can't close; I've tried everything. Here is the current situation:

Code:
CALLBACK FUNCTION AggiornaXProc()
    SELECT CASE CB.MSG
        '...........................................chiudi con X
        CASE %WM_SYSCOMMAND
        IF (CB.WPARAM AND &HFFF0) = %SC_CLOSE THEN
           PID = SHELL("PAY.EXE", 1)
           DIALOG END CB.HNDL, 0  ' Chiude hDlg2
           DIALOG END hDlg, 0     ' Chiude hDlg
           CLOSE                  ' Rilascia gli handle file
           END                    ' Termina definitivamente PAY_START.EXE
        END IF 
    END SELECT
END FUNCTION

Code:
       ' --- RICHIAMA PAY.EXE ---
       PID = SHELL("PAY.EXE", 1)
      
       ' --- CHIUSURA ORDINATA IN SEQUENZA CORRETTA ---
       DIALOG END hDlg2, 0   ' Chiude prima il dialogo figlio (Aggiornamenti)
       DIALOG END hDlg, 0    ' Poi chiude la finestra principale (AgriPag)
       CLOSE                 ' Chiude tutti i canali file aperti
       END                   ' Forza la terminazione del processo

I also tried using taskkill, but it doesn't work.

If I try from the CMD, on the other hand, I get this—and you can see that the program was open:

C:\PAG>cmd.exe /c taskkill /F /IM PAY_START.EXE
OPERAZIONE RIUSCITA: il processo "PAY_START.EXE" con il PID 8960 è stato terminato.


Do you have a solution for closing this program safely? P.S. This only happens with this one...


RE: Program that won't close - Kurt Kuzba - 25.10.2026

Should you be closing the current dialog before closing others?


RE: Program that won't close - Dale Yarker - 25.10.2026

CLOSE and END in the callback??? Bad idea IMO. Without trimmed but compilable example I can't figure out if you had a good reason to do that, and no suggestions possible.

hint: read END in Help!


RE: Program that won't close - Jules Marchildon - 25.10.2026

I'm with Dale on this one, using it inside a message callback breaks the message loop and prevents a proper cleanup...  forcing multiple DIALOG END calls inside a local callback is most likely causing you to crash before the process can exit. Another thing to look at is when you are launching PID = SHELL("PAY.EXE", 1) at practically the same time when you are destroying the parent process. You should consider restructuring your exit path,  fix it by removing all of this from the callback and let the dialogs close and handle the SHELL, CLOSE, and END in your main execution loop after the DIALOG LOOP terminates.


RE: Program that won't close - Mike Doty - 25.10.2026

Code:
#DIM ALL                'end all if dialog1 ended
#INCLUDE "WIN32API.INC"
%NumDialogs = 4
GLOBAL ghdg() AS DWORD

FUNCTION PBMAIN () AS LONG
    LOCAL i AS LONG
    REDIM ghdg(1 TO %NumDialogs) AS DWORD
    FOR i = LBOUND(ghdg) TO UBOUND(ghdg)
        DIALOG NEW 0, "Dialog " + FORMAT$(i),_
          50 + ((i - 1) * 110), 50 + ((i - 1) * 55), 200, 100, %WS_SYSMENU OR %WS_CAPTION TO ghdg(i)
    NEXT i
    FOR i = LBOUND(ghdg) TO UBOUND(ghdg)
        DIALOG SHOW MODELESS ghdg(i), CALL MyCallback
    NEXT i
    DO
        DIALOG DOEVENTS
        FOR i = LBOUND(ghdg) TO UBOUND(ghdg)
            IF ghdg(i) THEN ITERATE DO
        NEXT i
        EXIT DO
    LOOP
    MSGBOX "All dialogs have ended"
END FUNCTION

CALLBACK FUNCTION MyCallback() AS LONG
    LOCAL i AS LONG
    SELECT CASE CB.MSG
        CASE %WM_SYSCOMMAND
            IF (CB.WPARAM AND &hFFF0) = %SC_CLOSE THEN

                IF CB.HNDL = ghdg(1) THEN                  'close all
                    FOR i = LBOUND(ghdg) TO UBOUND(ghdg)
                        IF ghdg(i) THEN
                            DIALOG END ghdg(i), 0
                            ghdg(i) = 0
                        END IF
                    NEXT i
                    FUNCTION = %TRUE
                ELSE                                       'close ghdg(i)
                    FOR i = LBOUND(ghdg) TO UBOUND(ghdg)
                        IF ghdg(i) = CB.HNDL THEN
                            ghdg(i) = 0
                            EXIT FOR
                        END IF
                    NEXT i
                    DIALOG END CB.HNDL, 0
                    FUNCTION = %TRUE
                END IF
            END IF
    END SELECT
END FUNCTION



RE: Program that won't close - Borje Hagsten - 25.10.2026

I don't understand the problem. First of all, %WM_SYSCOMMAND and %SC_CLOSE is only reached when you close a program via the system menu close or X in caption bar. There is nothing you can do at that point other than preventing close by returning 1 and exit in dialogs, or exit function in SDK message loop.

Usually better to move closing stuff, stopping ticking timers and saving settings, etc. to %WM_DESTROY, which is reached regardless of how a program is ended. Also, when a parent dialog is closed, all child dialogs and controls are destroyed with it. No need for any extra dialog ends for child dialogs.

Is it the external PAY.EXE that is the problem and if so - is that your own program? A tip is to use MS Spy to monitor messages in a program. It can tell what is happening at the end - what is missing, etc.