As already noted by Richard your app should not insist on changing the resolution. You may check the resolution at program start and show a message like "Sorry. This application requires a screen resolution of x X y or higher" and terminate if it is too small.
The ugly part of your code is the loop calling
FindWindowEx
and
Sleep
without additional break condition.
When the screen resolution is changed by the user, Windows sends the
WM_DISPLAYCHANGE[
^] message to all windows. A better approach is handling this message. This will also detect a resolution change that occurs after your program has started.