From 17a74774003920e7fc543353a14d3141e84825c9 Mon Sep 17 00:00:00 2001 From: William Light Date: Fri, 11 Sep 2020 18:29:38 +0200 Subject: [PATCH] windows: WindowHandle.app_run_blocking() --- src/win/window.rs | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/src/win/window.rs b/src/win/window.rs index 944a012..955bb21 100644 --- a/src/win/window.rs +++ b/src/win/window.rs @@ -141,6 +141,29 @@ pub struct Window { 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 { pub fn open(options: WindowOpenOptions) -> WindowHandle { unsafe { @@ -203,24 +226,12 @@ impl Window { let win = Rc::new(RefCell::new(window)); SetWindowLongPtrA(hwnd, GWLP_USERDATA, Rc::into_raw(win) as *const _ as _); - SetTimer(hwnd, 4242, 13, None); - // todo: decide what to do with the message pump - if parent.is_null() { - 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 { + hwnd } } - - WindowHandle } } @@ -232,5 +243,3 @@ unsafe impl HasRawWindowHandle for Window { }) } } - -pub struct WindowHandle;