Highlighted
Absent Member.
Absent Member.
600 views

[archive] Progress window and Cancel button

[Migrated content. Thread originally posted on 10 July 2009]

On one of our windows we populate a grid and depending on the ranges the user enters it could take a long time. I have attempted to create a progress window that has a Cancel button on it and it works well. However once the grid is built I cannot for the life of me figure out how to automatically close the progress window (with no user intervention).

So to sum up user clicks a "go" button, progress window pops up, they can click cancel and change ranges and click "go" again. Or leave it to build and when it's done I would like to close the progress window. here is a sample of the code I have so far.


* This is the event for the button click
MainWin-PB-Go-Ev-Cmd-Clicked.
    PERFORM Acu-ProgWin-Routine.

* This is the Progress window The GRID-REFRESH is performed in a thread to
* allow the user to click the cancel while the grid is being built.
ProgWin-Aft-Create.
   SET WS-ABORT TO FALSE.
   MOVE ZEROS TO WS-PROGRESS-HANDLE.     
   PERFORM THREAD GRID-REFRESH THRU GRID-EXIT
                  HANDLE WS-PROGRESS-HANDLE.

* Clicking the cancel button sets the WS-ABORT flag so the above that checks this flag can exit gracefully
ProgWin-PB-Cancel-Ev-Cmd-Clicked.
   SET WS-ABORT TO TRUE. 



So now suppose everything goes as planned and the user doesn't click cancel how do I close the window? I have tried adding the following code to the end of the GRID-REFRESH THRU GRID-EXIT routine but it doesn't close the window.

PERFORM Acu-Progwin-Exit.

Any ideas or direction would be helpful thanks. keep in mind I'm using acubench to develop this also 🙂
0 Likes
5 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] Progress window and Cancel button

You should just have to do a "STOP THREAD WS-PROGRESS-HANDLE" after the grid has been completely filled.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Progress window and Cancel button

Well I'm sure that stops the thread, but by the time Grid is done loading the Thread has run it's course anyhow. The window still doesn't close. I have tried puting a wait for thread then performing the Acu-ProgWin-Exit routine and this works fine. but then I lose the ability for the user to click on the cancel button. lol
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Progress window and Cancel button

Are you displaying your window that you're wanting to destroy in the WS-PROGRESS-HANDLE thread?
If so, then stopping the thread should destroy your window.

When we print, we start a program in a separate thread that displays a window that will allow the user to cancel.
Here's basically what we do to start the thread:


    SET PRINTING-COMPLETE TO FALSE.
    SET PRINTING-CANCELLED TO FALSE.
    MOVE 0 TO CANCEL-THREAD-RETURN.
    CALL THREAD "UCANCLPG.COB" HANDLE CANCEL-THREAD
        RETURNING INTO CANCEL-THREAD-RETURN.


Then, as we're printing, we routinely do the following test:


    do some printing...
    PERFORM CHECK-CANCELLED-PRINT.
    IF PRINTING-CANCELLED
       do something to exit gracefully...
       
CHECK-CANCELLED-PRINT SECTION.
    IF (CANCEL-THREAD-RETURN = 99)
       SET PRINTING-CANCELLED TO TRUE.
CHECK-CANCELLED-PRINT-EXIT.
    EXIT.


If the cancel button is pressed in the CANCEL-THREAD, it returns 99 to the primary thread.
Then once we're done printing, we do something like this:


    the user never pressed the cancel button in the CANCEL-THREAD...
    SET PRINTING-COMPLETE TO TRUE.
    do some other cleanup...
    IF PRINTING-COMPLETE
       STOP THREAD CANCEL-THREAD.


If the user had already pressed the cancel button in the CANCEL-THREAD, that program would have destroyed the cancel window and PRINTING-COMPLETE would never get set to true. If the user didn't cancel, PRINTING-COMPLETE gets set to true and the STOP THREAD statement that gets performed will close the CANCEL-THREAD and destroy its window.

I hope this helps.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Progress window and Cancel button

Thanks for your insights into this, I had initially coded it the way you describe in your example but it was always going off into LA LA Land after I stopped the thread. Anyhow I tried putting back to the way you describe here,a nd still same thing was happening, even when I stepped thru the code I could see it just lost it's place after I had stopped the thread and went off into no man's land.

Eventually I figured out I had the BIND-TO-THREAD set to TRUE. Setting this to FALSE solved all my problems...

I dunno what the difference between BIND-TO-THREAD and LINK-TO-THREAD are, but LINK-TO-THREAD = TRUE and BIND-TO-THREAD = FALSE is the right combination.

Big Thanks for your samples and help 🙂
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Progress window and Cancel button

I had forgotten about the BIND TO THREAD and LINK TO THREAD.
What's really interesting is that I just checked our cancel program and it just uses BIND TO THREAD.
Glad it all worked out for you. 🙂
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.