Trait winsafe::prelude::gdi_Hdc

source ·
pub trait gdi_Hdc: user_Hdc {
Show 80 methods // Provided methods fn AbortPath(&self) -> SysResult<()> { ... } fn AlphaBlend( &self, origin_dest: RECT, hdc_src: &HDC, origin_src: RECT, ftn: &BLENDFUNCTION ) -> SysResult<()> { ... } fn AngleArc( &self, center: POINT, radius: u32, start_angle: f32, sweep_angle: f32 ) -> SysResult<()> { ... } fn Arc( &self, bound: RECT, radial_start: POINT, radial_end: POINT ) -> SysResult<()> { ... } fn ArcTo( &self, bound: RECT, radial_start: POINT, radial_end: POINT ) -> SysResult<()> { ... } fn BeginPath(&self) -> SysResult<()> { ... } fn BitBlt( &self, dest_pos: POINT, sz: SIZE, hdc_src: &HDC, src_src: POINT, rop: ROP ) -> SysResult<()> { ... } fn CancelDC(&self) -> SysResult<()> { ... } fn Chord( &self, bounds: RECT, start_radial: POINT, end_radial: POINT ) -> SysResult<()> { ... } fn CloseFigure(&self) -> SysResult<()> { ... } fn CreateCompatibleBitmap( &self, cx: i32, cy: i32 ) -> SysResult<DeleteObjectGuard<HBITMAP>> { ... } fn CreateCompatibleDC(&self) -> SysResult<DeleteDCGuard> { ... } fn CreateHalftonePalette(&self) -> SysResult<DeleteObjectPaletteGuard> { ... } fn Ellipse(&self, bound: RECT) -> SysResult<()> { ... } fn EndPath(&self) -> SysResult<()> { ... } fn FillPath(&self) -> SysResult<()> { ... } fn FillRect(&self, rc: RECT, hbr: &HBRUSH) -> SysResult<()> { ... } fn FillRgn(&self, rgn: &HRGN, brush: &HBRUSH) -> SysResult<()> { ... } fn FlattenPath(&self) -> SysResult<()> { ... } fn FrameRgn( &self, rgn: &HRGN, brush: &HBRUSH, w: i32, h: i32 ) -> SysResult<()> { ... } fn GetBkColor(&self) -> SysResult<COLORREF> { ... } fn GetBkMode(&self) -> SysResult<BKMODE> { ... } fn GetDCBrushColor(&self) -> SysResult<COLORREF> { ... } fn GetCurrentObject(&self, kind: CUR_OBJ) -> SysResult<CurObj> { ... } fn GetDCPenColor(&self) -> SysResult<COLORREF> { ... } unsafe fn GetDIBits( &self, hbm: &HBITMAP, first_scan_line: u32, num_scan_lines: u32, bmp_data_buf: Option<&mut [u8]>, bmi: &mut BITMAPINFO, usage: DIB ) -> SysResult<i32> { ... } fn GetDeviceCaps(&self, index: GDC) -> i32 { ... } fn GetStretchBltMode(&self) -> SysResult<STRETCH_MODE> { ... } fn GetTextColor(&self) -> SysResult<COLORREF> { ... } fn GetTextExtentPoint32(&self, text: &str) -> SysResult<SIZE> { ... } fn GetTextFace(&self) -> SysResult<String> { ... } fn GetTextMetrics(&self, tm: &mut TEXTMETRIC) -> SysResult<()> { ... } fn GetViewportExtEx(&self) -> SysResult<SIZE> { ... } fn GetViewportOrgEx(&self) -> SysResult<POINT> { ... } fn GetWindowExtEx(&self) -> SysResult<SIZE> { ... } fn GetWindowOrgEx(&self) -> SysResult<POINT> { ... } fn HiMetricToPixel(&self, x: i32, y: i32) -> (i32, i32) { ... } fn LineTo(&self, x: i32, y: i32) -> SysResult<()> { ... } fn MoveToEx(&self, x: i32, y: i32, pt: Option<&mut POINT>) -> SysResult<()> { ... } fn PatBlt(&self, top_left: POINT, sz: SIZE, rop: ROP) -> SysResult<()> { ... } fn PathToRegion(&self) -> SysResult<DeleteObjectGuard<HRGN>> { ... } fn Pie( &self, bounds: RECT, radial_1: POINT, radial_2: POINT ) -> SysResult<()> { ... } fn PixelToHiMetric(&self, x: i32, y: i32) -> (i32, i32) { ... } fn PolyBezier(&self, pts: &[POINT]) -> SysResult<()> { ... } fn PolyBezierTo(&self, pts: &[POINT]) -> SysResult<()> { ... } fn Polyline(&self, pts: &[POINT]) -> SysResult<()> { ... } fn PolylineTo(&self, pts: &[POINT]) -> SysResult<()> { ... } fn PtVisible(&self, x: i32, y: i32) -> SysResult<bool> { ... } fn RealizePalette(&self) -> SysResult<u32> { ... } fn Rectangle(&self, bounds: RECT) -> SysResult<()> { ... } fn RestoreDC(&self, saved_dc: i32) -> SysResult<()> { ... } fn RoundRect(&self, bounds: RECT, sz: SIZE) -> SysResult<()> { ... } fn SaveDC(&self) -> SysResult<i32> { ... } fn SelectClipPath(&self, mode: RGN) -> SysResult<()> { ... } fn SelectClipRgn(&self, rgn: &HRGN) -> SysResult<REGION> { ... } fn SelectObject<G>( &self, hgdiobj: &G ) -> SysResult<SelectObjectGuard<'_, Self, G>> where G: GdiObject { ... } fn SelectPalette( &self, hpal: &HPALETTE, force_bkgd: bool ) -> SysResult<Option<HPALETTE>> { ... } fn SetArcDirection(&self, dir: AD) -> SysResult<AD> { ... } fn SetBkColor(&self, color: COLORREF) -> SysResult<COLORREF> { ... } fn SetBkMode(&self, mode: BKMODE) -> SysResult<BKMODE> { ... } fn SetBrushOrgEx(&self, new_origin: POINT) -> SysResult<POINT> { ... } fn SetDCBrushColor(&self, color: COLORREF) -> SysResult<COLORREF> { ... } fn SetDCPenColor(&self, color: COLORREF) -> SysResult<COLORREF> { ... } fn SetDIBits( &self, hbm: &HBITMAP, first_scan_line: u32, num_scan_lines: u32, dib_color_data: &[u8], bmi: &BITMAPINFO, color_use: DIB ) -> SysResult<i32> { ... } fn SetGraphicsMode(&self, mode: GM) -> SysResult<GM> { ... } fn SetStretchBltMode(&self, mode: STRETCH_MODE) -> SysResult<STRETCH_MODE> { ... } fn SetTextAlign(&self, align: TA) -> SysResult<TA> { ... } fn SetTextColor(&self, color: COLORREF) -> SysResult<COLORREF> { ... } fn SetTextJustification(&self, extra: i32, count: i32) -> SysResult<()> { ... } fn SetViewportExtEx(&self, x: i32, y: i32) -> SysResult<SIZE> { ... } fn SetViewportOrgEx(&self, x: i32, y: i32) -> SysResult<POINT> { ... } fn SetWindowExtEx(&self, x: i32, y: i32) -> SysResult<SIZE> { ... } fn SetWindowOrgEx(&self, x: i32, y: i32) -> SysResult<POINT> { ... } fn StretchBlt( &self, pos_dest: POINT, sz_dest: SIZE, hdc_src: &HDC, pt_src: POINT, sz_src: SIZE, rop: ROP ) -> SysResult<()> { ... } fn StrokeAndFillPath(&self) -> SysResult<()> { ... } fn StrokePath(&self) -> SysResult<()> { ... } fn TextOut(&self, x: i32, y: i32, text: &str) -> SysResult<()> { ... } fn TransparentBlt( &self, dest_top_left: POINT, dest_sz: SIZE, hdc_src: HDC, src_top_left: POINT, src_sz: SIZE, color_transparent: COLORREF ) -> SysResult<()> { ... } fn UpdateColors(&self) -> SysResult<()> { ... } fn WidenPath(&self) -> SysResult<()> { ... }
}
Available on crate features kernel and gdi only.
Expand description

