Jump to content

ContextMenu on ListView


lsakizada
 Share

Recommended Posts

I am trying to make context menue to listview control without much successful.

I have asked help here:

but the issue not resolved yet. Please note that it is not working when using the: GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

Please help

Edited by lsakizada

Be Green Now or Never (BGNN)!

Link to comment
Share on other sites

Hi,

In the WM_Notify function change or comment out the Case.. eg:

Case $NM_RCLICK; Sent by a list-view control when the user clicks an item with the right mouse button
                    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    _DebugPrint("$NM_RCLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode & @LF & _
                            "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _
                            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
                            "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
                            "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
                            "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
                            "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
                            "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
                            "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _
                            "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
;~             ;Return 1; not to allow the default processing
                   ; Return 0; allow the default processing 
                   Return $GUI_RUNDEFMSG ; <------------- So it lets the autoit msg register the right click in the Listview control
Or just comment out the whole Case $NM_RCLICK section if your not needing it...

Cheers

Link to comment
Share on other sites

Hi,

In the WM_Notify function change or comment out the Case.. eg:

Case $NM_RCLICK; Sent by a list-view control when the user clicks an item with the right mouse button
                    Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                    _DebugPrint("$NM_RCLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _
                            "-->IDFrom:" & @TAB & $iIDFrom & @LF & _
                            "-->Code:" & @TAB & $iCode & @LF & _
                            "-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @LF & _
                            "-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @LF & _
                            "-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @LF & _
                            "-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @LF & _
                            "-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @LF & _
                            "-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @LF & _
                            "-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @LF & _
                            "-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @LF & _
                            "-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
;~             ;Return 1; not to allow the default processing
                   ; Return 0; allow the default processing 
                   Return $GUI_RUNDEFMSG ; <------------- So it lets the autoit msg register the right click in the Listview control
Or just comment out the whole Case $NM_RCLICK section if your not needing it...

Cheers

Have a best one Smashly! That's realy solves the problem. :)

Be Green Now or Never (BGNN)!

Link to comment
Share on other sites

  • 3 weeks later...

I am still having hard time to figure out how to create contextmenu to EXTERNAL ListView that was created with the _GUICtrlListView_Create() method.

It is not working for me. Please help on that issue.

$hListView = _GUICtrlListView_Create($GUI, "", $aiSize[0] - 185,70, 170,$aiSize[1] -120)
 _GUICtrlListView_SetExtendedListViewStyle ($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES,$LVS_EX_REGIONAL))
   $contextmenu = GUICtrlCreateContextMenu ($hListView)
    $newsubmenu     = GUICtrlCreateMenu ("new", $contextmenu)
    $textitem       = GUICtrlCreateMenuitem ("text", $newsubmenu)

    $fileitem       = GUICtrlCreateMenuitem ("Open", $contextmenu)
    $saveitem       = GUICtrlCreateMenuitem ("Save", $contextmenu)
    GUICtrlCreateMenuitem ("", $contextmenu); separator

    $infoitem       = GUICtrlCreateMenuitem ("Info", $contextmenu)
    $contextmenu    = GUICtrlCreateContextMenu ($hListView)
Edited by lsakizada

Be Green Now or Never (BGNN)!

Link to comment
Share on other sites

Sorry to say it's not going to work ..

$hListView = _GUICtrlListView_Create($GUI, "", $aiSize[0] - 185,70, 170,$aiSize[1] -120)

This returns a HANDLE to a control..

$hListView = GUICtrlCreateListView("", 5, 5, 190, 190)

This returns a Control ID of the control

$contextmenu = GUICtrlCreateContextMenu ($hListView)

Will only work with an internal Control ID

Autoit doesn't know the external _GUICtrlListView_Create() Control ID.

Even if Autoit did know the external Control ID it still wouldn't work because the control is not handled by Autoit's msg queue.. (As a guess)

Maybe look into custom context menu's , but it all sounds like to much effort for my likings..

Good luck

Cheers

Link to comment
Share on other sites

Sorry to say it's not going to work ..

Will only work with an internal Control ID

Autoit doesn't know the external _GUICtrlListView_Create() Control ID.

Even if Autoit did know the external Control ID it still wouldn't work because the control is not handled by Autoit's msg queue.. (As a guess)

Maybe look into custom context menu's , but it all sounds like to much effort for my likings..

Good luck

Cheers

Must be away to do it, I remember a script example from AU3Libarary that was able to add menucontext.

but unfortunately it can not run on my system anymore so I can not look for it.

Too bad if we can not add menutext since the new methods are awsome and have many nice features.

Be Green Now or Never (BGNN)!

Link to comment
Share on other sites

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

; ===============================================================================================================================
; Global variables
; ===============================================================================================================================

Global Enum $idOpen = 1000, $idSave, $idInfo

; ===============================================================================================================================
; Main
; ===============================================================================================================================

$hGUI = GUICreate('Context Menu Demo (Right Click)', 400, 300)
GUISetState()

; Register message handleers
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU")

; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

; ===============================================================================================================================
; Shows how to capture the contect menu selections
; ===============================================================================================================================
Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Switch $iwParam
        Case $idOpen
            ConsoleWrite("Open" & @LF)
        Case $idSave
            ConsoleWrite("Save" & @LF)
        Case $idInfo
            ConsoleWrite("Info" & @LF)
    EndSwitch
EndFunc   ;==>WM_COMMAND

; ===============================================================================================================================
; Shows how to display a context menu
; ===============================================================================================================================
Func WM_CONTEXTMENU($hWnd, $iMsg, $iwParam, $ilParam)

    ; -------------------- To Do --------------------
    ; Do some checking to see if the mouse was clicked in an
    ; area where we want to display a context menu...

    $hMenu = _GUICtrlMenu_CreatePopup()
    _GUICtrlMenu_AddMenuItem($hMenu, "Open", $idOpen)
    _GUICtrlMenu_AddMenuItem($hMenu, "Save", $idSave)
    _GUICtrlMenu_AddMenuItem($hMenu, "Info", $idInfo)
    _GUICtrlMenu_TrackPopupMenu($hMenu, $iwParam)
    _GUICtrlMenu_DestroyMenu($hMenu)
    Return True
EndFunc   ;==>WM_CONTEXTMENU

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

This should do the trick:

#include <GuiMenu.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>
#include <GuiImageList.au3>

; ========================================================================
; Global variables
; ========================================================================

Global Enum $idOpen = 1000, $idSave, $idInfo

; ========================================================================
; Main
; ========================================================================

$hGUI = GUICreate('Context Menu Demo (Right Click)', 400, 300)
$hListView = _GUICtrlListView_Create($hGUI, "", 2, 2, 394, 268)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES))
GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

