Unit 'Intuition' Package
[Overview][Constants][Types][Procedures and functions][Variables][Index] [#aros]

CloseWindow

Close an Intuition window.

Declaration

Source position: intuition.pas line 3199

procedure CloseWindow(

  Window: PWindow

);

Arguments

Window

  

A pointer to a Window structure

Description

Closes an Intuition window. Unlinks it from the system, deallocates its memory, and makes it disappear.

When this function is called, all IDCMP messages which have been sent to your window are deallocated. If the window had shared a message Port with other windows, you must be sure that there are no unreplied messages for this window in the message queue. Otherwise, your program will try to make use of a linked list (the queue) which contains free memory (the old messages). This will give you big problems. See the code fragment CloseWindowSafely(), below.

Note: If you have added a Menu strip to this Window (via a call to SetMenuStrip()) you must be sure to remove that Menu strip (via a call to ClearMenuStrip()) before closing your Window.

Note: This function may block until it is safe to de-link and free your window. Your program may thus be suspended while the user plays with gadgets, menus, or window sizes and position.

If your window is a "Visitor Window" (see OpenWindow()) CloseWindow() will decrement the "visitor count" in the public screen on which the window was open. When the last visitor window is closed, a signal will be sent to the public screen task, if this was pre-arranged (see OpenWindow()).

{ these functions close an Intuition window
  that shares a port with other Intuition
  windows or IPC customers.

  We are careful to set the UserPort to
  nil before closing, and to free
  any messages that it might have been
  sent.}
procedure CloseWindowSafely(Win: PWindow);
begin
  // we forbid here to keep out of race conditions with Intuition
  Forbid();
  // send back any messages for this window that have not yet been processed
  StripIntuiMessages(Win^.UserPort, Win);
  // clear UserPort so Intuition will not free it
  Win^.UserPort := nil;
  // tell Intuition to stop sending more messages
  ModifyIDCMP(Win, 0);
  // turn multitasking back on
  Permit();
  // and really close the window
  CloseWindow(Win);
end;

{ Remove and reply all IntuiMessages on a port that
  have been sent to a particular window
  (note that we don't rely on the ln_Succ pointer
  of a message after we have replied it)}
procedure StripIntuiMessages(var Mp: PMsgPort; var Win: PWindow);
var
  msg: PIntuiMessage;
  Succ: PNode;
begin
  Msg := PIntuiMessage(Mp^.mp_MsgList.lh_Head);
  Succ := Msg^.ExecMessage.mn_Node.ln_Succ;
  while Assigned(succ) do
  begin
    if Msg^.IDCMPWindow = Win then
    begin
      // Intuition is about to free this message. Make sure that we have politely sent it back.
      Remove(Msg);
      ReplyMsg(Msg);
    end;
    Msg := PIntuiMessage(Succ);
    Succ := Msg^.ExecMessage.mn_Node.ln_Succ;
  end;
end;

See also

OpenWindow

  

Open an Intuition window.

OpenScreen

  

Open an Intuition screen

CloseScreen

  

Close an Intuition screen.


Documentation generated on: 2021-07-30