This trait is enabled with the gdi feature, and provides methods for HDC.

Prefer importing this trait through the prelude:

use winsafe::prelude::*;

Provided Methods§

source

fn AbortPath(&self) -> SysResult<()>

AborthPath function.

source

fn AlphaBlend( &self, origin_dest: RECT, hdc_src: &HDC, origin_src: RECT, ftn: &BLENDFUNCTION ) -> SysResult<()>

AlphaBlend function.

source

fn AngleArc( &self, center: POINT, radius: u32, start_angle: f32, sweep_angle: f32 ) -> SysResult<()>

AngleArc function.

source

fn Arc( &self, bound: RECT, radial_start: POINT, radial_end: POINT ) -> SysResult<()>

Arc function.

source

fn ArcTo( &self, bound: RECT, radial_start: POINT, radial_end: POINT ) -> SysResult<()>

ArcTo function.

source

fn BeginPath(&self) -> SysResult<()>

BeginPath function.

source

fn BitBlt( &self, dest_pos: POINT, sz: SIZE, hdc_src: &HDC, src_src: POINT, rop: ROP ) -> SysResult<()>

BitBlt function.

source

fn CancelDC(&self) -> SysResult<()>

CancelDC function.

source

fn Chord( &self, bounds: RECT, start_radial: POINT, end_radial: POINT ) -> SysResult<()>

