fix: update console window handling
This commit is contained in:
parent
805ba16c2c
commit
fc7dd809fe
38
src/main.rs
38
src/main.rs
|
@ -1,7 +1,8 @@
|
||||||
#![windows_subsystem = "windows"]
|
#![windows_subsystem = "windows"]
|
||||||
|
|
||||||
|
use std::{ffi::OsStr, os::windows::ffi::OsStrExt};
|
||||||
|
|
||||||
use tray::TrayApp;
|
use tray::TrayApp;
|
||||||
use winapi::um::{self, wincon, winuser};
|
|
||||||
|
|
||||||
mod controller;
|
mod controller;
|
||||||
mod devices;
|
mod devices;
|
||||||
|
@ -11,21 +12,32 @@ mod tray;
|
||||||
fn main() {
|
fn main() {
|
||||||
unsafe {
|
unsafe {
|
||||||
// Allocate new console for the process
|
// Allocate new console for the process
|
||||||
um::consoleapi::AllocConsole();
|
winapi::um::consoleapi::AllocConsole();
|
||||||
|
|
||||||
// Modify the console window's style to remove the system menu (close, minimize, etc.).
|
let title: Vec<u16> = OsStr::new("Razer Battery Report Debug Console")
|
||||||
winuser::SetWindowLongPtrW(
|
.encode_wide()
|
||||||
wincon::GetConsoleWindow(),
|
.chain(std::iter::once(0))
|
||||||
winuser::GWL_STYLE,
|
.collect();
|
||||||
#[allow(clippy::cast_possible_wrap)]
|
winapi::um::wincon::SetConsoleTitleW(title.as_ptr());
|
||||||
{
|
|
||||||
winuser::GetWindowLongPtrW(wincon::GetConsoleWindow(), winuser::GWL_STYLE)
|
let hwnd = winapi::um::wincon::GetConsoleWindow();
|
||||||
& !winuser::WS_SYSMENU as isize
|
|
||||||
},
|
// Disable close command in the sys.menu of the new console, otherwise the whole process will quit: https://stackoverflow.com/a/12015131/126995
|
||||||
);
|
if !hwnd.is_null() {
|
||||||
|
let hmenu = winapi::um::winuser::GetSystemMenu(hwnd, 0);
|
||||||
|
if !hmenu.is_null() {
|
||||||
|
winapi::um::winuser::DeleteMenu(
|
||||||
|
hmenu,
|
||||||
|
winapi::um::winuser::SC_CLOSE as u32,
|
||||||
|
winapi::um::winuser::MF_BYCOMMAND,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Hide the console window
|
// Hide the console window
|
||||||
winuser::ShowWindow(wincon::GetConsoleWindow(), winuser::SW_HIDE);
|
if !hwnd.is_null() {
|
||||||
|
winapi::um::winuser::ShowWindow(hwnd, winapi::um::winuser::SW_HIDE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::env::set_var("RUST_LOG", "trace");
|
std::env::set_var("RUST_LOG", "trace");
|
||||||
|
|
Loading…
Reference in New Issue