Jump to content

Using DllCall with MSDN Menu functions like InsertMenu


Recommended Posts

Hi y'all,

I found wonderful code from picasso, Modded Calculator that appends newmenu items to a menu using DllCall to user32.dll

in same thread I made a post about trying to use it with InsertMenu rather than AppendMenu to enable position of the newly inserted menu items.

It works partly but popup submenu does not work yet - - -

Been studying the MSDN documentation without success so far...

any directions would be much appreciated

-hq

Link to comment
Share on other sites

Hi y'all,

I found wonderful code from picasso, Modded Calculator that appends newmenu items to a menu using DllCall to user32.dll

in same thread I made a post about trying to use it with InsertMenu rather than AppendMenu to enable position of the newly inserted menu items.

It works partly but popup submenu does not work yet - - -

Been studying the MSDN documentation without success so far...

any directions would be much appreciated

-hq

The Menu API calls for use with external programs are fully documented in Auto3Lib.
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

The Menu API calls for use with external programs are fully documented in Auto3Lib.

Thanks PaulIA - This is helpful and I did check it twice.

It looks to me like the library refers to the AutoIt function below

My issue rather seems to be with trying to get proper syntax of the direct DllCall for AppendMenu (original Modcalc.au3) vs my desired modification using InsertMenu

I'm trying to get the BYPOSITION and to work together with the POPUP flag

When using POPUP flag only the newmenu appears ok but doesnt add the handle of the popup window, which is needes in the subsequent lines

; Original using AppendMenu (works fine)

DllCall("user32.dll","int","AppendMenu","hwnd",$hMenuTarget,"int",$MFT_POPUP,"hwnd",$hSubMenuTarget,"str","&NewMenu")

; Desired modification using InsertMenu and MF_BYPOSITION

; this use of InsertMenu shows newmenu in correct position but no submenus ;;; returns ControlID 16 to console:

DllCall("user32.dll","int","InsertMenu","hwnd",$hMenuTarget,"int",2,"int",$MF_BYPOSITION,"int",$MFT_POPUP,"str","&NewMenu")

; this use of InsertMenu causes fatal crash ; unable to execute DllCall;

DllCall("user32.dll","int","InsertMenu","hwnd",$hMenuTarget,"int",2,"int",$MF_BYPOSITION,"int",$MFT_POPUP,"hwnd",$hSubMenuTarget,"str","&NewMenu")

; This function from A3LMenu.au3
; #FUNCTION# =====================================================================================================
; Description ...: Inserts a new menu item at the specified position in a menu
; Parameters ....: $hMenu       - Handle of the menu
;                  $iItem       - Position of the menu item before which to insert the new item
;                  $tInfo       - _tagMENUITEMINFO structure
;                  $fByPos      - If True, $iItem is a menu item position otherwise it is a menu item  identifier.
; Return values .: Success      - True
;                  Failure      - False
; Author ........: Paul Campbell (PaulIA)
; Remarks .......:
; Related .......: _Menu_AddMenuItem, _tagMENUITEMINFO
; ====================================================================================================
Func _Menu_InsertMenuItem($hMenu, $iItem, ByRef $tInfo, $fByPos=True)
  Local $pInfo, $aResult

  $pInfo   = _tagGetPtr($tInfo)
  $aResult = DllCall("User32.dll", "int", "InsertMenuItem", "hwnd", $hMenu, "int", $iItem, "int", $fByPos, "ptr", $pInfo)
  Return $aResult[0] <> 0
EndFunc
Link to comment
Share on other sites

Thanks PaulIA - This is helpful and I did check it twice.

It looks to me like the library refers to the AutoIt function below

My issue rather seems to be with trying to get proper syntax of the direct DllCall for AppendMenu (original Modcalc.au3) vs my desired modification using InsertMenu

I'm trying to get the BYPOSITION and to work together with the POPUP flag

When using POPUP flag only the newmenu appears ok but doesnt add the handle of the popup window, which is needes in the subsequent lines

; Original using AppendMenu (works fine)

DllCall("user32.dll","int","AppendMenu","hwnd",$hMenuTarget,"int",$MFT_POPUP,"hwnd",$hSubMenuTarget,"str","&NewMenu")

; Desired modification using InsertMenu and MF_BYPOSITION

; this use of InsertMenu shows newmenu in correct position but no submenus ;;; returns ControlID 16 to console:

DllCall("user32.dll","int","InsertMenu","hwnd",$hMenuTarget,"int",2,"int",$MF_BYPOSITION,"int",$MFT_POPUP,"str","&NewMenu")

; this use of InsertMenu causes fatal crash ; unable to execute DllCall;

DllCall("user32.dll","int","InsertMenu","hwnd",$hMenuTarget,"int",2,"int",$MF_BYPOSITION,"int",$MFT_POPUP,"hwnd",$hSubMenuTarget,"str","&NewMenu")

; This function from A3LMenu.au3
; #FUNCTION# =====================================================================================================
; Description ...: Inserts a new menu item at the specified position in a menu
; Parameters ....: $hMenu       - Handle of the menu
;                  $iItem       - Position of the menu item before which to insert the new item
;                  $tInfo       - _tagMENUITEMINFO structure
;                  $fByPos      - If True, $iItem is a menu item position otherwise it is a menu item  identifier.
; Return values .: Success      - True
;                  Failure      - False
; Author ........: Paul Campbell (PaulIA)
; Remarks .......:
; Related .......: _Menu_AddMenuItem, _tagMENUITEMINFO
; ====================================================================================================
Func _Menu_InsertMenuItem($hMenu, $iItem, ByRef $tInfo, $fByPos=True)
  Local $pInfo, $aResult

  $pInfo   = _tagGetPtr($tInfo)
  $aResult = DllCall("User32.dll", "int", "InsertMenuItem", "hwnd", $hMenu, "int", $iItem, "int", $fByPos, "ptr", $pInfo)
  Return $aResult[0] <> 0
EndFunc
You might want to check it a third time. :whistle: The A3LMenu file has all of the Menu functions, including AppendMenu and InsertMenu. The only difference between AppendMenu and InsertMenu is the postion. AppendMenu always tacks the menu item on at the end and InsertMenu allows you to specify the position. There is also a difference between InsertMenu and InsertMenuItem, which you are calling with the wrong parameters, hence the crash. Take some time and look at the demos and study the A3LMenu file. I think everything you are trying to do is already done for you.
Auto3Lib: A library of over 1200 functions for AutoIt
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...