I am using crate winsafe
and I want to know when a menu has been clicked.
flags & MF_MOUSESELECT as u16
It should be 1
when yes and 0
when no, but it always is 32768
.
Why?
self.wnd.on().wm(winsafe::co::WM::MENUSELECT, {
move |params| {
let wparam = params.wparam;
let lparam = params.lparam;
let flags = (wparam >> 16 & 0xffff) as u16;
let MF_MOUSESELECT = 0x00008000 as u32;
println!("{}", flags & MF_MOUSESELECT as u16);
// siempre 32768
0
}
});
According to https://docs.microsoft.com/en-us/windows/win32/menurc/wm-menuselect ,
WM_MENUSELECT
(winsafe::co::MF::MOUSESELECT
) is defined as0x00008000L
, which is equal to32768
.If you really need
0
or1
, you can use it(flags & MF_MENUSELECT) >> MF_MENUSELECT.trailing_zeros()
( ittrailing_zeros
means "zero bits at the end", and>>
it removes the same number of bits from the flag value).If you only need
false
ortrue
for a conditional, you can useflags & MF_MENUSELECT != 0
.