Jump to content

How to know if a GUI drop-down menu is displayed or not?

Recommended Posts

Hi all!

I've created a GUI menu using $hFile = _GUICtrlMenu_CreateMenu(), $hView = _GUICtrlMenu_CreateMenu() etc and it works fine.

But I need a function which would tell me that a specific drop-down menu is actually displayed, and if so, what's its rect. I've searched in help and forum, but to no avail. Apparently there's no function similar to the hypothetic IsDropDownMenuDisplayed($hmenu) that would return true if the menu is expanded, nor I've found how another hypothetic function GetDropDOwnMenuRect that would return x1,y1,x2,y2 or similar.

In the attached screen capture, the drop down menu Statistiche is displayed, so IsMenuDisplayed($hStat) would return true, and GetDropDOwnMenuRect would return x1,y1,x2,y2 or similar.

Thanks in advance to who knows how to write those functions!

Kind regards


Immagine 2021-08-24 203804.jpg

Link to comment
Share on other sites

You can check if the menu is highlighted.  If true then it is displayed, otherwise it will be false.

As for the rect, you need to get the first and last item rect...

Here an example :

#include <GuiMenu.au3>
#include <Array.au3>


Func Example()

  If Not WinExists("[CLASS:Notepad]") Then Run("notepad.exe")
  Local $hWnd = WinGetHandle("[CLASS:Notepad]")
  Local $hMain = _GUICtrlMenu_GetMenu($hWnd)

  ConsoleWrite("Is it displayed ? " & _GUICtrlMenu_GetItemHighlighted($hMain, 0) & @CRLF)

  Local $aPos = _GUICtrlMenu_GetItemRect($hWnd, $hMain, 0)
  MouseClick("left", $aPos[0] + 10, $aPos[1] + 5, 1, 0)

  ConsoleWrite("Is it displayed now ? " & _GUICtrlMenu_GetItemHighlighted($hMain, 0) & @CRLF)

  Local $hFile = _GUICtrlMenu_GetItemSubMenu($hMain, 0)
  Local $iCount = _GUICtrlMenu_GetItemCount($hFile)

  Local $aRect = _GUICtrlMenu_GetItemRect($hWnd, $hFile, 0)
  Local $aLast = _GUICtrlMenu_GetItemRect($hWnd, $hFile, $iCount - 1)
  $aRect[2] = $aLast[2]
  $aRect[3] = $aRect[3]


EndFunc   ;==>Example


Edited by Nine
Link to comment
Share on other sites

Hi Nine, thanks for looking into it!

I didn't manage to make work your example, applied on my situation. I've tried the single line first: is it displayed? My menu structure is as shown below. My try was to check whether the drop-down "Statistiche" is displayed. The position of that drop-down is 3 and it is a child of $hMain. But, I'm getting all the time false, when the menu Statistiche is displayed or not. 

Kind regards


$hMain = _GUICtrlMenu_CreateMenu()
    _GUICtrlMenu_InsertMenuItem($hMain, 0, "&File", 0, $hFile)
    _GUICtrlMenu_InsertMenuItem($hMain, 1, "&Trova", 0, $hTrova)
    _GUICtrlMenu_InsertMenuItem($hMain, 2, "&Visualizza", 0, $hVisualizza)
    _GUICtrlMenu_InsertMenuItem($hMain, 3, "&Statistiche", 0, $hStatistiche)
    If $p= 0 Then _GUICtrlMenu_InsertMenuItem($hMain, 4, "&Archivia", 0, $hArchivia)
    If $p = 0 Then _GUICtrlMenu_InsertMenuItem($hMain, 5, "A&rricchisci", 0, $hArricchisci)
    If $p = 0 Then _GUICtrlMenu_InsertMenuItem($hMain, 6, "&Strumenti", 0, $hStrumenti)
    _GUICtrlMenu_InsertMenuItem($hMain, 7, "&Guida", 0, $hGUI_Arch_menuda)

    ; Set window menu
    _GUICtrlMenu_SetMenu($hGUI_Arch_menu, $hMain)

    Local $aAccelKeys[2][2] = [["^1", $e_idArch_Zmin], ["^2", $e_idArch_Zmed]]


    ; Loop until the user exits.
    Global $hDLL = DllOpen("user32.dll")
    While 1
        $msg = GUIGetMsg()
        ConsoleWrite("Is it displayed ? " & _GUICtrlMenu_GetItemHighlighted($hMain, 3) & @CRLF)


Link to comment
Share on other sites

You need to specify $MNS_MODELESS in the creation of the main menu.  Please next time provide a runable snippet of code.  It is not very hard to produce and it facilitates the ones who are trying to help you.  Here :

#include <GUIConstantsEx.au3>
#include <GuiMenu.au3>


Func Example()
    Local $hGUI, $hFile, $hEdit, $hHelp, $hMain
    Local Enum $e_idNew = 1000, $e_idOpen, $e_idSave, $e_idExit, $e_idCut, $e_idCopy, $e_idPaste

    ; Create GUI
    $hGUI = GUICreate("Menu", 400, 300)

    ; Create File menu
    $hFile = _GUICtrlMenu_CreateMenu()
    _GUICtrlMenu_InsertMenuItem($hFile, 0, "&New", $e_idNew)
    _GUICtrlMenu_InsertMenuItem($hFile, 1, "&Open", $e_idOpen)
    _GUICtrlMenu_InsertMenuItem($hFile, 2, "&Save", $e_idSave)
    _GUICtrlMenu_InsertMenuItem($hFile, 3, "", 0)
    _GUICtrlMenu_InsertMenuItem($hFile, 4, "E&xit", $e_idExit)

    ; Create Edit menu
    $hEdit = _GUICtrlMenu_CreateMenu()
    _GUICtrlMenu_InsertMenuItem($hEdit, 0, "&Cut", $e_idCut)
    _GUICtrlMenu_InsertMenuItem($hEdit, 1, "C&opy", $e_idCopy)
    _GUICtrlMenu_InsertMenuItem($hEdit, 2, "&Paste", $e_idPaste)

    ; Create Help menu
    $hHelp = _GUICtrlMenu_CreateMenu()

    ; Create Main menu
    $hMain = _GUICtrlMenu_CreateMenu($MNS_MODELESS)
    _GUICtrlMenu_InsertMenuItem($hMain, 0, "&File", 0, $hFile)
    _GUICtrlMenu_InsertMenuItem($hMain, 1, "&Edit", 0, $hEdit)
    _GUICtrlMenu_InsertMenuItem($hMain, 2, "&Help", 0, $hHelp)

    ; Set window menu
    _GUICtrlMenu_SetMenu($hGUI, $hMain)

    ; Loop until the user exits.
      ConsoleWrite("Is it displayed ? " & _GUICtrlMenu_GetItemHighlighted($hMain, 1) & @CRLF)
    Until GUIGetMsg() = $GUI_EVENT_CLOSE
EndFunc   ;==>Example


Link to comment
Share on other sites

Thank you so much, Nine!

I would surely paste the code, but it is over 500 lines and in order to be tested appropriately, it requires Picasa 3.9 to be installed, running and have some content. That's the reason I didn't post it.

I will try your example ASAP and will let you know!

Kindest regards


Link to comment
Share on other sites

Understand that a snippet of 500 lines for us is not appropriate.  This is why you should always find a representative code that we can run easily.  Most of the time, the examples coming from the help file are simple enough to adapt to the issue you are having.

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

  • Recently Browsing   0 members

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