Modify

Opened 13 years ago

Closed 13 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 Changed 13 years ago by anonymous

EDIT:
instead of _GUICtrlMenu_AppendMenu3
should be _GUICtrlMenu_AppendMenu

comment:2 Changed 13 years ago by Zedna

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 Changed 13 years ago by Jpm

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 follow-up: Changed 13 years ago by 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.

comment:5 in reply to: ↑ 4 ; follow-up: Changed 13 years ago by Jpm

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

comment:6 in reply to: ↑ 5 ; follow-up: Changed 13 years ago by 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

comment:7 in reply to: ↑ 6 ; follow-ups: Changed 13 years ago by 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 ???

comment:8 in reply to: ↑ 7 Changed 13 years ago by Jpm

anonymous is me

comment:9 in reply to: ↑ 7 Changed 13 years ago by Zedna

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 Changed 13 years ago by trancexx

  • Milestone set to 3.3.7.22
  • Owner changed from Gary to trancexx
  • Resolution set to Fixed
  • Status changed from new to closed

Fixed by revision [6454] in version: 3.3.7.22

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The owner will remain trancexx.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.