; ----------------------------------------------------------------------------
; Attempt one or more times to close an open window by display name:
; ----------------------------------------------------------------------------
; $7 is "1" if a window was found, otherwise it is left at whatever value it
; was set to before this macro was invoked. NAME should be a single word which
; describes the window being closed.
; WINDOW is the window title of the window you want to close, and TRIES is the
; maximum number of close attempts you want to make... if there are three 
; windows with the title you are looking for and you set tries to 9 then if it
; takes more than 3 goes to close one of those windows not all of them will be
; closed. The NAME has to be a single word because it is used to create a
; unique label. This also means that you can't invoke this macro twice on the
; same NAME twice in a single function (you will get a duplicate label error).
; ----------------------------------------------------------------------------
!macro CloseWindow NAME WINDOW TRIES
  Push $8
  Push $0
  DetailPrint `Closing window "${WINDOW}"`
  StrCpy $8 "0"
  find${NAME}:
  IntCmp $8 ${TRIES} done${NAME} 0 done${NAME}
  FindWindow $0 "" "${WINDOW}"
  IntCmp $0 0 done${NAME}
  IsWindow $0 0 done${NAME}
    SendMessage $0 ${WM_CLOSE} 0 0
    SendMessage $0 ${WM_QUIT} 0 0
    SendMessage $0 ${WM_DESTROY} 0 0
    StrCpy $7 "1"
    IntOp $8 $8 + 1
    Goto find${NAME}
  done${NAME}:
  Pop $0
  Pop $8
!macroend
