Skip to content

Commit 6a70fca

Browse files
committed
fix esc exiting the app when in a textbox
1 parent 4d66b3b commit 6a70fca

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

native-windows-gui/src/win32/window.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,13 @@ unsafe extern "system" fn process_events(hwnd: HWND, msg: UINT, w: WPARAM, l: LP
574574
_ /* WM_KEYUP */ => Event::OnKeyRelease,
575575
};
576576

577+
// Block the textbox ESC key from closing the whole application
578+
if w == 27 {
579+
if is_textbox_control(hwnd) {
580+
return 0;
581+
}
582+
}
583+
577584
let keycode = w as u32;
578585
let data = EventData::OnKey(keycode);
579586
callback(evt, data, base_handle);
@@ -1026,6 +1033,17 @@ unsafe fn handle_default_notify_callback<'a>(notif_raw: *const NMHDR, callback:
10261033
}
10271034
}
10281035

1036+
unsafe fn is_textbox_control(hwnd: HWND) -> bool {
1037+
use winapi::um::winnt::WCHAR;
1038+
use winapi::um::winuser::GetClassNameW;
1039+
1040+
let mut class_name_raw: [WCHAR; 100] = [0; 100];
1041+
let count = GetClassNameW(hwnd, class_name_raw.as_mut_ptr(), 100) as usize;
1042+
let class_name = OsString::from_wide(&class_name_raw[..count]).into_string().unwrap_or("".to_string());
1043+
1044+
class_name == "Edit" || class_name == "RICHEDIT50W"
1045+
}
1046+
10291047
//
10301048
// Hack to make `GetWindowSubclass` work on GNU
10311049
//

0 commit comments

Comments
 (0)