Unfortunately dropping a big chunk of code from a different library, that also uses a different license, is not acceptable.
Afaics the main line here is
image = CGDisplayCreateImage(kCGDirectMainDisplay);
The rest of the code brings the returned data into the right format and crops a subrectangle, if necessary. Wine has code for this already (in form of Win32 / NtGdi functions), there's no need to copypaste it from WX. It is also possible that the upper layer (win32u, user32) already handle part of this task.