Chord function.

source

fn CloseFigure(&self) -> SysResult<()>

CloseFigure function.

source

fn CreateCompatibleBitmap( &self, cx: i32, cy: i32 ) -> SysResult<DeleteObjectGuard<HBITMAP>>

source

fn CreateCompatibleDC(&self) -> SysResult<DeleteDCGuard>

source

fn CreateHalftonePalette(&self) -> SysResult<DeleteObjectPaletteGuard>

source

fn Ellipse(&self, bound: RECT) -> SysResult<()>

Ellipse function.

source

fn EndPath(&self) -> SysResult<()>

EndPath function.

source

fn FillPath(&self) -> SysResult<()>

FillPath function.

source

fn FillRect(&self, rc: RECT, hbr: &HBRUSH) -> SysResult<()>

FillRect function.

source

fn FillRgn(&self, rgn: &HRGN, brush: &HBRUSH) -> SysResult<()>

FillRgn function.

source

fn FlattenPath(&self) -> SysResult<()>

FlattenPath function.

source

fn FrameRgn(&self, rgn: &HRGN, brush: &HBRUSH, w: i32, h: i32) -> SysResult<()>

FrameRgn function.

source

fn GetBkColor(&self) -> SysResult<COLORREF>

GetBkColor function.

source

fn GetBkMode(&self) -> SysResult<BKMODE>

GetBkMode function.

source

fn GetDCBrushColor(&self) -> SysResult<COLORREF>

GetDCBrushColor function.

source

fn GetCurrentObject(&self, kind: CUR_OBJ) -> SysResult<CurObj>

GetCurrentObject function.

§Examples
use winsafe::{self as w, prelude::*, co};

let hdc: w::HDC; // initialized somewhere

let obj = hdc.GetCurrentObject(co::CUR_OBJ::BRUSH)?;
let w::CurObj::Brush(hbrush) = obj else { panic!("never") };

println!("HBRUSH: {}", hbrush);
w::SysResult::Ok(())
source

fn GetDCPenColor(&self) -> SysResult<COLORREF>

GetDCPenColor function.

source

unsafe fn GetDIBits( &self, hbm: &HBITMAP, first_scan_line: u32, num_scan_lines: u32, bmp_data_buf: Option<&mut [u8]>, bmi: &mut BITMAPINFO, usage: DIB ) -> SysResult<i32>

GetDIBits function.

§Safety

If bmpDataBuf is smaller than needed, you’ll have a buffer overflow.

§Examples

Taking a screenshot and saving to file:

use winsafe::{self as w, prelude::*, co};

let cx_screen = w::GetSystemMetrics(co::SM::CXSCREEN);
let cy_screen = w::GetSystemMetrics(co::SM::CYSCREEN);

let hdc_screen = w::HWND::DESKTOP.GetDC()?;
let hbmp = hdc_screen.CreateCompatibleBitmap(cx_screen, cy_screen)?;
let hdc_mem = hdc_screen.CreateCompatibleDC()?;
let _hbmp_guard = hdc_mem.SelectObject(&*hbmp)?;

hdc_mem.BitBlt(w::POINT::new(0, 0), w::SIZE::new(cx_screen, cy_screen),
    &hdc_screen, w::POINT::new(0, 0), co::ROP::SRCCOPY)?;

let mut bmp_obj = w::BITMAP::default();
hbmp.GetObject(&mut bmp_obj)?;

