|
1 | 1 | use crate::win::util::to_wstr; |
2 | 2 | use crate::{PhySize, Size, WindowInfo, WindowOpenOptions, WindowScalePolicy}; |
3 | | -use raw_window_handle::{RawWindowHandle, Win32WindowHandle}; |
| 3 | +use raw_window_handle::Win32WindowHandle; |
4 | 4 | use std::cell::Cell; |
5 | 5 | use std::ffi::c_void; |
6 | 6 | use std::ptr::null_mut; |
7 | 7 | use winapi::shared::minwindef::{DWORD, UINT}; |
8 | 8 | use winapi::shared::windef::{HWND, RECT}; |
9 | 9 | use winapi::um::winuser::{ |
10 | | - AdjustWindowRectEx, CreateWindowExW, GetDpiForWindow, KillTimer, PostMessageW, |
11 | | - SetProcessDpiAwarenessContext, SetTimer, SetWindowPos, SWP_NOMOVE, SWP_NOZORDER, WM_USER, |
12 | | - WS_CAPTION, WS_CHILD, WS_CLIPSIBLINGS, WS_MAXIMIZEBOX, WS_MINIMIZEBOX, WS_POPUPWINDOW, |
| 10 | + AdjustWindowRectEx, CreateWindowExW, GetDpiForWindow, GetFocus, KillTimer, PostMessageW, |
| 11 | + SetFocus, SetProcessDpiAwarenessContext, SetTimer, SetWindowPos, SWP_NOMOVE, SWP_NOZORDER, |
| 12 | + WM_USER, WS_CAPTION, WS_CHILD, WS_CLIPSIBLINGS, WS_MAXIMIZEBOX, WS_MINIMIZEBOX, WS_POPUPWINDOW, |
13 | 13 | WS_SIZEBOX, WS_VISIBLE, |
14 | 14 | }; |
15 | 15 |
|
@@ -170,6 +170,17 @@ impl Win32Window { |
170 | 170 | self.current_size.set(new_size); |
171 | 171 | } |
172 | 172 |
|
| 173 | + pub fn has_focus(&self) -> bool { |
| 174 | + let focused_window = unsafe { GetFocus() }; |
| 175 | + focused_window == self.handle |
| 176 | + } |
| 177 | + |
| 178 | + pub fn focus(&self) { |
| 179 | + unsafe { |
| 180 | + SetFocus(self.handle); |
| 181 | + } |
| 182 | + } |
| 183 | + |
173 | 184 | pub fn handle(&self) -> HWND { |
174 | 185 | self.handle |
175 | 186 | } |
|
0 commit comments