rust-windows icon indicating copy to clipboard operation
rust-windows copied to clipboard

Add wrapper/Rustic interface for multiple monitors in GDI

Open alexchandel opened this issue 10 years ago • 1 comments

Getting a handle and device context for the first monitor is relatively easy:

let h_wnd_screen = GetDesktopWindow();
let h_dc_screen = GetDC(h_wnd_screen);
// do stuff
ReleaseDC(h_wnd_screen, h_dc_screen);

Getting a handle and device context for the second monitor is worse than death:


struct monitor_enum_proc_data {
...
}
fn monitor_enum_proc(...) -> BOOL {
...
}
let data = monitor_enum_proc_data {
...
};
EnumDisplayMonitors(h_dc, lprc_clip, monitor_enum_proc, &data as LPARAM);
// call GetMonitorInfo() somewhere
// no end in sight

A simple helper function in gdi.rs, like Dc::get_monitor_window(usize) -> Dc, would go a long way.

alexchandel avatar Jan 19 '15 21:01 alexchandel

At the very least, this should work for one monitor:

// Primary monitor
let screen_num = 0;

let h_dc_screen = Dc::get_screen(screen_num);
let width, height = h_dc_screen.get_size();
let h_dc = MemoryDc::new(h_dc_screen).unwrap();
let h_bmp = h_dc.create_compatible_bitmap(width, height);
h_dc.select_object(h_bmp);
h_dc.bit_blt((0, 0), (width, height), h_dc_screen, (0, 0), SRCCOPY);

let bitmap: Vec<u8> = h_bmp.get_di_bits();

alexchandel avatar Feb 04 '15 02:02 alexchandel