Jump to content

Dropdown Menu Buttons


Recommended Posts

Hello, how are you? I need help creating a menu but a dropdown of buttons. I have this idea, but I would like to know if it can be done in another way, since when entering an option and returning to attract, the menu by buttons no longer works. Thank you very much in advance.

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <DateTimeConstants.au3>
#include <MsgBoxConstants.au3>
#include <Constants.au3>
#include <GUIConstants.au3>
#include <FontConstants.au3>
#include <WinAPI.au3>
#include <WinAPISysWin.au3>
#include <Array.au3>
#include <GuiEdit.au3>
#NoTrayIcon






;Ventanas
Dim $VIngreP


;Funciones Principales
Prin ()

 Func Prin ()

$VIngreP = GUICreate("Ingreso", 601, 201, iniread("cord.ini", "Section", "X-Pos2", 0), iniread("cord.ini", "Section", "Y-Pos2", 0))
GUISetBkColor(0xFFFFFF)

GUICtrlSetFont(-1, 12, 800, 0, "Times New Roman")
$Button2 = GUICtrlCreateButton("Ingreso", 24, 152, 161, 33)
GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")
GUICtrlSetCursor (-1, 0)
Local $ingreDummy = GUICtrlCreateDummy()
        Local $ingreContext = GUICtrlCreateContextMenu($ingreDummy)
        Local $PP = GUICtrlCreateMenuItem("He", $ingreContext)
        Local $PT = GUICtrlCreateMenuItem("Hi", $ingreContext)

$Button3 = GUICtrlCreateButton("Ingreso d", 216, 152, 161, 33)
GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")
GUICtrlSetCursor (-1, 0)
Local $resulDummy = GUICtrlCreateDummy()
       Local $resulContext = GUICtrlCreateContextMenu($resulDummy)
       Local $RP = GUICtrlCreateMenuItem("lol", $resulContext)
       Local $RT = GUICtrlCreateMenuItem("Cool", $resulContext)
       Local $RA =GUICtrlCreateMenuItem("holl", $resulContext)

$Button4 = GUICtrlCreateButton("Busqueda", 410, 152, 161, 33)
GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")
GUICtrlSetCursor (-1, 0)
Local $busqueDummy = GUICtrlCreateDummy()
        Local $busqueContext = GUICtrlCreateContextMenu($busqueDummy)
        Local $BP = GUICtrlCreateMenuItem("cool", $busqueContext)
        Local $BT = GUICtrlCreateMenuItem("roll", $busqueContext)
        Local $BA =GUICtrlCreateMenuItem("jkl", $busqueContext)
GUISetState(@SW_SHOW)


While 1
$a = wingetpos("Ingreso")
        $nMsg = GUIGetMsg()
        Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button2
          ShowMenu($VIngreP, $nMsg, $ingreContext)
       Case $PP
       Case $PT
       Case $Button3
          ShowMenu($VIngreP, $nMsg, $resulContext)
       Case $RP
       Case $RT
       Case $RA
       Case $Button4
          ShowMenu($VIngreP, $nMsg, $busqueContext)
       Case $BP
       Case $BT
       Case $BA
       EndSwitch

iniwrite("cord.ini", "Section", "X-Pos2", $a[0])
iniwrite("cord.ini", "Section", "Y-Pos2", $a[1])
WEnd

 EndFunc

; Cordenadas de Menu Contextual
Func ShowMenu($hWnd, $idCtrl, $idContext)
        Local $aPos, $x, $y
        Local $hMenu = GUICtrlGetHandle($idContext)

        $aPos = ControlGetPos($hWnd, "", $idCtrl)

        $x = $aPos[0]
        $y = $aPos[1] + $aPos[3]

        ClientToScreen($hWnd, $x, $y)
        TrackPopupMenu($hWnd, $hMenu, $x, $y)
EndFunc   ;==>ShowMenu

; Convert the client (GUI) coordinates to screen (desktop) coordinates
Func ClientToScreen($hWnd, ByRef $x, ByRef $y)
        Local $tPoint = DllStructCreate("int;int")

        DllStructSetData($tPoint, 1, $x)
        DllStructSetData($tPoint, 2, $y)

        DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "struct*", $tPoint)

        $x = DllStructGetData($tPoint, 1)
        $y = DllStructGetData($tPoint, 2)
        ; release Struct not really needed as it is a local
        $tPoint = 0
EndFunc   ;==>ClientToScreen

; Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd)
Func TrackPopupMenu($hWnd, $hMenu, $x, $y)
        DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
EndFunc   ;==>TrackPopupMenu

 

Link to comment
Share on other sites

