Modify

Opened 14 years ago

Closed 14 years ago

#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:1 by anonymous, 14 years ago

EDIT:
instead of _GUICtrlMenu_AppendMenu3
should be _GUICtrlMenu_AppendMenu

comment:2 by Zedna, 14 years ago

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 J-Paul Mesnage, 14 years ago

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.

comment:4 by Zedna, 14 years ago

@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.

in reply to:  4 ; comment:5 by J-Paul Mesnage, 14 years ago

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

in reply to:  5 ; comment:6 by Zedna, 14 years ago

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

in reply to:  6 ; comment:7 by anonymous, 14 years ago

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 ???

in reply to:  7 comment:8 by J-Paul Mesnage, 14 years ago

anonymous is me

in reply to:  7 comment:9 by Zedna, 14 years ago

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 trancexx, 14 years ago

Milestone: 3.3.7.22
Owner: changed from Gary to trancexx
Resolution: Fixed
Status: newclosed

Fixed by revision [6454] in version: 3.3.7.22

Modify Ticket

Action
as closed The owner will remain trancexx.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.