Guest User

Untitled

a guest
Dec 29th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 1.99 KB | None | 0 0
  1. use std::mem::zeroed;
  2. use winapi::shared::windef::HBITMAP;
  3. use winapi::shared::windef::HDC;
  4. use winapi::shared::windef::HGDIOBJ;
  5. use winapi::um::wingdi::BitBlt;
  6. use winapi::um::wingdi::CreateCompatibleBitmap;
  7. use winapi::um::wingdi::CreateCompatibleDC;
  8. use winapi::um::wingdi::DeleteDC;
  9. use winapi::um::wingdi::DeleteObject;
  10. use winapi::um::wingdi::GetDIBits;
  11. use winapi::um::wingdi::SelectObject;
  12. use winapi::um::wingdi::BITMAPINFO;
  13. use winapi::um::wingdi::DIB_RGB_COLORS;
  14. use winapi::um::wingdi::SRCCOPY;
  15. use winapi::um::winuser::GetDC;
  16. use winapi::um::winuser::GetDesktopWindow;
  17.  
  18. fn main() {
  19.     const width: i32 = 1000;
  20.     const height: i32 = 500;
  21.     unsafe {
  22.         let desktopHandle = GetDesktopWindow();
  23.         let mut windowDC = GetDC(desktopHandle);
  24.         let outputBitmap = CreateCompatibleBitmap(windowDC, width, height);
  25.         let blitDC = CreateCompatibleDC(windowDC);
  26.         let oldBitmap = SelectObject(blitDC, outputBitmap as HGDIOBJ);
  27.         BitBlt(blitDC, 0, 0, width, height, windowDC, 0, 0, SRCCOPY);
  28.         SelectObject(blitDC, oldBitmap);
  29.         let mut bi = zeroed::<BITMAPINFO>();
  30.         bi.bmiHeader.biSize = 40;
  31.         let ok = GetDIBits(
  32.             blitDC,
  33.             outputBitmap,
  34.             0,
  35.             height as u32,
  36.             std::ptr::null_mut(),
  37.             &mut bi,
  38.             DIB_RGB_COLORS,
  39.         );
  40.         if ok != 0 {
  41.             let mut bih = bi.bmiHeader;
  42.             bih.biHeight = -(bih.biHeight).abs();
  43.             bi.bmiHeader.biCompression = 0;
  44.             createImage(blitDC, outputBitmap, bi);
  45.             // return image
  46.         }
  47.  
  48.         DeleteObject(outputBitmap as HGDIOBJ);
  49.         DeleteDC(blitDC);
  50.     }
  51. }
  52.  
  53. fn createImage(hdc: HDC, outputBitmap: HBITMAP, bi: BITMAPINFO) {
  54.     let bih = bi.bmiHeader;
  55.     let height = bih.biHeight.abs();
  56.     let bitCount = bih.biBitCount as i32;
  57.     let strideBits = bih.biWidth * bitCount;
  58.     let strideBytesAligned = (((strideBits - 1) | 0x1F) + 1) >> 3;
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment