In dialogs don't use "wait", it has no sense. If need a delay, use a timer. Or move the code to another thread.
And avoid key and mouse functions. In this case can be used messages EM_GETSEL and EM_SETSEL.
And avoid key and mouse functions. In this case can be used messages EM_GETSEL and EM_SETSEL.