let mut bi = w::BITMAPINFO::default();
bi.bmiHeader.biWidth = cx_screen;
bi.bmiHeader.biHeight = cy_screen;
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biBitCount = 32;
bi.bmiHeader.biCompression = co::BI::RGB;

let bmp_size = (bmp_obj.bmWidth * (bi.bmiHeader.biBitCount as i32) + 31)
    / 32 * 4 * bmp_obj.bmHeight;
let mut data_buf = vec![0u8; bmp_size as _];

unsafe {
    hdc_screen.GetDIBits(&hbmp, 0, cy_screen as _,
        Some(&mut data_buf), &mut bi, co::DIB::RGB_COLORS)?;
}

let mut bfh = w::BITMAPFILEHEADER::default();
bfh.bfOffBits = (std::mem::size_of::<w::BITMAPFILEHEADER>()
    + std::mem::size_of::<w::BITMAPINFOHEADER>()) as _;
bfh.bfSize = bfh.bfOffBits + (bmp_size as u32);

let fo = w::File::open("C:\\Temp\\foo.bmp", w::FileAccess::OpenOrCreateRW)?;
fo.write(bfh.serialize())?;
fo.write(bi.bmiHeader.serialize())?;
fo.write(&data_buf)?;
source

fn GetDeviceCaps(&self, index: GDC) -> i32

GetDeviceCaps function.

source

fn GetStretchBltMode(&self) -> SysResult<STRETCH_MODE>

source

fn GetTextColor(&self) -> SysResult<COLORREF>

GetTextColor function.

source

fn GetTextExtentPoint32(&self, text: &str) -> SysResult<SIZE>

source

fn GetTextFace(&self) -> SysResult<String>

GetTextFace function.

source

fn GetTextMetrics(&self, tm: &mut TEXTMETRIC) -> SysResult<()>

GetTextMetrics function.

source

fn GetViewportExtEx(&self) -> SysResult<SIZE>

GetViewportExtEx function.

source

fn GetViewportOrgEx(&self) -> SysResult<POINT>

GetViewportOrgEx function.

source

fn GetWindowExtEx(&self) -> SysResult<SIZE>

GetWindowExtEx function.

source

fn GetWindowOrgEx(&self) -> SysResult<POINT>

GetWindowOrgEx function.

source

fn HiMetricToPixel(&self, x: i32, y: i32) -> (i32, i32)

AtlHiMetricToPixel function.

Converts HIMETRIC units to pixels. The inverse operation is HDC::PixelToHiMetric.

source

fn LineTo(&self, x: i32, y: i32) -> SysResult<()>

LineTo function.

source

fn MoveToEx(&self, x: i32, y: i32, pt: Option<&mut POINT>) -> SysResult<()>

MoveToEx function.

source

fn PatBlt(&self, top_left: POINT, sz: SIZE, rop: ROP) -> SysResult<()>

PatBlt function.

source

fn PathToRegion(&self) -> SysResult<DeleteObjectGuard<HRGN>>

PathToRegion function.

source

fn Pie(&self, bounds: RECT, radial_1: POINT, radial_2: POINT) -> SysResult<()>

Pie function.

source

fn PixelToHiMetric(&self, x: i32, y: i32) -> (i32, i32)

AtlPixelToHiMetric function.

Converts pixels to HIMETRIC units. The inverse operation is HDC::HiMetricToPixel.

source

fn PolyBezier(&self, pts: &[POINT]) -> SysResult<()>

PolyBezier function.

source

fn PolyBezierTo(&self, pts: &[POINT]) -> SysResult<()>

PolyBezierTo function.

source

fn Polyline(&self, pts: &[POINT]) -> SysResult<()>

Polyline function.

source

fn PolylineTo(&self, pts: &[POINT]) -> SysResult<()>

PolylineTo function.

source

fn PtVisible(&self, x: i32, y: i32) -> SysResult<bool>

PtVisible function.

source

fn RealizePalette(&self) -> SysResult<u32>

RealizePalette function.

source

fn Rectangle(&self, bounds: RECT) -> SysResult<()>

Rectangle function.

source

fn RestoreDC(&self, saved_dc: i32) -> SysResult<()>

RestoreDC function.

source

fn RoundRect(&self, bounds: RECT, sz: SIZE) -> SysResult<()>

RoundRect function.

source

fn SaveDC(&self) -> SysResult<i32>

