Announcement

Collapse
No announcement yet.

Process Doesn't Stop on "X"

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

  • Process Doesn't Stop on "X"

    When I run this code and then "X" out of it, the process doesn't go away. I have to open Window Task Manager to stop it.

    Code:
    Function PBMain () As Long
      Local hWin As Dword
      Graphic Window "Box", 300, 300, 130, 130 To hWin
      While 1
      Wend
    End Function
    Is is supposed to work that way?

  • #2
    >Is is supposed to work that way?
    Well...
    Code:
     While 1
     Wend
    .. usually does not do a whole lot until one does not equal zero. And as a bonus, it is context-agnostic.

    Maybe something like
    Code:
     WHILE ISWIN (hWin) 
     WEND
    .. would exit the endless loop when 'hWin' is destroyed and no longer passes the 'smell test' as a valid window.



    MCM
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Hmm... same thing here. "X" closes the window but not the process.

      Code:
      Function PBMain () As Long
        Local hWin As Dword, i As Long, j As Long
        Graphic Window "Box", 300, 300, 130, 130 To hWin
        For i = 1 To 1000000
           For j = 1 To 1000000
              '
           Next j
        Next i
      End Function
      MCM, I guess I was expecting the loops to be exited when the "X" was pressed.

      Any place you've seen at MSDN that might discuss this?

      Comment


      • #4
        Gary,
        the code that looks after the window is written by you if you use SDK programming and you'd then trap the appropriate message in the message loop and flag that your program loop should quit.
        For DDT programming, as in this case, the compiler will generate the code to do the basic maintenance of the graphic window and you'd need to intercept messages by subclassing the window to see if the window has been closed.
        I'd think it's easier, in this case, to just check if the window still exists unless you need to intercept other messages as well.

        Paul

        Comment


        • #5
          Thanks for the info, though not using the feature right now.
          Code:
          FUNCTION PBMAIN () AS LONG
            LOCAL hWin AS DWORD
            GRAPHIC WINDOW "Box", 300, 300, 130, 130 TO hWin
            GRAPHIC ATTACH hWin, 0
            DO
              SLEEP 1000
              GRAPHIC GET CLIENT TO ncWidth!, ncHeight!
              IF ncWidth! = 0 THEN EXIT DO
              BEEP
            LOOP
          END FUNCTION
          The world is full of apathy, but who cares?

          Comment


          • #6
            Gary,

            Think of the Graphic Window as a Modeless Dialog that your program (Function PBMain) has created.
            Even if it is closed your program will continue to run until it's natural end - by reaching the End Function statement.
            Rgds, Dave

            Comment


            • #7
              >MCM, I guess I was expecting the loops to be exited when the "X" was pressed.

              Huh? Why would it do that?

              How then could you EVER create a program which gets input from a GRAPHIC Window, then dismisses the window and goes on to "do something" with that input?

              I mean, we've all written a loop like that at one time or another. And I will bet a lot money we've all had exactly the same reaction, too:

              MCM
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                Gary:

                This subject was posted some weeks ago. I suggested to use the Device Context (DC) in every nested loop to enable the programm to detect whether the graphic window was closed. Even though was deemed ugly, it works.

                Regards,

                Code:
                 
                GLOBAL hdcon AS LONG
                 
                Function PBMain () As Long
                  Local hWin as Dword
                Graphic Window "Box", 300, 300, 130, 130 To hWin
                  While 1
                    GRAPHIC GET DC TO hdcon
                    IF hdcon = 0 THEN EXIT LOOP
                  Wend
                End Function
                Last edited by Manuel Valdes; 17 Aug 2009, 10:42 AM.

                Comment


                • #9
                  Thanks everyone,

                  I guess I was guilty of a "Window-centric" attitude - when the last window is destroyed, the program is over and the compiler was supposed to add code to shut down the process.

                  But that's not the case and not even desired since many apps don't even need/want a window.

                  Comment


                  • #10
                    guess I was guilty of a "Window-centric" attitude - when the last window is destroyed, the program is over ...
                    Not true, even if you are thinking "window-centric."

                    and the compiler was supposed to add code to shut down the process.
                    Oh, but it does add such code.... when you reach the logical end of WinMain() it adds ExitProcess().

                    MCM
                    Michael Mattias
                    Tal Systems (retired)
                    Port Washington WI USA
                    [email protected]
                    http://www.talsystems.com

                    Comment

                    Working...
                    X