add another SetFocus() after calling CloseDocumentInTab() in CloseWindow()