Store and restore window state