1 #![cfg(target_os = "windows")]
2 
3 use std::os::raw::c_void;
4 
5 use libc;
6 use winapi::shared::windef::HWND;
7 
8 use {DeviceId, EventsLoop, Icon, MonitorId, Window, WindowBuilder};
9 use platform::EventsLoop as WindowsEventsLoop;
10 
11 /// Additional methods on `EventsLoop` that are specific to Windows.
12 pub trait EventsLoopExt {
13     /// By default, winit on Windows will attempt to enable process-wide DPI awareness. If that's
14     /// undesirable, you can create an `EventsLoop` using this function instead.
new_dpi_unaware() -> Self where Self: Sized15     fn new_dpi_unaware() -> Self where Self: Sized;
16 }
17 
18 impl EventsLoopExt for EventsLoop {
19     #[inline]
new_dpi_unaware() -> Self20     fn new_dpi_unaware() -> Self {
21         EventsLoop {
22             events_loop: WindowsEventsLoop::with_dpi_awareness(false),
23             _marker: ::std::marker::PhantomData,
24         }
25     }
26 }
27 
28 /// Additional methods on `Window` that are specific to Windows.
29 pub trait WindowExt {
30     /// Returns the native handle that is used by this window.
31     ///
32     /// The pointer will become invalid when the native window was destroyed.
get_hwnd(&self) -> *mut libc::c_void33     fn get_hwnd(&self) -> *mut libc::c_void;
34 
35     /// This sets `ICON_BIG`. A good ceiling here is 256x256.
set_taskbar_icon(&self, taskbar_icon: Option<Icon>)36     fn set_taskbar_icon(&self, taskbar_icon: Option<Icon>);
37 }
38 
39 impl WindowExt for Window {
40     #[inline]
get_hwnd(&self) -> *mut libc::c_void41     fn get_hwnd(&self) -> *mut libc::c_void {
42         self.window.hwnd() as *mut _
43     }
44 
45     #[inline]
set_taskbar_icon(&self, taskbar_icon: Option<Icon>)46     fn set_taskbar_icon(&self, taskbar_icon: Option<Icon>) {
47         self.window.set_taskbar_icon(taskbar_icon)
48     }
49 }
50 
51 /// Additional methods on `WindowBuilder` that are specific to Windows.
52 pub trait WindowBuilderExt {
53     /// Sets a parent to the window to be created.
with_parent_window(self, parent: HWND) -> WindowBuilder54     fn with_parent_window(self, parent: HWND) -> WindowBuilder;
55 
56     /// This sets `ICON_BIG`. A good ceiling here is 256x256.
with_taskbar_icon(self, taskbar_icon: Option<Icon>) -> WindowBuilder57     fn with_taskbar_icon(self, taskbar_icon: Option<Icon>) -> WindowBuilder;
58 
59     /// This sets `WS_EX_NOREDIRECTIONBITMAP`.
with_no_redirection_bitmap(self, flag: bool) -> WindowBuilder60     fn with_no_redirection_bitmap(self, flag: bool) -> WindowBuilder;
61 }
62 
63 impl WindowBuilderExt for WindowBuilder {
64     #[inline]
with_parent_window(mut self, parent: HWND) -> WindowBuilder65     fn with_parent_window(mut self, parent: HWND) -> WindowBuilder {
66         self.platform_specific.parent = Some(parent);
67         self
68     }
69 
70     #[inline]
with_taskbar_icon(mut self, taskbar_icon: Option<Icon>) -> WindowBuilder71     fn with_taskbar_icon(mut self, taskbar_icon: Option<Icon>) -> WindowBuilder {
72         self.platform_specific.taskbar_icon = taskbar_icon;
73         self
74     }
75 
76     #[inline]
with_no_redirection_bitmap(mut self, flag: bool) -> WindowBuilder77     fn with_no_redirection_bitmap(mut self, flag: bool) -> WindowBuilder {
78         self.platform_specific.no_redirection_bitmap = flag;
79         self
80     }
81 }
82 
83 /// Additional methods on `MonitorId` that are specific to Windows.
84 pub trait MonitorIdExt {
85     /// Returns the name of the monitor adapter specific to the Win32 API.
native_id(&self) -> String86     fn native_id(&self) -> String;
87 
88     /// Returns the handle of the monitor - `HMONITOR`.
hmonitor(&self) -> *mut c_void89     fn hmonitor(&self) -> *mut c_void;
90 }
91 
92 impl MonitorIdExt for MonitorId {
93     #[inline]
native_id(&self) -> String94     fn native_id(&self) -> String {
95         self.inner.get_native_identifier()
96     }
97 
98     #[inline]
hmonitor(&self) -> *mut c_void99     fn hmonitor(&self) -> *mut c_void {
100         self.inner.get_hmonitor() as *mut _
101     }
102 }
103 
104 /// Additional methods on `DeviceId` that are specific to Windows.
105 pub trait DeviceIdExt {
106     /// Returns an identifier that persistently refers to this specific device.
107     ///
108     /// Will return `None` if the device is no longer available.
get_persistent_identifier(&self) -> Option<String>109     fn get_persistent_identifier(&self) -> Option<String>;
110 }
111 
112 impl DeviceIdExt for DeviceId {
113     #[inline]
get_persistent_identifier(&self) -> Option<String>114     fn get_persistent_identifier(&self) -> Option<String> {
115         self.0.get_persistent_identifier()
116     }
117 }
118