How to use dll "DestroyMenu"? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
eqv
Posts: 72
Joined: 18 Sep 2018, 22:17

How to use dll "DestroyMenu"?

22 Aug 2021, 10:49

Hello everyone. I'm trying to destroy the menu from a window, using this script:

Code: Select all

Sleep, 1000	;;  time-for-selectWindow

v := DllCall("GetMenu",uint,WinActive( "A" ))
DllCall("DestroyMenu",uint,v)
Msgbox % "Menu expected to be remove"

WinActivate
v:=DllCall("GetMenu",uint,WinActive( "A" ))
Msgbox % "still showing: " v
If I try a similar dll, it returns the error code ("-1"):

Code: Select all

Sleep, 1000	;;  time-for-selectWindow
v := DllCall("GetMenu",uint,WinActive( "A" ))
w := DllCall("GetMenuItemCount",uint,v)
Msgbox % w
So I guess, I just using incorrectly the function. I would be very grateful if someone could clarify how to use it.

(PS - I know the next code hide it, but I want to destroy it:)

Code: Select all

Sleep, 1000	;;  time-for-selectWindow
v := DllCall("GetMenu",uint,WinActive( "A" ))
Msgbox % "Hide Menu"
DllCall("SetMenu", uint, WinExist(""), uint, 0)
Msgbox % "Show Menu, using it hwnd: " v
DllCall("SetMenu", uint, WinExist(""), uint, v)
Sources:
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getmenu
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-destroymenu
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getmenuitemcount
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setmenu
teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: How to use dll "DestroyMenu"?

22 Aug 2021, 11:34

Code: Select all

$F1:: DllCall("SetMenu", "Ptr", WinExist("A"), "Ptr", 0)
eqv
Posts: 72
Joined: 18 Sep 2018, 22:17

Re: How to use dll "DestroyMenu"?

22 Aug 2021, 11:38

teadrinker wrote:
22 Aug 2021, 11:34

Code: Select all

$F1:: DllCall("SetMenu", "Ptr", WinExist("A"), "Ptr", 0)
Thanks, but I already knew this method (see my "PS" from my post).
teadrinker
Posts: 4412
Joined: 29 Mar 2015, 09:41
Contact:

Re: How to use dll "DestroyMenu"?  Topic is solved

22 Aug 2021, 12:02

Code: Select all

$F1::
   if !hMenu := DllCall("GetMenu", "Ptr", WinExist("A"), "Ptr")
      throw "Failed to get window menu"
   DllCall("SetMenu", "Ptr", WinExist("A"), "Ptr", 0)
   if !DllCall("DestroyMenu", "Ptr", hMenu)
      throw "Failed to destroy menu"
   Return
eqv
Posts: 72
Joined: 18 Sep 2018, 22:17

Re: How to use dll "DestroyMenu"?

22 Aug 2021, 12:12

teadrinker wrote:
22 Aug 2021, 12:02

Code: Select all

$F1::
   if !hMenu := DllCall("GetMenu", "Ptr", WinExist("A"), "Ptr")
      throw "Failed to get window menu"
   DllCall("SetMenu", "Ptr", WinExist("A"), "Ptr", 0)
   if !DllCall("DestroyMenu", "Ptr", hMenu)
      throw "Failed to destroy menu"
   Return
Awesome!! Works as expected 👍. It seems that I need to "SetMenu" to 0 first.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: peter_ahk and 382 guests