1
0
Fork 0

windows: WindowHandle.app_run_blocking()

This commit is contained in:
William Light 2020-09-11 18:29:38 +02:00
parent 196883b390
commit 17a7477400

View file

@ -141,6 +141,29 @@ pub struct Window {
hwnd: HWND, hwnd: HWND,
} }
pub struct WindowHandle {
hwnd: HWND
}
impl WindowHandle {
pub fn app_run_blocking(self) {
unsafe {
let mut msg: MSG = std::mem::zeroed();
loop {
let status = GetMessageA(&mut msg, self.hwnd, 0, 0);
if status == -1 {
break;
}
TranslateMessage(&mut msg);
DispatchMessageA(&mut msg);
}
}
}
}
impl Window { impl Window {
pub fn open<H: WindowHandler>(options: WindowOpenOptions) -> WindowHandle { pub fn open<H: WindowHandler>(options: WindowOpenOptions) -> WindowHandle {
unsafe { unsafe {
@ -203,24 +226,12 @@ impl Window {
let win = Rc::new(RefCell::new(window)); let win = Rc::new(RefCell::new(window));
SetWindowLongPtrA(hwnd, GWLP_USERDATA, Rc::into_raw(win) as *const _ as _); SetWindowLongPtrA(hwnd, GWLP_USERDATA, Rc::into_raw(win) as *const _ as _);
SetTimer(hwnd, 4242, 13, None); SetTimer(hwnd, 4242, 13, None);
// todo: decide what to do with the message pump WindowHandle {
if parent.is_null() { hwnd
let mut msg: MSG = std::mem::zeroed();
loop {
let status = GetMessageA(&mut msg, hwnd, 0, 0);
if status == -1 {
break;
}
TranslateMessage(&mut msg);
DispatchMessageA(&mut msg);
}
} }
} }
WindowHandle
} }
} }
@ -232,5 +243,3 @@ unsafe impl HasRawWindowHandle for Window {
}) })
} }
} }
pub struct WindowHandle;