Sign in to follow this  
Followers 0
roofninja

check marks usage on drop down menu

7 posts in this topic

I am trying to make this program read the check marks from the drop down menu so that I can choose which ones to install. The problem that I can't seem to get past is why it will not register the check mark when I click on the install chose.

I know that is is not the normal way to use check marks, but why be normal? HaHa


RUN . . . Slide . . . TAG . . . Your out . . . PAINTBALL !!!

Share this post


Link to post
Share on other sites



roofninja,

Good question! You can set the check marks but not (as far as I can see) read them. :unsure:

Although I cannot offer a solution to read the check marks directly, I can suggest how you might do it - use an array to hold the check data: ;)

;this is a test to create a window with a 5 check mark boxs for blue, green, orange, data managment, and all.

#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#Include <GuiMenu.au3>
#include <Misc.au3>
if _Singleton("Warning",1) = 0 Then
    Msgbox(0,"Warning","An occurence of your program is already running")
    Exit
EndIf

Opt('MustDeclareVars', 1)

Global $aItems[4] = [0, 0, 0, 0]
Global $aChecks = $aItems

Menu()

Func Menu()
    Local $hGui, $msg
    Local $aarBtn, $aarDummy, $aarContext, $insfull, $insblue, $insgreen, $insorange, $insdatamg, $install

    $hGui = GUICreate("LLi install", 100, 40)
;-------------Menu for LLi install---------------------------------
    $aarBtn = GUICtrlCreateButton("&LLi install", 10, 10, 80, 20, $BS_FLAT)
    $aarDummy = GUICtrlCreateDummy()
    $aarContext = GUICtrlCreateContextMenu($aarDummy)
    $insfull = GUICtrlCreateMenuItem("Full install", $aarContext)
    GUICtrlCreateMenuItem("", $aarContext)
    $aItems[0] = GUICtrlCreateMenuItem("Blue install", $aarContext)
    $aItems[1] = GUICtrlCreateMenuItem("Green install", $aarContext)
    $aItems[2] = GUICtrlCreateMenuItem("Orange install", $aarContext)
    $aItems[3] = GUICtrlCreateMenuItem("Data Manager", $aarContext)
    GUICtrlCreateMenuItem("", $aarContext)
    $install = GUICtrlCreateMenuItem("Install", $aarContext)
    GUICtrlCreateMenuItem("", $aarContext)

;-----------------------------------------------------------------------------------
    GUISetState()
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $aarBtn
                ShowMenu($hGui, $msg, $aarContext)

;-------------------------LLi install-------
            Case $insfull
                MsgBox(64,"Install LLi","LLi has been installed",2)
                ExitLoop
            Case $aItems[0]
                _CheckIt(0)
            Case $aItems[1]
                _CheckIt(1)
            Case $aItems[2]
                _CheckIt(2)
            Case $aItems[3]
                _CheckIt(3)
            Case $install
                For $i = 0 To 3
                    If $aChecks[$i] Then MsgBox(64, "Install", "Item " & $i)
                Next
                MsgBox(64,"Install LLi","LLi is being installed",2)
                ExitLoop
        EndSwitch
    WEnd
    GUIDelete()
EndFunc
;----------------------Func call list-------------

Func _CheckIt($iIndex)

    $aChecks[$iIndex] = Not $aChecks[$iIndex]
    For $i = 0 To 3
        If $aChecks[$i] Then
            GUICtrlSetState($aItems[$i],$GUI_CHECKED)
        Else
            GUICtrlSetState($aItems[$i],$GUI_UNCHECKED)
        EndIf
    Next
EndFunc

; Show a menu in a given GUI window which belongs to a given GUI ctrl
Func ShowMenu($hWnd, $CtrlID, $nContextID)
    Local $arPos, $x, $y
    Local $hMenu = GUICtrlGetHandle($nContextID)
    $arPos = ControlGetPos($hWnd, "", $CtrlID)
    $x = $arPos[0]
    $y = $arPos[1] + $arPos[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 $stPoint = DllStructCreate("int;int")
    DllStructSetData($stPoint, 1, $x)
    DllStructSetData($stPoint, 2, $y)
    DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint))
    $x = DllStructGetData($stPoint, 1)
    $y = DllStructGetData($stPoint, 2)
    ; release Struct not really needed as it is a local
    $stPoint = 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
Exit

Any use? :>

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

I didn't think about going this way, but that is why I posted for help. I will let you know if it works. Thanks.


RUN . . . Slide . . . TAG . . . Your out . . . PAINTBALL !!!

Share this post


Link to post
Share on other sites

Here another method:

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

