Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add wrapper/Rustic interface for multiple monitors in GDI #14

Open
alexchandel opened this issue Jan 19, 2015 · 1 comment
Open

Add wrapper/Rustic interface for multiple monitors in GDI #14

alexchandel opened this issue Jan 19, 2015 · 1 comment

Comments

@alexchandel
Copy link

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
Copy link
Author

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();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant