Answer the question
In order to leave comments, you need to log in
How to take a screenshot with winapi using Rust?
At the moment there is such code (not the best, the main task is to make it work):
use winapi::*;
use std::ptr;
use ::core::mem::size_of;
fn get_sct(){
unsafe{
let mut HDC_screen = um::winuser::GetDC(ptr::null_mut());
let mut HDC_compatible_DC = um::wingdi::CreateCompatibleDC(HDC_screen);
let bmi = um::wingdi::BITMAPINFO {
bmiHeader: um::wingdi::BITMAPINFOHEADER {
biSize: size_of::<um::wingdi::BITMAPINFOHEADER>() as shared::minwindef::DWORD,
biWidth: 1920,
biHeight: 1080,
biPlanes: 1,
biBitCount: 32,
biCompression: um::wingdi::BI_RGB,
biSizeImage: 0,
biXPelsPerMeter: 0,
biYPelsPerMeter: 0,
biClrUsed: 0,
biClrImportant: 0,
},
bmiColors: [um::wingdi::RGBQUAD {
rgbBlue: 0,
rgbGreen: 0,
rgbRed: 0,
rgbReserved: 0
}],
};
let mut my_dib_data: *mut ctypes::c_void = ptr::null_mut();
let hbitmap: shared::windef::HBITMAP = um::wingdi::CreateDIBSection(HDC_screen,
&bmi,
um::wingdi::DIB_RGB_COLORS,
&mut my_dib_data,
ptr::null_mut(),
0);
um::wingdi::SelectObject(HDC_compatible_DC, hbitmap as shared::windef::HGDIOBJ);
let my_bit_blt: shared::minwindef::BOOL = um::wingdi::BitBlt(HDC_compatible_DC,
0,
0,
1920,
1080,
HDC_screen,
0,
0,
um::wingdi::SRCCOPY);
println!("{}", my_bit_blt);
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question