; Load images
$hImage = _GUIImageList_Create()
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0xFF0000, 16, 16))
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 16, 16))
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x0000FF, 16, 16))
_GUICtrlListView_SetImageList($hListView, $hImage, 1)

; Add columns
_GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100)
_GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100)
_GUICtrlListView_InsertColumn($hListView, 2, "Column 3", 100)

; Add items
_GUICtrlListView_AddItem($hListView, "Row 1: Col 1", 0)
_GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 2", 1)
_GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 3", 2)
_GUICtrlListView_AddItem($hListView, "Row 2: Col 1", 1)
_GUICtrlListView_AddSubItem($hListView, 1, "Row 2: Col 2", 1)
_GUICtrlListView_AddItem($hListView, "Row 3: Col 1", 2)

GUISetState()

; Loop until user exits
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func ListView_RClick()
    Local $aHit

    $aHit = _GUICtrlListView_SubItemHitTest($hListView)
    If ($aHit[0] <> -1) Then
        ; Create a standard popup menu
        ; -------------------- To Do --------------------
        $hMenu = _GUICtrlMenu_CreatePopup()
        _GUICtrlMenu_AddMenuItem($hMenu, "Open", $idOpen)
        _GUICtrlMenu_AddMenuItem($hMenu, "Save", $idSave)
        _GUICtrlMenu_AddMenuItem($hMenu, "Info", $idInfo)
        ; ========================================================================
        ; Shows how to capture the context menu selections
        ; ========================================================================
        Switch _GUICtrlMenu_TrackPopupMenu($hMenu, $hListView, -1, -1, 1, 1, 2)
            Case $idOpen
                _DebugPrint("Open: " & StringFormat("Item, SubItem [%d, %d]", $aHit[0], $aHit[1]))
            Case $idSave
                _DebugPrint("Save: " & StringFormat("Item, SubItem [%d, %d]", $aHit[0], $aHit[1]))
            Case $idInfo
                _DebugPrint("Info: " & StringFormat("Item, SubItem [%d, %d]", $aHit[0], $aHit[1]))
        EndSwitch
        _GUICtrlMenu_DestroyMenu($hMenu)
    EndIf
EndFunc   ;==>ListView_RClick


Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_RCLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    ListView_RClick()
                    Return 0
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func _DebugPrint($s_text, $line = @ScriptLineNumber)
    ConsoleWrite( _
            "!===========================================================" & @LF & _
            "+======================================================" & @LF & _
            "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _
            "+======================================================" & @LF)