Not exactly sure what is not working.  Looks good to me.

I do not know where you got this code, but it seems kind of oldish. No offense.  Here a streamlined version :

#include <GUIConstants.au3>
#include <Constants.au3>
#include <WinAPISysWin.au3>
#include <GuiMenu.au3>
#NoTrayIcon

Opt("MustDeclareVars", True)

Prin()

Func Prin()
  Local $hGUI = GUICreate("Ingreso", 601, 201, IniRead("coord.ini", "Position", "X-Pos", 0), IniRead("coord.ini", "Position", "Y-Pos", 0))
  GUISetBkColor(0xFFFFFF)

  GUICtrlSetFont(-1, 12, 800, 0, "Times New Roman")
  Local $Button2 = GUICtrlCreateButton("Ingreso", 24, 152, 161, 33)
  GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")
  GUICtrlSetCursor(-1, 0)
  Local $ingreDummy = GUICtrlCreateDummy()
  Local $ingreContext = GUICtrlCreateContextMenu($ingreDummy)
  Local $PP = GUICtrlCreateMenuItem("He", $ingreContext)
  Local $PT = GUICtrlCreateMenuItem("Hi", $ingreContext)

  Local $Button3 = GUICtrlCreateButton("Ingreso d", 216, 152, 161, 33)
  GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")
  GUICtrlSetCursor(-1, 0)
  Local $resulDummy = GUICtrlCreateDummy()
  Local $resulContext = GUICtrlCreateContextMenu($resulDummy)
  Local $RP = GUICtrlCreateMenuItem("lol", $resulContext)
  Local $RT = GUICtrlCreateMenuItem("Cool", $resulContext)
  Local $RA = GUICtrlCreateMenuItem("holl", $resulContext)

  Local $Button4 = GUICtrlCreateButton("Busqueda", 410, 152, 161, 33)
  GUICtrlSetFont(-1, 12, 400, 2, "Times New Roman")
  GUICtrlSetCursor(-1, 0)
  Local $busqueDummy = GUICtrlCreateDummy()
  Local $busqueContext = GUICtrlCreateContextMenu($busqueDummy)
  Local $BP = GUICtrlCreateMenuItem("cool", $busqueContext)
  Local $BT = GUICtrlCreateMenuItem("roll", $busqueContext)
  Local $BA = GUICtrlCreateMenuItem("jkl", $busqueContext)
  GUISetState()

  GUIRegisterMsg($WM_MOVE, WM_MOVE)

  Local $nMsg
  While True
    $nMsg = GUIGetMsg()
    Switch $nMsg
      Case $GUI_EVENT_CLOSE
        Exit
      Case $Button2
        ShowMenu($hGUI, $nMsg, $ingreContext)
      Case $PP
        ConsoleWrite("test" & @CRLF)
      Case $PT
      Case $Button3
        ShowMenu($hGUI, $nMsg, $resulContext)
      Case $RP
      Case $RT
      Case $RA
      Case $Button4
        ShowMenu($hGUI, $nMsg, $busqueContext)
      Case $BP
      Case $BT
      Case $BA
    EndSwitch
  WEnd
EndFunc   ;==>Prin

Func ShowMenu($hWnd, $idCtrl, $idContext)
  Local $hMenu = GUICtrlGetHandle($idContext)
  Local $aPos = ControlGetPos($hWnd, "", $idCtrl)
  Local $tPoint = DllStructCreate($tagPOINT)
  $tPoint.X = $aPos[0]
  $tPoint.Y = $aPos[1] + $aPos[3]
  _WinAPI_ClientToScreen($hWnd, $tPoint)
  _GUICtrlMenu_TrackPopupMenu($hMenu, $hWnd, $tPoint.X, $tPoint.Y)
EndFunc   ;==>ShowMenu

Func WM_MOVE($hWnd, $iMsg, $wParam, $lParam)
  Local $aPos = WinGetPos($hWnd)
  IniWrite("Coord.ini", "Position", "X-Pos", $aPos[0])
  IniWrite("Coord.ini", "Position", "Y-Pos", $aPos[1])
  Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_MOVE

 

Link to comment
Share on other sites

Nice @Nine !
It works fine but I got a little problem on my antique PC : when you try to move the window, it doesn't move fluently (hiccups) because of the WM_MOVE function which rewrites several times the .ini file during the registered WM_MOVE function.

If I'm not mistaken, OP's script looks worse because of the hundreds of iniwrite during the While...Wend loop.

Could it be possible to get totally rid of the WM_MOVE function and (re)write the .ini file only once, before leaving the script (Case $GUI_EVENT_CLOSE) ?

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