Support topmost functionality in Windows (#201)

Most of this was taken from #159. This does not include the API addition of adding a topmost call on Window.

That should probably be in another PR. And the doc fixes as well.

Used implementation from https://github.com/emoon/rust_minifb/pull/159#discussion_r401374050

Co-authored-by: phillvancejr <phillipvancejr@gmail.com>
Co-authored-by: Daniel Collin <daniel@collin.com>

Co-authored-by: phillvancejr <phillipvancejr@gmail.com>
Co-authored-by: Daniel Collin <daniel@collin.com>
This commit is contained in:
Nelson Chen 2020-07-27 00:27:13 -07:00 committed by GitHub
parent 49004f4380
commit 291d8a0441
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 0 deletions

23
examples/topmost.rs Normal file
View file

@ -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();
}
}

View file

@ -610,6 +610,10 @@ impl Window {
}, },
}; };
if opts.topmost {
window.topmost(true)
}
Ok(window) Ok(window)
} }
} }
@ -986,6 +990,25 @@ impl Window {
Some(t) 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)] #[derive(Clone)]