Skip to content

Commit

Permalink
Disable close button on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
james58899 committed Dec 13, 2023
1 parent 5a8e6a7 commit f58759b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,12 +634,20 @@ fn build_tray_icon() {
fn switch_window(hide: bool) {
use windows::Win32::{
System::Console::{AllocConsole, GetConsoleWindow},
UI::WindowsAndMessaging::{ShowWindow, SW_HIDE, SW_SHOW},
UI::WindowsAndMessaging::{DeleteMenu, GetSystemMenu, ShowWindow, MF_BYCOMMAND, SC_CLOSE, SW_HIDE, SW_SHOW},
};

let mut window = unsafe { GetConsoleWindow() };
if window.0 == 0 && unsafe { AllocConsole().is_ok() } {
window = unsafe { GetConsoleWindow() };

// Try Disable close button
let menu = unsafe { GetSystemMenu(window, false) };
if !menu.is_invalid() {
unsafe {
let _ = DeleteMenu(menu, SC_CLOSE, MF_BYCOMMAND);
};
}
}

if window.0 != 0 {
Expand Down

0 comments on commit f58759b

Please sign in to comment.