#2034 closed Bug (Fixed)
_GUICtrlMenu_AppendMenu - bug when BitOr($MF_BYPOSITION, $MF_STRING) is used
| Reported by: | Zedna | Owned by: | trancexx |
|---|---|---|---|
| Milestone: | 3.3.7.22 | Component: | Standard UDFs |
| Version: | 3.3.7.18 | Severity: | None |
| Keywords: | Cc: |
Description
MSDN link to AppendMenu API
[http://msdn.microsoft.com/en-us/library/windows/desktop/ms647616%28v=vs.85%29.aspx
]
I use it this way
$Form1 = GUICreate(...)
CreateSystemMenuItem("") ; separator
$id_about = CreateSystemMenuItem("About")
Func CreateSystemMenuItem($sText, $hMenu = -1)
If $hMenu = -1 Then $hMenu = _GUICtrlMenu_GetSystemMenu($Form1, 0)
Local $nID = GUICtrlCreateDummy()
Local $nFlags = 0
If $sText = "" Then $nFlags = $MF_SEPARATOR
$nFlags = BitOr($MF_BYPOSITION, $nFlags)
_GUICtrlMenu_AppendMenu($hMenu, $nFlags, $nID, $sText)
Return $nID
EndFunc
On older Autoit 3.2.12.1 it was OK but on latest beta _GUICtrlMenu_AppendMenu() was changed and it doesn't work --> About system menu item is not created (separator is OK). Tested on beta 3.3.7.18.
I discovered source of problem:
Func _GUICtrlMenu_AppendMenu3($hMenu, $iFlags, $iNewItem, $pNewItem)
Local $sType= "ptr"
If BitAND($iFlags, $MF_STRING) = $MF_STRING Then $sType= "wstr" ; --> CORRECTION
; If $iFlags = 0 Then $sType= "wstr" ; $MF_STRING is equal to 0 ; --> BUG HERE
Local $aResult = DllCall("User32.dll", "bool", "AppendMenuW", "handle", $hMenu, "uint", $iFlags, "uint_ptr", $iNewItem, $sType, $pNewItem)
If @error Then Return SetError(@error, @extended, False)
If $aResult[0] = 0 Then Return SetError(10, 0, False)
_GUICtrlMenu_DrawMenuBar(_GUICtrlMenu_FindParent($hMenu))
Return True
EndFunc ;==>_GUICtrlMenu_AppendMenu
Instead of
If $iFlags = 0 Then $sType= "wstr"
is needed to use
If BitAND($iFlags, $MF_STRING) = $MF_STRING Then $sType= "wstr"
because wstr type should be used for MF_STRING no matter what other flags (MF_BYPOSITION) are used
Attachments (0)
Change History (10)
comment:2 by , on Oct 14, 2011 at 7:39:39 PM
EDIT2:
Now I noticed that using $MF_BYPOSITION in AppendMenu is not correct
because this flag is used in other menu functions like DeleteMenu,GetMenuString,GetMenuState,...
but my above correction still should be used
because wstr type should be used for MF_STRING flag no matter what other flags are used together with it (BitOr)
comment:3 by , on Nov 5, 2011 at 3:17:46 PM
I am sure the suggested fix is not correct as
BitAND($iFlags, $MF_STRING)
is always equal to
$MF_STRING
so $sType will never be set to "ptr".
For me you ask for a separator and you get it. Perhaps the doc is not enough precise when you use it for system menu.
follow-up: 5 comment:4 by , on Nov 6, 2011 at 10:58:21 AM
@jpm
You are wrong.
$iFlags can be for example MF_BITMAP and also combined by BitOr() with other MF_xxx flags.
So my fix is correct.
I discovered this problem in my project where About in system menu was missing after upgrade from Autoit 3.2.12.1 to latest beta. My above fix corrected the problem.
As I said before, finally I removed from my project code line adding MF_BYPOSITION as it's not correct in this context so without it it works fine also with latest beta.
follow-up: 6 comment:5 by , on Nov 6, 2011 at 12:05:07 PM
Replying to Zedna:
@jpm
You are wrong.
$iFlags can be for example MF_BITMAP and also combined by BitOr() with other MF_xxx flags.
So my fix is correct.
I discovered this problem in my project where About in system menu was missing after upgrade from Autoit 3.2.12.1 to latest beta. My above fix corrected the problem.
As I said before, finally I removed from my project code line adding MF_BYPOSITION as it's not correct in this context so without it it works fine also with latest beta.
Perhaps I am wrong but
BitAND($iFlags, $MF_STRING)
is always equal to 0
as $MF_STRING is equal to 0 whatever $iFlags value
So the comparison with $MF_STRING is always true
So I don't know what is the solution if one is needed as your example want to create a sparator line which is what the release/beta is doing
I agree that $MF_STRING defined as 0 is a strange value but that what MS defined to
follow-up: 7 comment:6 by , on Nov 7, 2011 at 12:34:32 AM
Replying to Jpm:
BitAND($iFlags, $MF_STRING)
is always equal to 0
as $MF_STRING is equal to 0 whatever $iFlags value
AHA! I didn't know that MF_STRING=0
follow-ups: 8 9 comment:7 by , on Nov 7, 2011 at 8:24:41 AM
comment:9 by , on Nov 7, 2011 at 11:03:07 AM
Replying to anonymous:
Replying to Zedna:
Replying to Jpm:
BitAND($iFlags, $MF_STRING)
is always equal to 0
as $MF_STRING is equal to 0 whatever $iFlags value
AHA! I didn't know that MF_STRING=0
So no BUG ???
I don't know yet. I don't have time to think about it/test it right now deeply.
I want only say what was source our diferrent opinion.
comment:10 by , on Nov 27, 2011 at 11:25:09 PM
| Milestone: | → 3.3.7.22 |
|---|---|
| Owner: | changed from to |
| Resolution: | → Fixed |
| Status: | new → closed |
Fixed by revision [6454] in version: 3.3.7.22

EDIT:
instead of _GUICtrlMenu_AppendMenu3
should be _GUICtrlMenu_AppendMenu