EndFunc   ;==>_DebugPrint
Edited by GaryFrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

  • 1 year later...

I'm trying to use this function, but I have a problem: I need to call a function when is clicked "Description" item of the context menu, to show a window with some information about the item selected of the listview. The script crash after the window opening, but the function Description works fine if called by a simple button.

Is there a way to correctly call the function? Thanks!

Func ListView_RClick()
    Local $aHit, $hMenu
    $aHit = _GUICtrlListView_SubItemHitTest($hListView)
    If ($aHit[0] <> -1) Then
        ; Create a standard popup menu
        $hMenu = _GUICtrlMenu_CreatePopup()
        _GUICtrlMenu_AddMenuItem($hMenu, "Description", $ID1)
        _GUICtrlMenu_AddMenuItem($hMenu, "")
        _GUICtrlMenu_AddMenuItem($hMenu, "Don't check", $ID2)
        _GUICtrlMenu_AddMenuItem($hMenu, "Remove", $ID3)
        Switch _GUICtrlMenu_TrackPopupMenu($hMenu, $hListView, -1, -1, 1, 1, 2)
            Case $ID1
                Description($aHit[0])
            Case $ID2
                MsgBox(0x40000, "Info2", $appman)
            Case $ID3
                MsgBox(0x40000, "Info3", $appman)
        EndSwitch
        _GUICtrlMenu_DestroyMenu($hMenu)
    EndIf
EndFunc

SFTPEx, AutoCompleteInput, _DateTimeStandard(), _ImageWriteResize(), _GUIGraduallyHide(): some AutoIt functions.

Lupo PenSuite: all-in-one and completely free selection of portable programs and games.

DropIt: a personal assistant to automatically manage your files.

ArcThemALL!: application to multi-archive your files and folders.

Link to comment
Share on other sites

Depends what your function 'Description' is doing, but I'm going to guess you're crashing because of this from the help file:

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

For example, if you try to use _ArrayDisplay() it will crash your script.
Link to comment
Share on other sites

I have replaced Description function with a simple MsgBox() that show app description and it works fine.

I have another problem now: I'd like to pass variables to ListView_RClick, as ListView_RClick($var), but this function is under WM_NOTIFY and it seems to support only global var.. Can I send vars to WM_NOTIFY?

SFTPEx, AutoCompleteInput, _DateTimeStandard(), _ImageWriteResize(), _GUIGraduallyHide(): some AutoIt functions.

Lupo PenSuite: all-in-one and completely free selection of portable programs and games.

DropIt: a personal assistant to automatically manage your files.

ArcThemALL!: application to multi-archive your files and folders.

Link to comment
Share on other sites

1) DO NOT use a blocking function like MsgBox(). Read the documentation for GuiRegisterMsg(), then read it again.

2) No. The WM_NOTIFY function is called by the OS. You have no control over its parameters or the information you receive. Review the WM_NOTIFY notification in MSDN and the specific message your are interested in dealing with for more info (NM_RCLICK).

Link to comment
Share on other sites

I read the GuiRegisterMsg() but I don't exactly understand what modifications I have to do at my code, in particular the MsgBox() that I used may be replaced (even if works fine on my computer). Can you help me?

Func ListView_RClick()
    Local $aHit, $hMenu, $a
    $aHit = _GUICtrlListView_SubItemHitTest($hListView)
    If ($aHit[0] <> -1) Then
        ; Create a standard popup menu
        $hMenu = _GUICtrlMenu_CreatePopup()
        _GUICtrlMenu_AddMenuItem($hMenu, "Description", $ID1)
        _GUICtrlMenu_AddMenuItem($hMenu, "Web Page", $ID2)
        _GUICtrlMenu_AddMenuItem($hMenu, "")
        _GUICtrlMenu_AddMenuItem($hMenu, "Remove", $ID4)
        If _GUICtrlListView_GetItemText($hListViewH, $aHit[0], 2) = "Unknown" Then _GUICtrlMenu_SetItemDisabled($hMenu, 1)
        Switch _GUICtrlMenu_TrackPopupMenu($hMenu, $hListView, -1, -1, 1, 1, 2)
            Case $ID1
                MsgBox(0x40040, _GUICtrlListView_GetItemText($hListView, $aHit[0], 0), "Description:  " & _GUICtrlListView_GetItemText($hListViewH, $aHit[0], 1))
            Case $ID2
                If _GUICtrlListView_GetItemText($hListViewH, $aHit[0], 2) = "Internal" Then
                    $a = _GUICtrlListView_GetItemText($hListView, $aHit[0], 0)
                    $Page = $site & "db/" & StringLower(StringReplace(StringReplace($a, "!", ""), " ", "")) & ".htm"
                Else
                    $Page = _GUICtrlListView_GetItemText($hListViewH, $aHit[0], 2)
                EndIf
                $runPage = Run($FFp & " -new-tab " & $Page, "", @SW_MAXIMIZE)
                If $runPage = 0 Then _IECreate($Page, 1, 1, 0)
            Case $ID4
                _GUICtrlListView_SetItemChecked($hListView, $aHit[0])
                AppsRemove($aHit[0])
        EndSwitch
        _GUICtrlMenu_DestroyMenu($hMenu)
    EndIf
