diff --git a/examples/topmost.rs b/examples/topmost.rs new file mode 100644 index 0000000..555de12 --- /dev/null +++ b/examples/topmost.rs @@ -0,0 +1,23 @@ +use minifb::{Key, ScaleMode, Window, WindowOptions}; + +fn main() { + // Allocate the output buffer. + let buf = vec![0x00FFFF00; 320 * 480]; + + let mut window = Window::new( + "Press ESC to exit", + 320, + 480, + WindowOptions { + resize: true, + scale_mode: ScaleMode::Center, + topmost: true, + ..WindowOptions::default() + }, + ) + .expect("Unable to open Window"); + + while window.is_open() && !window.is_key_down(Key::Escape) { + window.update_with_buffer(&buf, 320, 480).unwrap(); + } +} diff --git a/src/os/windows/mod.rs b/src/os/windows/mod.rs index e60d57b..36c77ef 100644 --- a/src/os/windows/mod.rs +++ b/src/os/windows/mod.rs @@ -610,6 +610,10 @@ impl Window { }, }; + if opts.topmost { + window.topmost(true) + } + Ok(window) } } @@ -986,6 +990,25 @@ impl Window { Some(t) } } + + #[inline] + fn topmost(&self, topmost: bool) { + unsafe { + winuser::SetWindowPos( + self.window.unwrap(), + if topmost == true { + winuser::HWND_TOPMOST + } else { + winuser::HWND_TOP + }, + 0, + 0, + 0, + 0, + winuser::SWP_SHOWWINDOW | winuser::SWP_NOSIZE | winuser::SWP_NOMOVE, + ); + } + } } #[derive(Clone)]