SaveDC function.

source

fn SelectClipPath(&self, mode: RGN) -> SysResult<()>

SelectClipPath function.

source

fn SelectClipRgn(&self, rgn: &HRGN) -> SysResult<REGION>

SelectClipRgn function.

source

fn SelectObject<G>( &self, hgdiobj: &G ) -> SysResult<SelectObjectGuard<'_, Self, G>>
where G: GdiObject,

SelectObject function.

In the original C implementation, SelectObject returns a handle to the object being replaced. You must perform a cleanup operation, calling SelectObject again, passing the handle to the replaced object.

Here, the cleanup is performed automatically, because SelectObject returns a SelectObjectGuard, which stores the replaced handle and calls SelectObject automatically when the guard goes out of scope. You must, however, keep the guard alive, otherwise the cleanup will be performed right away.

§Examples
use winsafe::{self as w, prelude::*, co};

let hdc: w::HDC; // initialized somewhere

let hpen = w::HPEN::CreatePen(
    co::PS::SOLID,
    1,
    w::COLORREF::new(0xff, 0x00, 0x88),
)?;

let _pen_guard = hdc.SelectObject(&*hpen); // keep guard alive
source

fn SelectPalette( &self, hpal: &HPALETTE, force_bkgd: bool ) -> SysResult<Option<HPALETTE>>

SelectPalette function.

source

fn SetArcDirection(&self, dir: AD) -> SysResult<AD>

SetArcDirection function.

source

fn SetBkColor(&self, color: COLORREF) -> SysResult<COLORREF>

SetBkColor function.

source

fn SetBkMode(&self, mode: BKMODE) -> SysResult<BKMODE>

SetBkMode function.

source

fn SetBrushOrgEx(&self, new_origin: POINT) -> SysResult<POINT>

SetBrushOrgEx function.

source

fn SetDCBrushColor(&self, color: COLORREF) -> SysResult<COLORREF>

SetDCBrushColor function.

source

fn SetDCPenColor(&self, color: COLORREF) -> SysResult<COLORREF>

SetDCPenColor function.

source

fn SetDIBits( &self, hbm: &HBITMAP, first_scan_line: u32, num_scan_lines: u32, dib_color_data: &[u8], bmi: &BITMAPINFO, color_use: DIB ) -> SysResult<i32>

SetDIBits function.

source

fn SetGraphicsMode(&self, mode: GM) -> SysResult<GM>

SetGraphicsMode function.

source

fn SetStretchBltMode(&self, mode: STRETCH_MODE) -> SysResult<STRETCH_MODE>

source

fn SetTextAlign(&self, align: TA) -> SysResult<TA>

SetTextAlign function.

source

fn SetTextColor(&self, color: COLORREF) -> SysResult<COLORREF>

SetTextColor function.

source

fn SetTextJustification(&self, extra: i32, count: i32) -> SysResult<()>

source

fn SetViewportExtEx(&self, x: i32, y: i32) -> SysResult<SIZE>

SetViewportExtEx function.

source

fn SetViewportOrgEx(&self, x: i32, y: i32) -> SysResult<POINT>

SetViewportOrgEx function.

source

fn SetWindowExtEx(&self, x: i32, y: i32) -> SysResult<SIZE>

SetWindowExtEx function.

source

fn SetWindowOrgEx(&self, x: i32, y: i32) -> SysResult<POINT>

SetWindowOrgEx function.

source

fn StretchBlt( &self, pos_dest: POINT, sz_dest: SIZE, hdc_src: &HDC, pt_src: POINT, sz_src: SIZE, rop: ROP ) -> SysResult<()>

StretchBlt function.

source

fn StrokeAndFillPath(&self) -> SysResult<()>

source

fn StrokePath(&self) -> SysResult<()>

StrokePath function.

source

fn TextOut(&self, x: i32, y: i32, text: &str) -> SysResult<()>

TextOut function.

source

fn TransparentBlt( &self, dest_top_left: POINT, dest_sz: SIZE, hdc_src: HDC, src_top_left: POINT, src_sz: SIZE, color_transparent: COLORREF ) -> SysResult<()>

TransparentBlt function.

source

fn UpdateColors(&self) -> SysResult<()>

UpdateColors function.

source

fn WidenPath(&self) -> SysResult<()>

WidenPath function.

Object Safety§

This trait is not object safe.

Implementors§