Jump to content

Recommended Posts

Posted

What a novel idea. Thanks for sharing this.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

Nice idea, but i thought that there is one main reason why this could be useful, and it's the scrolling option.

You are using only $CBS_DROPDOWNLIST as combobox style, this one disables the scrolling option. Replace it with this:

BitOr($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST)

and now you can see that this kind of context menu is useful :).

P.S.

And also i think you should pull out the File*Dialog functions from WM_COMMAND, because as docs states:

  Quote

Warning: blocking of running user functions which executes window messages with commands such as "Msgbox()" can lead to unexpected behavior, the return to the system should be as fast as possible !!!

Edited by MrCreatoR

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted

My suggestion would be use a dummy control with GUICtrlCreateDummy.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted (edited)

I would do it like this (simpler :) ):

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <WinAPI.au3>
#include <GUIComboBox.au3>

Global $hComboMenu, $hComboMenu_GUI

_Main()

Func _Main()
    Local $hForm, $iEdit
    
    $hForm = GUICreate("ComboBox like a Context Menu!", 400, 300)
    GUICtrlCreateButton("Button", 150, 250, 100, 25)
    
    GUISetState(@SW_SHOW)
    
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                Exit
            Case $GUI_EVENT_SECONDARYUP
                If IsHWnd($hComboMenu_GUI) Then
                    GUIDelete($hComboMenu_GUI)
                EndIf
                
                $tPoint = _WinAPI_GetMousePos()
                
                If _WinAPI_WindowFromPoint($tPoint) <> $hForm Then
                    ContinueLoop
                EndIf
                
                $iLeft = MouseGetPos(0)
                $iTop = MouseGetPos(1)
                
                $hComboMenu_GUI = GUICreate('ComboMenu', 100, 25, $iLeft, $iTop, $WS_POPUP, -1, $hForm)
                $hComboMenu = GUICtrlGetHandle(GUICtrlCreateCombo("", 0, 0, 100, 30, BitOr($GUI_SS_DEFAULT_COMBO, $CBS_DROPDOWNLIST)))
                
                _GUICtrlComboBox_AddString($hComboMenu, "Open file")
                _GUICtrlComboBox_AddString($hComboMenu, "Save As...")
                _GUICtrlComboBox_AddString($hComboMenu, "Close and save")
                _GUICtrlComboBox_AddString($hComboMenu, "Exit")
                _GUICtrlComboBox_SetCurSel($hComboMenu, 0)
                
                GUISetState(@SW_SHOWNOACTIVATE, $hComboMenu_GUI)
                
                _GUICtrlComboBox_ShowDropDown($hComboMenu, True)
            Case $GUI_EVENT_PRIMARYDOWN
                If Not IsHWnd($hComboMenu_GUI) Then
                    ContinueLoop
                EndIf
                
                $tPoint = _WinAPI_GetMousePos()
                
                If _WinAPI_GetAncestor(_WinAPI_WindowFromPoint($tPoint), $GA_ROOT) <> $hForm Then
                    $iSel = _GUICtrlComboBox_GetCurSel($hComboMenu)
                    
                    GUIDelete($hComboMenu_GUI)
                    
                    Switch $iSel
                        Case 0
                            FileOpenDialog("Select to open image files...", @WindowsDir & "", "Images (*.jpg;*.bmp)", 1 + 4, "", $hForm)
                        Case 1
                            FileSaveDialog("Choose a name.", "::{450D8FBA-AD25-11D0-98A8-0800361B1103}", "Scripts (*.aut;*.au3)", 2, "", $hForm)
                        Case 3
                            Exit
                    EndSwitch
                Else
                    GUIDelete($hComboMenu_GUI)
                EndIf
        EndSwitch
    WEnd
EndFunc
Edited by MrCreatoR

 

  Reveal hidden contents

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Posted

Yeh $GUI_EVENT_SECONDARYUP, duh! Nice example MrCreatoR.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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
×
×
  • Create New...