threads

I have a problem figuring out how to control threads.

Have 2 programs: Program1 should stay in control, program2 contains a window that the user may activate.

Summary of source:

---

Program1 (called from my main application):

display floating window, modeless

           bind to thread.

call thread "Program2".

display screen-1.

accept screen-1.

 ---

Program2:

display floating windows, modeless, bind to thread.

display screen-2

accept screen-2

---

My problem is that control is in Program2 and not in Program1 even if Program1 displays and accept screen-1. User has to click window in Program1 to make it active.

What do I do wrong?

  • Thank you for answering.
    The purpose of Program2 is to display additional customer information to Program1 (holding customer basic information) and should automatically appear showing this information while the user runs Program1. User may modify information in Program2, but this is normally not the case. As it is now, user has to click Program1 to focus there, which is annoying.
    Maybe I’m using wrong features. How would you normally solve this scenario?
  • Verified Answer

    Shjerpe's answer might work but if your Program2 needs any user interaction it also needs to be sitting on an ACCEPT.

    You can set the active current window using Format 10 of the SET verb. You would do this in Program2, after the DISPLAY but before the ACCEPT:  

    SET I-O WINDOW TO Prog1-Win1

    A few things you'll need to make this work:

    • Each window should have a handle. If you're not already setting a handle, you should do so in the "display floating window" statement:
    Display floating window, modeless, bind to thread, HANDLE IN Prog1-Win1 ...
    • The window handles needs to be declared in Working-Storage of both programs and should be EXTERNAL so that, for instance, Program2 can refer to Program1's handle:
    01  Win-Handle-Group External.
    03 Main-Win usage is handle of window.
    03 Prog1-Win1 usage is handle of window.
    03 Prog1-Win2 usage is handle of window.
    03 Prog2-Win1 usage is handle of window.
    03 Prog2-Win2 usage is handle of window.

    Also, consider using INDEPENDENT windows instead of FLOATING windows. In your example, if Program2's window is FLOATING but it intersects Program1's window, it will be "above" and therefore covering part of Program1's window, even when Program1's window is active. With INDEPENDENT windows, whichever window is active moves to the front. However, this affects the parent/child relationship, so when you close (or destroy) Program1's window, it won't necessarily close Program2's window.

  • Thank you very much!
    This was indeed what I needed. Programs are running perfectly now.