Maybe there's a problem I'm not aware of.
Is there a problem with implementing this using WM_IME_INTERNAL?
Another topic, code works, but the hwnd used by the xic callback function is not valid, so it would be nice if it could be cleaned up. Is this because you don't like to use get_focus()?