Opt("GUICoordMode", 1)
$hGUI = GUICreate("Menu", 400, 300)
Global Const $idButton = GUICtrlCreateButton("Test", 100, 100, 80, 40)
Global Enum $idFullInstall = 1000, $idBlueInstall, $idGreenInstall, $idOrangeInstall, $idInstall
Global $hMenu
$hMenu = _GUICtrlMenu_CreatePopup()
_GUICtrlMenu_InsertMenuItem ($hMenu, 0, "Full install", $idFullInstall)
_GUICtrlMenu_InsertMenuItem ($hMenu, 1, "", 0)
_GUICtrlMenu_InsertMenuItem ($hMenu, 2, "Blue install", $idBlueInstall)
_GUICtrlMenu_InsertMenuItem ($hMenu, 3, "Green install", $idGreenInstall)
_GUICtrlMenu_InsertMenuItem ($hMenu, 4, "Orange install", $idOrangeInstall)
_GUICtrlMenu_InsertMenuItem ($hMenu, 5, "", 0)
_GUICtrlMenu_InsertMenuItem ($hMenu, 6, "Install", $idInstall)
GUISetState()

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            _GUICtrlMenu_DestroyMenu($hMenu)
            GUIDelete()
            Exit
        Case $idButton
            ShowMenu($hGUI)
    EndSwitch
WEnd

Func InstallBlue()
    MsgBox(0, "Information", "Installing Blue", 5)
    MsgBox(0, "Information", "Done", 5)
EndFunc

Func InstallGreen()
    MsgBox(0, "Information", "Installing Green", 5)
    MsgBox(0, "Information", "Done", 5)
EndFunc

Func InstallOrange()
    MsgBox(0, "Information", "Installing Orange", 5)
    MsgBox(0, "Information", "Done", 5)
EndFunc

Func ShowMenu($hWnd)
    Local $aButton = ControlGetPos("", "", $idButton)
    Local $x = $aButton[0]
    Local $y = $aButton[1] + $aButton[3]
    ClientToScreen($hGUI, $x, $y)
    _GUICtrlMenu_TrackPopupMenu($hMenu, $hWnd, $x, $y)
    Return True
EndFunc   ;==>WM_CONTEXTMENU

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Switch $iwParam
        Case $idFullInstall
            If Not _GUICtrlMenu_GetItemState($hMenu, 0) Then
                _GUICtrlMenu_SetItemChecked($hMenu, 0, 1)
                _GUICtrlMenu_SetItemChecked($hMenu, 2, 1)
                _GUICtrlMenu_SetItemChecked($hMenu, 3, 1)
                _GUICtrlMenu_SetItemChecked($hMenu, 4, 1)
            Else
                _GUICtrlMenu_SetItemChecked($hMenu, 0, 0)
                _GUICtrlMenu_SetItemChecked($hMenu, 2, 0)
                _GUICtrlMenu_SetItemChecked($hMenu, 3, 0)
                _GUICtrlMenu_SetItemChecked($hMenu, 4, 0)
            EndIf
        Case $idBlueInstall
            If Not _GUICtrlMenu_GetItemState($hMenu, 2) Then
                _GUICtrlMenu_SetItemChecked($hMenu, 2, 1)
            Else
                _GUICtrlMenu_SetItemChecked($hMenu, 2, 0)
            EndIf
        Case $idGreenInstall
            If Not _GUICtrlMenu_GetItemState($hMenu, 3) Then
                _GUICtrlMenu_SetItemChecked($hMenu, 3, 1)
            Else
                _GUICtrlMenu_SetItemChecked($hMenu, 3, 0)
            EndIf
        Case $idOrangeInstall
            If Not _GUICtrlMenu_GetItemState($hMenu, 4) Then
                _GUICtrlMenu_SetItemChecked($hMenu, 4, 1)
            Else
                _GUICtrlMenu_SetItemChecked($hMenu, 4, 0)
            EndIf
        Case $idInstall
            If _GUICtrlMenu_GetItemState($hMenu, 2) Then InstallBlue()
            If _GUICtrlMenu_GetItemState($hMenu, 3) Then InstallGreen()
            If _GUICtrlMenu_GetItemState($hMenu, 4) Then InstallOrange()
    EndSwitch
EndFunc

; Convert the client (GUI) coordinates to screen (desktop) coordinates
Func ClientToScreen($hWnd, ByRef $x, ByRef $y)
    Local $stPoint = DllStructCreate("int;int")
    DllStructSetData($stPoint, 1, $x)
    DllStructSetData($stPoint, 2, $y)
    DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint))
    $x = DllStructGetData($stPoint, 1)
    $y = DllStructGetData($stPoint, 2)
    ; release Struct not really needed as it is a local
    $stPoint = 0
EndFunc   ;==>ClientToScreen

Br,

UEZ


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

UEZ,

I have done one similar to what you have but because I don't know what size of screen I am going to be on, I have to account for 640x480 up to 1900x1600 screen sizes. Using a drop down menu or title bar menu has worked the best for my situation. Thanks, I will save it for a later project.