EndFunc


Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView
    $hWndListView = $hListView
    If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView)
    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_RCLICK
                    ListView_RClick()
                    Return 0
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

SFTPEx, AutoCompleteInput, _DateTimeStandard(), _ImageWriteResize(), _GUIGraduallyHide(): some AutoIt functions.

Lupo PenSuite: all-in-one and completely free selection of portable programs and games.

DropIt: a personal assistant to automatically manage your files.

ArcThemALL!: application to multi-archive your files and folders.

Link to comment
Share on other sites

I thought to remove the MsgBox() from ListView_RClick(), to add there a variable that is returned and that run a MsgBox() in that case. But I don't know if in this way the script works fine, because I can't verify if it works bad in the actual way. :D

Probably it isn't the correct solution for this issue, but I can't understand how to do to show a description when a context menu item is clicked. I'm working on it in these days, but I can't find the solution. :D

SFTPEx, AutoCompleteInput, _DateTimeStandard(), _ImageWriteResize(), _GUIGraduallyHide(): some AutoIt functions.

Lupo PenSuite: all-in-one and completely free selection of portable programs and games.

DropIt: a personal assistant to automatically manage your files.

ArcThemALL!: application to multi-archive your files and folders.

Link to comment
Share on other sites

DO NOT use a blocking function like MsgBox(). Read the documentation for GuiRegisterMsg(), then read it again.

You are certainly right, but in AutoIt I found one usefull feature (bug). If you register WM_ACTIVATE window message by using GUIRegisterMsg(), then ...

Global Const $WM_ACTIVATE = 0x0006
Global Const $WM_LBUTTONDOWN = 0x0201

GUIRegisterMsg($WM_ACTIVATE, 'WM_ACTIVATE') ; <= Try to comment this
GUIRegisterMsg($WM_LBUTTONDOWN, 'WM_LBUTTONDOWN')

_MyGUI()

Func WM_ACTIVATE($hWnd, $iMsg, $wParam, $lParam)
    Return 'GUI_RUNDEFMSG'
EndFunc   ;==>WM_ACTIVATE

Func WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    _MyGUI()
    Return 'GUI_RUNDEFMSG'
EndFunc   ;==>WM_LBUTTONDOWN

Func _MyGUI()

    Local $hForm, $Msg, $Button

    $hForm = GUICreate('MyGUI', 400, 400)
    $Button = GUICtrlCreateButton('Exit', 165, 360, 70, 23)
    GUISetState()
    While 1
        $Msg = GUIGetMsg()
        Switch $Msg
            Case -3, $Button
                ExitLoop
        EndSwitch
    WEnd
    GUIDelete($hForm)
EndFunc   ;==>_MyGUI

For example, my ColorPicker.au3 uses this trick and works great.

@Lupo

#Include <File.au3>
#Include <GUIConstantsEx.au3>
#Include <GUIListView.au3>
#Include <GUIMenu.au3>
#Include <WindowsConstants.au3>

$hForm  = GUICreate('MyGUI', 400, 300)
$Dummy = GUICtrlCreateDummy()
$Menu = GUICtrlCreateContextMenu($Dummy)
$hMenu = GUICtrlGetHandle($Menu)
$OpenItem = GUICtrlCreateMenuItem('???', $Menu)
$ListView = GUICtrlCreateListView('Name', 4, 4, 392, 268)
$hListView = GUICtrlGetHandle($ListView)
_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_INFOTIP))
_GUICtrlListView_SetColumnWidth($hListView, 0, 300)
$FileList = _FileListToArray(@WindowsDir, '*.exe', 1)
For $i = 1 To $FileList[0]
    _GUICtrlListView_AddItem($hListView, $FileList[$i], $i)
Next
GUIRegisterMsg($WM_NOTIFY, 'WM_NOTIFY')
GUISetState()

$hMenu = GUICtrlGetHandle($Menu)

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $Dummy
            $Item = GUICtrlRead($Dummy)
            If $Item >= 0 Then
                _GUICtrlMenu_SetItemText($hMenu, 0, 'Open "' & _GUICtrlListView_GetItemText($hListView, $Item) & '"')
                _GUICtrlMenu_TrackPopupMenu($hMenu, $hForm)
            EndIf
        Case $OpenItem
            MsgBox(0, '', 'Open...')
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    Local $tNMITEMACTIVATE = DllStructCreate($tagNMITEMACTIVATE, $lParam)
    Local $hWndFrom = DllStructGetData($tNMITEMACTIVATE, 'hWndFrom')
    Local $Index = DllStructGetData($tNMITEMACTIVATE, 'Index')
    Local $Code = DllStructGetData($tNMITEMACTIVATE, 'Code')

    Switch $hWndFrom
        Case $hListView
            Switch $Code
                Case $NM_RCLICK
                    GUICtrlSendToDummy($Dummy, $Index)
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Can I send vars to WM_NOTIFY?

:D

$tagMyCrazyData = '...'
$tData = DllStructCreate($tagMyCrazyData)
_SendMessage($hWnd, $WM_NOTIFY, -1, DllStructGetPtr($tData))

...

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    Switch $wParam
        Case -1
            Local $tData = DllStructCreate($tagMyCrazyData, $lParam)
            ; Do something with $tData
            Return 0
        Case Else
            ; Do something as it should be
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY
Edited by Yashied
Link to comment
Share on other sites

Thank you Yashied, I may have correctly updated my code now. I have some problems to understand the mechanism behind Dummy functions, in particular what procedure they do.. anyway now seems to work fine.

One question: I saw in your code there are two lines "$hMenu = GUICtrlGetHandle($Menu)", are both needed? Is it not enough to define $hMenu after GUISetState()?

SFTPEx, AutoCompleteInput, _DateTimeStandard(), _ImageWriteResize(), _GUIGraduallyHide(): some AutoIt functions.

Lupo PenSuite: all-in-one and completely free selection of portable programs and games.

DropIt: a personal assistant to automatically manage your files.

ArcThemALL!: application to multi-archive your files and folders.

Link to comment
Share on other sites

I've also used the GuiCtrlSendToDummy() method, and it works well. The WM_ACTIVATE thing definitely seems like a bug. I probably wouldn't rely on that always working...

@Lupo73

See if you can follow this:

#include <array.au3>
Global Const $WM_LBUTTONDOWN = 0x0201

Global $array[3][2] = [["one", "1"], ["two", "2"], ["three", "3"]]

$gui = GUICreate("GUI")
$dummy = GUICtrlCreateDummy()
GUIRegisterMsg($WM_LBUTTONDOWN, 'WM_LBUTTONDOWN')
GUISetState()

Do
    $msg = GUIGetMsg()
    Switch $msg
        Case $dummy
            ; this is where the message for dummy is received in the main loop
            ; we can do whatever we want at this point
            _MyArray()
    EndSwitch
Until $msg = -3

Func WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam, $lParam
;~     _MyArray() ; this will crash or hang
    GUICtrlSendToDummy($dummy) ; this will work fine
    Return 'GUI_RUNDEFMSG'
EndFunc   ;==>WM_LBUTTONDOWN

Func _MyArray()
    _ArrayDisplay($array)
EndFunc   ;==>_MyArray
Link to comment
Share on other sites

Perhaps GUICtrlSendToDummy() will not work in Event mode (not tested).

It does indeed work. I've used it in both modes.

Opt("GuiOnEventMode", 1)
#include <array.au3>
Global Const $WM_LBUTTONDOWN = 0x0201

Global $array[3][2] = [["one", "1"], ["two", "2"], ["three", "3"]]

$gui = GUICreate("GUI")
$dummy = GUICtrlCreateDummy()
GUIRegisterMsg($WM_LBUTTONDOWN, 'WM_LBUTTONDOWN')
GUISetOnEvent(-3, "_Exit")
GUICtrlSetOnEvent($dummy, "_MyArray")
GUISetState()

While 1
    Sleep(1000)
WEnd

Func WM_LBUTTONDOWN($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam, $lParam
;~     _MyArray() ; this will crash or hang
    GUICtrlSendToDummy($dummy) ; this will work fine
    Return 'GUI_RUNDEFMSG'
EndFunc   ;==>WM_LBUTTONDOWN

Func _MyArray()
    _ArrayDisplay($array)
EndFunc   ;==>_MyArray

Func _Exit()
    Exit
EndFunc
Edited by wraithdu
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...