Skip to content

Instantly share code, notes, and snippets.

@thewh1teagle
Created July 4, 2024 11:44
Show Gist options
  • Save thewh1teagle/4d8b607fda91d106c94f995429434b0d to your computer and use it in GitHub Desktop.
Save thewh1teagle/4d8b607fda91d106c94f995429434b0d to your computer and use it in GitHub Desktop.
Hide app from taskbar in tauri windows 11
// windows = { version = "0.58.0", features = ["Win32", "Win32_UI", "Win32_UI_WindowsAndMessaging"] }
#[tauri::command]
fn set_app_visible(app: AppHandle, visible: bool) {
use windows::Win32::UI::WindowsAndMessaging::{
GetWindowLongPtrW, SetWindowLongPtrW, GWL_EXSTYLE, WS_EX_APPWINDOW, WS_EX_TOOLWINDOW,
};
use windows::Win32::Foundation::HWND;
use std::os::raw::c_void;
for (_, webview) in app.webview_windows() {
let hwnd = webview.hwnd().unwrap();
unsafe {
// Get current extended window style
let ex_style = GetWindowLongPtrW(HWND(hwnd.0 as *mut c_void), GWL_EXSTYLE) as u32;
// Modify the extended window style based on the visibility argument
let new_ex_style = if visible {
(ex_style & !WS_EX_TOOLWINDOW.0) | WS_EX_APPWINDOW.0
} else {
(ex_style & !WS_EX_APPWINDOW.0) | WS_EX_TOOLWINDOW.0
};
// Set the new extended window style
SetWindowLongPtrW(HWND(hwnd.0 as *mut c_void), GWL_EXSTYLE, new_ex_style as isize);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment