VAN0 Posted March 27, 2023 Share Posted March 27, 2023 (edited) Hello. When $TRAY_FOCUS used in TrayItemSetState(), how do we remove that state without removing and adding a new menu item? The state parameter is a bit counterintuitive, because it's bitwise state, however why would we need $TRAY_UNCHECKED or $TRAY_ENABLE states if absents of $TRAY_CHECKED or $TRAY_DISABLE bits would in theory be the same thing...Anyhow, since there is no unfocus bit, how do we remove the focus bit? expandcollapse popup#NoTrayIcon #include <TrayConstants.au3> ; Required for the $TRAY_CHECKED and $TRAY_ICONSTATE_SHOW constants. Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode. Example() Func Example() TrayCreateItem("Item 1") TrayItemSetState(-1, $TRAY_FOCUS) TrayItemSetState(-1, $TRAY_CHECKED) ConsoleWrite("Item 1 state: " & bits(TrayItemGetState(-1)) & " (" & TrayItemGetState(-1) & ")" & @CRLF) TrayCreateItem("Item 2") TrayItemSetState(-1, $TRAY_CHECKED) ConsoleWrite("Item 2 state: " & bits(TrayItemGetState(-1)) & " (" & TrayItemGetState(-1) & ")" & @CRLF) TrayCreateItem("Item 3") TrayItemSetState(-1, $TRAY_FOCUS) ConsoleWrite("Item 3 state: " & bits(TrayItemGetState(-1)) & " (" & TrayItemGetState(-1) & ")" & @CRLF) TrayCreateItem("Item 4") TrayItemSetState(-1, $TRAY_DISABLE) ConsoleWrite("Item 4 state: " & bits(TrayItemGetState(-1)) & " (" & TrayItemGetState(-1) & ")" & @CRLF) TrayCreateItem("Item 5") for $i = 0 to 4096 TrayItemSetState(-1, $i) Next ConsoleWrite("Item 5 state: " & bits(TrayItemGetState(-1)) & " (" & TrayItemGetState(-1) & ")" & @CRLF) TrayCreateItem("Item 6") for $i = 0 to 4096 TrayItemSetState(-1, $i) Next TrayItemSetState(-1, $TRAY_ENABLE) ConsoleWrite("Item 6 state: " & bits(TrayItemGetState(-1)) & " (" & TrayItemGetState(-1) & ")" & @CRLF) TrayCreateItem("Item 7") for $i = 0 to 4096 TrayItemSetState(-1, $i) Next TrayItemSetState(-1, 0) ConsoleWrite("Item 7 state: " & bits(TrayItemGetState(-1)) & " (" & TrayItemGetState(-1) & ")" & @CRLF) TrayCreateItem("") ; Create a separator line. Local $idExit = TrayCreateItem("Exit") TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu. While 1 Switch TrayGetMsg() Case $idExit ; Exit the loop. ExitLoop EndSwitch WEnd EndFunc ;==>Example Func bits($iNum) Local $sNum = "" While $iNum $sNum = BitAND($iNum, 1) & $sNum $iNum = BitShift($iNum, 1) WEnd $sNum = StringRight("0000000000000000" & $sNum, 15) If $sNum < 0 Then Return '1' & $sNum Return '0' & $sNum EndFunc Edited March 27, 2023 by VAN0 Link to comment Share on other sites More sharing options...
Dan_555 Posted March 27, 2023 Share Posted March 27, 2023 (edited) Maybe this is a bug. Currently it can be only removed by hovering the mouse over it. (I guess, if you have a Tutorial option in a Program, this can be used to show where user needs to go or to click ... ) If it is an issue, maybe you should open a ticket in the bug-tracker ? I have modified your code, a bit. Now you can check and uncheck the 1st menu item but the focus does not go away. expandcollapse popup#NoTrayIcon #include <TrayConstants.au3> ; Required For the $TRAY_CHECKED And $TRAY_ICONSTATE_SHOW constants. Opt("TrayMenuMode", 3) ; The default tray menu items will not be shown and items are not checked when selected. These are options 1 and 2 for TrayMenuMode. Example() Func Example() $ti = TrayCreateItem("Item 1") TrayItemSetState($ti, $TRAY_FOCUS) TrayItemSetState($ti, $TRAY_CHECKED) ConsoleWrite("Item 1 state: " & bits(TrayItemGetState($ti)) & " (" & TrayItemGetState($ti) & ")" & @CRLF) $pp = TrayCreateItem("Display menu 1 state") $pi = TrayCreateItem("Focus menu 1") $pc = TrayCreateItem("Check menu 1") $puc = TrayCreateItem("Uncheck menu 1") TrayCreateItem("") ; Create a separator line. Local $idExit = TrayCreateItem("Exit") TraySetState($TRAY_ICONSTATE_SHOW) ; Show the tray menu. While 1 Switch TrayGetMsg() Case $idExit ; Exit the loop. ExitLoop Case $pp ConsoleWrite("Item 1 state: " & bits(TrayItemGetState($ti)) & " (" & TrayItemGetState($ti) & ")" & @CRLF) Case $pi TrayItemSetState($ti, $TRAY_FOCUS) ConsoleWrite("Item 1 state: " & bits(TrayItemGetState($ti)) & " (" & TrayItemGetState($ti) & ")" & @CRLF) Case $pc TrayItemSetState($ti, $TRAY_CHECKED) ConsoleWrite("Item 1 state: " & bits(TrayItemGetState($ti)) & " (" & TrayItemGetState($ti) & ")" & @CRLF) Case $puc TrayItemSetState($ti, $TRAY_UNCHECKED) ConsoleWrite("Item 1 state: " & bits(TrayItemGetState($ti)) & " (" & TrayItemGetState($ti) & ")" & @CRLF) EndSwitch WEnd EndFunc ;==>Example Func bits($iNum) Local $sNum = "" While $iNum $sNum = BitAND($iNum, 1) & $sNum $iNum = BitShift($iNum, 1) WEnd $sNum = StringRight("0000000000000000" & $sNum, 15) If $sNum < 0 Then Return '1' & $sNum Return '0' & $sNum EndFunc ;==>bits Edited March 27, 2023 by Dan_555 Some of my script sourcecode Link to comment Share on other sites More sharing options...
Nine Posted March 27, 2023 Share Posted March 27, 2023 (edited) The problem is more deep than you think. By getting the hMenu of the tray menu, you can use Win32 API to modify it. But (oh surprise) even with pure Win32 API you cannot remove the focus state. So the problem is not AutoIt at all, it is a Windows issue (feature ?). Edited March 27, 2023 by Nine ioa747 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
VAN0 Posted March 28, 2023 Author Share Posted March 28, 2023 According to MENUITEMINFO structure there is a MFS_UNHILITE state, however autoit $tagMENUITEMINFO does not have this option... Link to comment Share on other sites More sharing options...
Nine Posted March 28, 2023 Share Posted March 28, 2023 Look MFS_UNHILITE has the same value (0x0000) as MFS_ENABLED or MFS_UNCHECKED. It just does not work. “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
VAN0 Posted March 28, 2023 Author Share Posted March 28, 2023 May I ask how did you test it bypassing autoit? As in setting state to 0, does nothing at all? Link to comment Share on other sites More sharing options...
Nine Posted March 28, 2023 Share Posted March 28, 2023 Simple : Local $hMenu = TrayItemGetHandle(0) Local $tInfo = DllStructCreate($tagMENUITEMINFO) DllStructSetData($tInfo, "Size", DllStructGetSize($tInfo)) DllStructSetData($tInfo, "Mask", $MIIM_STATE) DllStructSetData($tInfo, "State", 0) ; should remove check & hilite, but only check is done Local $aCall = DllCall("user32.dll", "bool", "SetMenuItemInfoW", "handle", $hMenu, "uint", 0, "bool", True, "struct*", $tInfo) Dan_555 and VAN0 2 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
VAN0 Posted March 28, 2023 Author Share Posted March 28, 2023 Well for the time being the only solution is to remove/re-add menu items Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now