RUN . . . Slide . . . TAG . . . Your out . . . PAINTBALL !!!

Share this post


Link to post
Share on other sites

M23,

That was the answer. That fixed it and got it finished.

Thanks, SOLVED.


RUN . . . Slide . . . TAG . . . Your out . . . PAINTBALL !!!

Share this post


Link to post
Share on other sites

In regards to why the first script didn't work as expected, just for future reference in case anyone wishes to use the "_GUICtrlMenu_GetItemChecked" function to get the information, here's the answer to how to get the checked/unchecked state of a menu item using that function. I have modified the original script so that it works now, notice the lines marked with ; <<<<<<<<<<<<<<<<

;this is a test to create a window with a 5 check mark boxs for blue, green, orange, data managment, and all.
#include <GUIConstantsEx.au3>
#include <ButtonConstants.au3>
#include <GuiMenu.au3>
#include <Misc.au3>
If _Singleton("Warning", 1) = 0 Then
    MsgBox(0, "Warning", "An occurence of your program is already running")
    Exit
EndIf
Opt('MustDeclareVars', 1)
Menu()
Func Menu()
    Local $hGui, $msg
    Local $aarBtn, $aarDummy, $aarContext, $insfull, $insblue, $insgreen, $insorange, $insdatamg, $install, $haarContext
    $hGui = GUICreate("LLi install", 100, 40)
    ;-------------Menu for LLi install---------------------------------
    $aarBtn = GUICtrlCreateButton("&LLi install", 10, 10, 80, 20, $BS_FLAT)
    $aarDummy = GUICtrlCreateDummy()
    $aarContext = GUICtrlCreateContextMenu($aarDummy)
    $haarContext = GUICtrlGetHandle($aarContext) ; <<<<<<<<<< Get the handle of the Control $aarContext
    $insfull = GUICtrlCreateMenuItem("Full install", $aarContext)
    GUICtrlCreateMenuItem("", $aarContext)
    $insblue = GUICtrlCreateMenuItem("Blue install", $aarContext)
    $insgreen = GUICtrlCreateMenuItem("Green install", $aarContext)
    $insorange = GUICtrlCreateMenuItem("Orange install", $aarContext)
    $insdatamg = GUICtrlCreateMenuItem("Data Manager", $aarContext)
    GUICtrlCreateMenuItem("", $aarContext)
    $install = GUICtrlCreateMenuItem("Install", $aarContext)
    GUICtrlCreateMenuItem("", $aarContext)
    ;-----------------------------------------------------------------------------------
    GUISetState()
    While 1
        $msg = GUIGetMsg()
        Switch $msg
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $aarBtn
                ShowMenu($hGui, $msg, $aarContext)
                ;-------------------------LLi install-------
            Case $insfull
                MsgBox(64, "Install LLi", "LLi has been installed", 2)
                ExitLoop
            Case $insblue
                GUICtrlSetState($insblue, $GUI_CHECKED)
            Case $insgreen
                GUICtrlSetState($insgreen, $GUI_CHECKED)
            Case $insorange
                GUICtrlSetState($insorange, $GUI_CHECKED)
            Case $insdatamg
                GUICtrlSetState($insdatamg, $GUI_CHECKED)
            Case $install
                MsgBox(64, "blue", _GUICtrlMenu_GetItemChecked($haarContext, 2), 8) ; <<<<<<<<<<<<< use the handle of the MENU, and not the menu item, also you were referencing the menu items wrong
                MsgBox(64, "green", _GUICtrlMenu_GetItemChecked($haarContext, 3), 8)
                MsgBox(64, "orange", _GUICtrlMenu_GetItemChecked($haarContext, 4), 8)
                MsgBox(64, "data", _GUICtrlMenu_GetItemChecked($haarContext, 5), 8)
                ExitLoop
        EndSwitch
    WEnd
    GUIDelete()
EndFunc   ;==>Menu
;----------------------Func call list-------------
; Show a menu in a given GUI window which belongs to a given GUI ctrl
Func ShowMenu($hWnd, $CtrlID, $nContextID)
    Local $arPos, $x, $y
    Local $hMenu = GUICtrlGetHandle($nContextID)
    $arPos = ControlGetPos($hWnd, "", $CtrlID)
    $x = $arPos[0]
    $y = $arPos[1] + $arPos[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 $stPoint = DllStructCreate("int;int")
    DllStructSetData($stPoint, 1, $x)
    DllStructSetData($stPoint, 2, $y)
    DllCall("user32.dll", "int", "ClientToScreen", "hwnd", $hWnd, "ptr", DllStructGetPtr($stPoint))
    $x = DllStructGetData($stPoint, 1)
    $y = DllStructGetData($stPoint, 2)
    ; release Struct not really needed as it is a local
    $stPoint = 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
Exit

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
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
Sign in to follow this  
Followers 0