Fix resolution changing on Windows. Improve the resolution selection algorithm.