1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#![warn(missing_docs)]
#![cfg(windows)]
#![allow(clippy::if_not_else)]

//! Easier wrappers for Win32 API stuff, safe when possible.

use core::{
  convert::TryFrom,
  ffi::c_void,
  ptr::{null, null_mut, NonNull},
};
use winapi::{
  shared::{
    minwindef::{ATOM, HINSTANCE, HMODULE},
    windef::{HBRUSH, HCURSOR, HDC, HICON, HMENU, HWND, POINT, RECT},
  },
  um::{winnt::HANDLE, winuser::WNDCLASSW},
};

mod consoleapi;
pub use consoleapi::*;

mod errhandlingapi;
pub use errhandlingapi::*;

mod libloaderapi;
pub use libloaderapi::*;

mod processenv;
pub use processenv::*;

mod profileapi;
pub use profileapi::*;

mod winbase;
pub use winbase::*;

mod wingdi;
pub use wingdi::*;

mod winuser;
pub use winuser::*;

/// Allocates a utf-16, null-terminated version of the `&str` given.
pub fn wide_null(s: &str) -> Vec<u16> {
  s.encode_utf16().chain(Some(0)).collect()
}

/// Newtype of [`ATOM`](winapi::shared::minwindef::ATOM).
///
/// This helps you avoid accidentally mixing an `ATOM` with other `u16` values,
/// but otherwise has no additional semantics.
#[repr(transparent)]
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
pub struct Atom(pub ATOM);

/// Laid out like [`POINT`](https://docs.microsoft.com/en-us/windows/win32/api/windef/ns-windef-point)
#[repr(C)]
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
#[allow(missing_docs)]
pub struct Point {
  pub x: i32,
  pub y: i32,
}

/// Rect that stores a corner point as well as a width and height.
#[repr(C)]
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
#[allow(missing_docs)]
pub struct PointSizeRect {
  pub x: i32,
  pub y: i32,
  pub width: i32,
  pub height: i32,
}

/// Rect that stores four edge locations.
///
/// Laid out like [`RECT`](https://docs.microsoft.com/en-us/windows/win32/api/windef/ns-windef-rect)
#[repr(C)]
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
#[allow(missing_docs)]
pub struct EdgeRect {
  pub left: i32,
  pub top: i32,
  pub right: i32,
  pub bottom: i32,
}