Jump to content
Bilgus

Recieve KeyUp/KeyDn Events in a listview

Recommended Posts

Example of Subclassing listviews using setwindowSubclass in order to intercept WM_KEYUP events

Also pops context menu on  Shift + F10

#include <Misc.au3>
#include <ListViewConstants.au3>
#include <GUIConstants.au3>
#include <GuiMenu.au3>

#include <WinAPIShellEx.au3>

Global $g_hCB, $g_pCB, $g_ahProc[2][2] ;Stores the Data for subclassing listview
Global $g_LVKEYUP = 0xFE00, $g_LVKEYDN = 0xFD00 ;Our Own Custom messages (Key Up/Dn)
Global $g_iDummyData

Global $g_hGui = GUICreate("test")

Global $g_hList1 = GUICtrlCreateListView("#|x|y", 5, 24, 161, 70, $LVS_SHOWSELALWAYS Or $LVS_SINGLESEL)
GUICtrlCreateListViewItem("text", $g_hList1)
Global $g_hList1_LVN = GUICtrlCreateDummy() ;Recieves Messages from the callback

Global $g_hContext1 = GUICtrlCreateContextMenu($g_hList1)
GUICtrlCreateMenuItem("1", $g_hContext1)
GUICtrlCreateMenuItem("2", $g_hContext1)

Global $g_hList2 = GUICtrlCreateListView("#|x|y", 5, 100, 161, 70, $LVS_SHOWSELALWAYS Or $LVS_SINGLESEL)
GUICtrlCreateListViewItem("text", $g_hList2)
Global $g_hList2_LVN = GUICtrlCreateDummy() ;Recieves Messages from the callback

Global $g_hContext2 = GUICtrlCreateContextMenu($g_hList2)
GUICtrlCreateMenuItem("3", $g_hContext2)
GUICtrlCreateMenuItem("4", $g_hContext2)

GUISetState(@SW_SHOW)
SubClassListView() ;Creates our subclass

Func SubClassListView()
    OnAutoItExitRegister("Cleanup") ;to remove our subclass

    $g_hCB = DllCallbackRegister('_SubclassProc', 'lresult', 'hwnd;uint;wparam;lparam;uint_ptr;dword_ptr')
    $g_pCB = DllCallbackGetPtr($g_hCB)

    $g_ahProc[0][0] = $g_hList1 ;Add the Ids of the controls we'd like to subclass
    $g_ahProc[1][0] = $g_hList2

    ;Set up the subclass _WinAPI_SetWindowSubclass ( $hWnd, $pSubclassProc, $idSubClass [, $pData = 0] )
    $g_ahProc[0][1] = _WinAPI_SetWindowSubclass(GUICtrlGetHandle($g_ahProc[0][0]), $g_pCB, $g_ahProc[0][0], $g_hList1_LVN)
    $g_ahProc[1][1] = _WinAPI_SetWindowSubclass(GUICtrlGetHandle($g_ahProc[1][0]), $g_pCB, $g_ahProc[1][0], $g_hList2_LVN)
EndFunc   ;==>SubClassListView

Func _SubclassProc($hWnd, $iMsg, $wParam, $lParam, $iID, $pData)
    #forceref $iID

    Local $iRtnMsg = 0
    ;Events we'd like to intercept
    If $iMsg = $WM_KEYUP Or $iMsg = $WM_SYSKEYUP Then
        $iRtnMsg = $g_LVKEYUP
    ElseIf $iMsg = $WM_KEYDOWN Or $iMsg = $WM_SYSKEYDOWN Then
        $iRtnMsg = $g_LVKEYDN
    EndIf

    ;We Recieve the Id of the dummy through $pData and pass our RtnMsg to the dummy control
    If $iRtnMsg Then GUICtrlSendToDummy($pData, BitOR($iRtnMsg, $wParam))

    ;Pass messages on to the default handler
    Return _WinAPI_DefSubclassProc($hWnd, $iMsg, $wParam, $lParam)
EndFunc   ;==>_SubclassProc

Func Cleanup()
    For $i = 0 To UBound($g_ahProc) - 1 ;Remove Our Subclass' by setting it back to the original proc
        _WinAPI_RemoveWindowSubclass(GUICtrlGetHandle($g_ahProc[$i][0]), DllCallbackGetPtr($g_ahProc[$i][1]), $g_ahProc[$i][0])
    Next
    
    DllCallbackFree($g_hCB)
EndFunc   ;==>Cleanup

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

        Case $g_hList1_LVN ;This is just a dummy it only recieves events
            ConsoleWrite("LV1 EVENT 0x" & Hex($g_iDummyData, 4) & @CRLF)
            $g_iDummyData = GUICtrlRead($g_hList1_LVN) ;Retrieve the code that was sent

            Switch BitAND($g_iDummyData, 0xFF00) ;Get the keyup/dn status
                Case $g_LVKEYDN
                    If BitAND($g_iDummyData, 0x00FF) = 0x79 And (_IsPressed("A0") Or _IsPressed("A1")) Then ;Right/ Left Shift & F10
                        ShowMenu($g_hGui, $g_hList1, $g_hContext1)
                    Else
                        ConsoleWrite("Lv1 KeyDn Vk: 0x" & Hex(BitAND($g_iDummyData, 0x00FF), 2) & @CRLF) ;Get the Virtual keycode
                    EndIf

                Case $g_LVKEYUP
                    ConsoleWrite("Lv1 KeyUp Vk: 0x" & Hex(BitAND($g_iDummyData, 0x00FF), 2) & @CRLF) ;Get the Virtual keycode

            EndSwitch

        Case $g_hList2_LVN
            $g_iDummyData = GUICtrlRead($g_hList2_LVN) ;Retrieve the code that was sent
            ConsoleWrite("LV2 EVENT 0x" & Hex($g_iDummyData, 4) & @CRLF)

            Switch BitAND($g_iDummyData, 0xFF00) ;Get the keyup/dn status
                Case $g_LVKEYDN
                    ConsoleWrite("Lv2 KeyDn Vk: 0x" & Hex(BitAND($g_iDummyData, 0x00FF), 2) & @CRLF) ;Get the Virtual keycode
                Case $g_LVKEYUP
                    ConsoleWrite("Lv2 KeyUp Vk: 0x" & Hex(BitAND($g_iDummyData, 0x00FF), 2) & @CRLF) ;Get the Virtual keycode
            EndSwitch
    EndSwitch
WEnd

Func ShowMenu($hWnd, $idCtrl, $idContext)
    Local $aPos, $iX, $iY
    Local $hMenu = GUICtrlGetHandle($idContext)

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

    $iX = $aPos[0]
    $iY = $aPos[1] + $aPos[3]

    ClientToScreen($hWnd, $iX, $iY)
    ; Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd)
    _GUICtrlMenu_TrackPopupMenu($hMenu, $hWnd, $iX, $iY)
EndFunc   ;==>ShowMenu

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

    DllStructSetData($tPoint, 1, $iX)
    DllStructSetData($tPoint, 2, $iY)

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

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

 

Old Code Using setWindowLong

Spoiler
#include <Misc.au3>
#include <ListViewConstants.au3>
#include <GUIConstants.au3>
#include <GuiMenu.au3>

#include <WinAPISys.au3>

Global $g_hCB, $g_pCB, $g_hProc[2][2] ;Stores the Data for subclassing listview
Global $g_LVKEYUP = 0xFE00, $g_LVKEYDN = 0xFD00 ;Our Own Custom Key Up/Dn messages
Global $g_iDummyData

Global $g_hGui = GUICreate("test")

Global $g_hList1 = GUICtrlCreateListView("#|x|y", 5, 24, 161, 70, $LVS_SHOWSELALWAYS Or $LVS_SINGLESEL)
GUICtrlCreateListViewItem("text", $g_hList1)
Global $g_hList1_LVN = GUICtrlCreateDummy() ;Recieves Messages from the callbacks

Global $g_hContext1 = GUICtrlCreateContextMenu($g_hList1)
GUICtrlCreateMenuItem("1", $g_hContext1)
GUICtrlCreateMenuItem("2", $g_hContext1)

Global $g_hList2 = GUICtrlCreateListView("#|x|y", 5, 100, 161, 70, $LVS_SHOWSELALWAYS Or $LVS_SINGLESEL)
GUICtrlCreateListViewItem("text", $g_hList2)
Global $g_hList2_LVN = GUICtrlCreateDummy() ;Recieves Messages from the callbacks

Global $g_hContext2 = GUICtrlCreateContextMenu($g_hList2)
GUICtrlCreateMenuItem("3", $g_hContext2)
GUICtrlCreateMenuItem("4", $g_hContext2)

GUISetState()
SubClassListView() ;Creates our subclass

Func SubClassListView()
    OnAutoItExitRegister("Cleanup") ;to remove our subclass
    Local $iPID
    $g_hCB = DllCallbackRegister('_WinProc', 'ptr', 'hwnd;uint;wparam;lparam')
    $g_pCB = DllCallbackGetPtr($g_hCB)
    $g_hProc[0][0] = GUICtrlGetHandle($g_hList1)
    $g_hProc[1][0] = GUICtrlGetHandle($g_hList2)
    $g_hProc[0][1] = _WinAPI_SetWindowLong($g_hProc[0][0], $GWL_WNDPROC, $g_pCB)
    $g_hProc[1][1] = _WinAPI_SetWindowLong($g_hProc[1][0], $GWL_WNDPROC, $g_pCB)
EndFunc   ;==>SubClassWndProc

Func _WinProc($hWnd, $iMsg, $wParam, $lParam)
    Local $iRtnMsg = 0
    If $iMsg = $WM_KEYUP Or $iMsg = $WM_SYSKEYUP Then
        $iRtnMsg = $g_LVKEYUP
    ElseIf $iMsg = $WM_KEYDOWN Or $iMsg = $WM_SYSKEYDOWN Then
        $iRtnMsg = $g_LVKEYDN
    EndIf

    Switch $hWnd
        Case $g_hProc[0][0]
            If $iRtnMsg Then GUICtrlSendToDummy($g_hList1_LVN, BitOR($iRtnMsg, $wParam))

            Return _WinAPI_CallWindowProc($g_hProc[0][1], $hWnd, $iMsg, $wParam, $lParam)

        Case $g_hProc[1][0]
            If $iRtnMsg Then GUICtrlSendToDummy($g_hList2_LVN, BitOR($iRtnMsg, $wParam))

            Return _WinAPI_CallWindowProc($g_hProc[1][1], $hWnd, $iMsg, $wParam, $lParam)
    EndSwitch

EndFunc   ;==>_WinProc

Func Cleanup()
    _WinAPI_SetWindowLong($g_hProc[0][0], $GWL_WNDPROC, $g_hProc[0][1]);Remove our subclass
    _WinAPI_SetWindowLong($g_hProc[1][0], $GWL_WNDPROC, $g_hProc[1][1]);Remove our subclass
    DllCallbackFree($g_hCB)
EndFunc   ;==>Cleanup

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

        Case $g_hList1_LVN ;This is just a dummy it only recieves events
            ConsoleWrite("LV1 EVENT 0x" & Hex(BitAND($g_iDummyData, 0xFF00), 4) & @CRLF)
            $g_iDummyData = GUICtrlRead($g_hList1_LVN) ;Retrieve the code that was sent
            Switch BitAND($g_iDummyData, 0xFF00) ;Get the keyup/dn status
                Case $g_LVKEYDN
                    If BitAND($g_iDummyData, 0x00FF) = 0x79 And (_IsPressed("A0") Or _IsPressed("A1")) Then ;Right/ Left Shift & F10
                        ShowMenu($g_hGui, $g_hList1, $g_hContext1)
                    Else
                        ConsoleWrite("Lv1 KeyDN Vk: 0x" & Hex(BitAND($g_iDummyData, 0x00FF), 2) & @CRLF) ;Get the Virtual keycode
                    EndIf
                Case $g_LVKEYUP
                    ConsoleWrite("Lv1 KeyUp Vk: 0x" & Hex(BitAND($g_iDummyData, 0x00FF), 2) & @CRLF) ;Get the Virtual keycode
            EndSwitch

        Case $g_hList2_LVN
            $g_iDummyData = GUICtrlRead($g_hList2_LVN) ;Retrieve the code that was sent
            ConsoleWrite("LV2 EVENT 0x" & Hex(BitAND($g_iDummyData, 0xFF00), 4) & @CRLF)
            Switch BitAND($g_iDummyData, 0xFF00) ;Get the keyup/dn status
                Case $g_LVKEYDN
                    ConsoleWrite("Lv2 KeyDN Vk: 0x" & Hex(BitAND($g_iDummyData, 0x00FF), 2) & @CRLF) ;Get the Virtual keycode
                Case $g_LVKEYUP
                    ConsoleWrite("Lv2 KeyUp Vk: 0x" & Hex(BitAND($g_iDummyData, 0x00FF), 2) & @CRLF) ;Get the Virtual keycode
            EndSwitch
    EndSwitch
WEnd

Func ShowMenu($hWnd, $idCtrl, $idContext)
    Local $aPos, $iX, $iY
    Local $hMenu = GUICtrlGetHandle($idContext)

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

    $iX = $aPos[0]
    $iY = $aPos[1] + $aPos[3]

    ClientToScreen($hWnd, $iX, $iY)
    ; Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd)
    _GUICtrlMenu_TrackPopupMenu($hMenu, $hWnd, $iX, $iY)
EndFunc   ;==>ShowMenu

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

    DllStructSetData($tPoint, 1, $iX)
    DllStructSetData($tPoint, 2, $iY)

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

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

 

 

Edited by Bilgus

Share this post


Link to post
Share on other sites
9 hours ago, Bilgus said:

Example of Subclassing listviews using setwindowlong in order to intercept WM_KEYUP events

Also pops context menu on  Shift + F10

#include <Misc.au3>
#include <ListViewConstants.au3>
#include <GUIConstants.au3>
#include <GuiMenu.au3>

#include <WinAPISys.au3>

Global $g_hCB, $g_pCB, $g_hProc[2][2] ;Stores the Data for subclassing listview
Global $g_LVKEYUP = 0xFE00, $g_LVKEYDN = 0xFD00 ;Our Own Custom Key Up/Dn messages
Global $g_iDummyData

Global $g_hGui = GUICreate("test")

Global $g_hList1 = GUICtrlCreateListView("#|x|y", 5, 24, 161, 70, $LVS_SHOWSELALWAYS Or $LVS_SINGLESEL)
GUICtrlCreateListViewItem("text", $g_hList1)
Global $g_hList1_LVN = GUICtrlCreateDummy() ;Recieves Messages from the callbacks

Global $g_hContext1 = GUICtrlCreateContextMenu($g_hList1)
GUICtrlCreateMenuItem("1", $g_hContext1)
GUICtrlCreateMenuItem("2", $g_hContext1)

Global $g_hList2 = GUICtrlCreateListView("#|x|y", 5, 100, 161, 70, $LVS_SHOWSELALWAYS Or $LVS_SINGLESEL)
GUICtrlCreateListViewItem("text", $g_hList2)
Global $g_hList2_LVN = GUICtrlCreateDummy() ;Recieves Messages from the callbacks

Global $g_hContext2 = GUICtrlCreateContextMenu($g_hList2)
GUICtrlCreateMenuItem("3", $g_hContext2)
GUICtrlCreateMenuItem("4", $g_hContext2)

GUISetState()
SubClassListView() ;Creates our subclass

Func SubClassListView()
    OnAutoItExitRegister("Cleanup") ;to remove our subclass
    Local $iPID
    $g_hCB = DllCallbackRegister('_WinProc', 'ptr', 'hwnd;uint;wparam;lparam')
    $g_pCB = DllCallbackGetPtr($g_hCB)
    $g_hProc[0][0] = GUICtrlGetHandle($g_hList1)
    $g_hProc[1][0] = GUICtrlGetHandle($g_hList2)
    $g_hProc[0][1] = _WinAPI_SetWindowLong($g_hProc[0][0], $GWL_WNDPROC, $g_pCB)
    $g_hProc[1][1] = _WinAPI_SetWindowLong($g_hProc[1][0], $GWL_WNDPROC, $g_pCB)
EndFunc   ;==>SubClassWndProc

Func _WinProc($hWnd, $iMsg, $wParam, $lParam)
    Local $iRtnMsg = 0
    If $iMsg = $WM_KEYUP Or $iMsg = $WM_SYSKEYUP Then
        $iRtnMsg = $g_LVKEYUP
    ElseIf $iMsg = $WM_KEYDOWN Or $iMsg = $WM_SYSKEYDOWN Then
        $iRtnMsg = $g_LVKEYDN
    EndIf

    Switch $hWnd
        Case $g_hProc[0][0]
            If $iRtnMsg Then GUICtrlSendToDummy($g_hList1_LVN, BitOR($iRtnMsg, $wParam))

            Return _WinAPI_CallWindowProc($g_hProc[0][1], $hWnd, $iMsg, $wParam, $lParam)

        Case $g_hProc[1][0]
            If $iRtnMsg Then GUICtrlSendToDummy($g_hList2_LVN, BitOR($iRtnMsg, $wParam))

            Return _WinAPI_CallWindowProc($g_hProc[1][1], $hWnd, $iMsg, $wParam, $lParam)
    EndSwitch

EndFunc   ;==>_WinProc

Func Cleanup()
    _WinAPI_SetWindowLong($g_hProc[0][0], $GWL_WNDPROC, $g_hProc[0][1]);Remove our subclass
    _WinAPI_SetWindowLong($g_hProc[1][0], $GWL_WNDPROC, $g_hProc[1][1]);Remove our subclass
    DllCallbackFree($g_hCB)
EndFunc   ;==>Cleanup

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

        Case $g_hList1_LVN ;This is just a dummy it only recieves events
            ConsoleWrite("LV1 EVENT 0x" & Hex(BitAND($g_iDummyData, 0xFF00), 4) & @CRLF)
            $g_iDummyData = GUICtrlRead($g_hList1_LVN) ;Retrieve the code that was sent
            Switch BitAND($g_iDummyData, 0xFF00) ;Get the keyup/dn status
                Case $g_LVKEYDN
                    If BitAND($g_iDummyData, 0x00FF) = 0x79 And (_IsPressed("A0") Or _IsPressed("A1")) Then ;Right/ Left Shift & F10
                        ShowMenu($g_hGui, $g_hList1, $g_hContext1)
                    Else
                        ConsoleWrite("Lv1 KeyDN Vk: 0x" & Hex(BitAND($g_iDummyData, 0x00FF), 2) & @CRLF) ;Get the Virtual keycode
                    EndIf
                Case $g_LVKEYUP
                    ConsoleWrite("Lv1 KeyUp Vk: 0x" & Hex(BitAND($g_iDummyData, 0x00FF), 2) & @CRLF) ;Get the Virtual keycode
            EndSwitch

        Case $g_hList2_LVN
            $g_iDummyData = GUICtrlRead($g_hList2_LVN) ;Retrieve the code that was sent
            ConsoleWrite("LV2 EVENT 0x" & Hex(BitAND($g_iDummyData, 0xFF00), 4) & @CRLF)
            Switch BitAND($g_iDummyData, 0xFF00) ;Get the keyup/dn status
                Case $g_LVKEYDN
                    ConsoleWrite("Lv2 KeyDN Vk: 0x" & Hex(BitAND($g_iDummyData, 0x00FF), 2) & @CRLF) ;Get the Virtual keycode
                Case $g_LVKEYUP
                    ConsoleWrite("Lv2 KeyUp Vk: 0x" & Hex(BitAND($g_iDummyData, 0x00FF), 2) & @CRLF) ;Get the Virtual keycode
            EndSwitch
    EndSwitch
WEnd

Func ShowMenu($hWnd, $idCtrl, $idContext)
    Local $aPos, $iX, $iY
    Local $hMenu = GUICtrlGetHandle($idContext)

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

    $iX = $aPos[0]
    $iY = $aPos[1] + $aPos[3]

    ClientToScreen($hWnd, $iX, $iY)
    ; Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd)
    _GUICtrlMenu_TrackPopupMenu($hMenu, $hWnd, $iX, $iY)
EndFunc   ;==>ShowMenu

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

    DllStructSetData($tPoint, 1, $iX)
    DllStructSetData($tPoint, 2, $iY)

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

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

 

This is very cool code !!Help me a lot
I need some time to study
Thank you again

Share this post


Link to post
Share on other sites

Updated Code to using SetWindowSubclass() instead of setwindowlong

This allows us to pass the ID of the dummy control through the pData Variable which cleans up the subclass procedure a bit

 

Share this post


Link to post
Share on other sites

Neat approach.  I was looking for a way to implement looking for the $WM_CONTEXTMENU notification instead of listening specifically for the Right-Click or Shift+F10 inputs.  That way they (along with the application/menu key) would work without special checks.  My quick implementation was producing two menu pop-ups though and I'm not sure why.


Share this post


Link to post
Share on other sites

@spudw2k If you are just wanting some control over the context menu this example is probably a bit much

since its meant to get KeyUp events before the listview has a chance to eat the message

Instead THIS might be a bit  better

#include <Misc.au3>
#include <ListViewConstants.au3>
#include <GUIConstants.au3>
#include <GuiMenu.au3>

Global $GUI = GUICreate("test")
Global $g_iTemp
Global $g_hList1 = GUICtrlCreateListView("#|x|y", 5, 24, 161, 70, $LVS_SHOWSELALWAYS Or $LVS_SINGLESEL)
GUICtrlCreateListViewItem("text", $g_hList1)
Global $g_hList1_LVN = GUICtrlCreateDummy()

Global $context = GUICtrlCreateContextMenu($g_hList1_LVN);Just Associating with dummy so we can have multiple menu
GUICtrlCreateMenuItem("1", $context)
GUICtrlCreateMenuItem("2", $context)

Global $contextH = GUICtrlCreateContextMenu($g_hList1);Only for header since we intercept rightclick on items
GUICtrlCreateMenuItem("1Header", $contextH)
GUICtrlCreateMenuItem("2Header", $contextH)

Global $g_hList2 = GUICtrlCreateListView("#|x|y", 5, 100, 161, 70, $LVS_SHOWSELALWAYS Or $LVS_SINGLESEL)
GUICtrlCreateListViewItem("text", $g_hList2)
Global $g_hList2_LVN = GUICtrlCreateDummy()

Global $context2 = GUICtrlCreateContextMenu($g_hList2_LVN) ;Just Associating with dummy so we can have multiple menus
GUICtrlCreateMenuItem("3", $context2)
GUICtrlCreateMenuItem("4", $context2)

Global $context2H = GUICtrlCreateContextMenu($g_hList2)
;Nothing Here

GUISetState()
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
While 1
    Switch GUIGetMsg()
        Case $gui_event_close
            Exit
        Case $g_hList1_LVN ;This is just a dummy it only recieves events
            ConsoleWrite("LV1 EVENT" & @CRLF)
            $g_iTemp = GUICtrlRead($g_hList1_LVN) ;Retrieve the code that WM_NOTIFY SENT
            If $g_iTemp = $LVN_KEYDOWN Then
                If _IsPressed("79") And (_IsPressed("A0") Or _IsPressed("A1")) Then ;Right/ Left Shift & F10
                    ShowMenu($GUI, $g_hList1, $context)
                Else
                    ConsoleWrite("Some Other Keys" & @CRLF)
                EndIf
            ElseIf $g_iTemp = $NM_RCLICK Then
                ShowMenu($GUI, $g_hList1, $context)
            Else
                ConsoleWrite("Some Other Event Lv1" & @CRLF)
            EndIf

        Case $g_hList2_LVN
            ConsoleWrite("LV2 EVENT" & @CRLF)
            $g_iTemp = GUICtrlRead($g_hList2_LVN)
            If $g_iTemp = $LVN_KEYDOWN Then
                If _IsPressed("79") And (_IsPressed("A0") Or _IsPressed("A1")) Then ;Right/ Left Shift & F10
                    ShowMenu($GUI, $g_hList2, $context2)
                EndIf
            ElseIf $g_iTemp = $NM_RCLICK Then
                ShowMenu($GUI, $g_hList2, $context2)
            Else
                ConsoleWrite("Some Other Event Lv2" & @CRLF)
            EndIf
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    Local $tNMHDR, $iCode ;
    Switch $wParam
        Case $g_hList1
            $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
            $iCode = DllStructGetData($tNMHDR, "Code")
            Switch $iCode
                Case $LVN_KEYDOWN, $NM_CLICK
                    GUICtrlSendToDummy($g_hList1_LVN, $iCode) ;send the code back to be processed by the dummy
                Case $NM_RCLICK
                    GUICtrlSendToDummy($g_hList1_LVN, $iCode)
                    Return 1 ;Don't pass message onto default handler
            EndSwitch

        Case $g_hList2
            $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
            $iCode = DllStructGetData($tNMHDR, "Code")
            Switch $iCode
                Case $LVN_KEYDOWN, $NM_CLICK
                    GUICtrlSendToDummy($g_hList2_LVN, $iCode)
                Case $NM_RCLICK
                    GUICtrlSendToDummy($g_hList2_LVN, $iCode)
                    Return 1 ;Don't pass message onto default handler
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func ShowMenu($hWnd, $idCtrl, $idContext)
    ConsoleWrite("POPUP MENU")
    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)
    _GUICtrlMenu_TrackPopupMenu($hMenu, $hWnd, $x, $y)
EndFunc   ;==>TrackPopupMenu

Edit I tried with WM_ContextMenu and while it does recieve Shift+F10 it lags behind on notifications and isn't able to be blocked either so I'd say thats probably the reason for the behavior you saw.. My guess is that the listview implements its own context popup

Spoiler
#include <Misc.au3>
#include <ListViewConstants.au3>
#include <GUIConstants.au3>
#include <GuiMenu.au3>


Global $GUI = GUICreate("test")

Global $g_IdList1 = GUICtrlCreateListView("#|x|y", 5, 24, 161, 70, $LVS_SHOWSELALWAYS Or $LVS_SINGLESEL)
Global $g_hList1 = GUICtrlGetHandle ($g_IdList1)
GUICtrlCreateListViewItem("text", $g_IdList1)


Global $context = GUICtrlCreateContextMenu($g_IdList1)
GUICtrlCreateMenuItem("1", $context)
GUICtrlCreateMenuItem("2", $context)


Global $g_IdList2 = GUICtrlCreateListView("#|x|y", 5, 100, 161, 70, $LVS_SHOWSELALWAYS Or $LVS_SINGLESEL)
Global $g_hList2 = GUICtrlGetHandle ($g_IdList2)
GUICtrlCreateListViewItem("text", $g_IdList2)

Global $context2 = GUICtrlCreateContextMenu($g_IdList2)
GUICtrlCreateMenuItem("3", $context2)
GUICtrlCreateMenuItem("4", $context2)


GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_CONTEXTMENU, WM_CONTEXTMENU)
GUIRegisterMsg($WM_ENTERMENULOOP, WM_CONTEXTMENU)

While 1
    Switch GUIGetMsg()
        Case $gui_event_close
            Exit

    EndSwitch
WEnd

Func WM_CONTEXTMENU($hWnd, $iMsg, $wParam, $lParam)
    Switch $wParam
        Case $g_hList1
            ConsoleWrite("LV1 " & Hex($hWnd) & @CRLF)
        Case $g_hList2
            ConsoleWrite("LV2 " & Hex($hWnd) & @CRLF)
        Case Else
            If $iMsg = $WM_ENTERMENULOOP Then
                ConsoleWrite("ENTERMENULOOP: " & Hex($hWnd) & " TrackPopup: " & ($wParam ? "True":"False") & @CRLF)
            EndIf
    EndSwitch

    Return $GUI_RUNDEFMSG
EndFunc

Func ShowMenu($hWnd, $idCtrl, $idContext)
    ConsoleWrite("POPUP MENU")
    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)
    _GUICtrlMenu_TrackPopupMenu($hMenu, $hWnd, $x, $y)
EndFunc   ;==>TrackPopupMenu

 

 

Edited by Bilgus

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

  • Similar Content

    • By Miliardsto
      I have the following code. You can see there are $color_normal and $color_trans
      In my case normal is too dark . And color trans is to much violet.
      If you run it you will see how its looks. I want gui with listView have the same color like taskbar in windows 10.
      How to achieve that?
       
       
      #include <Date.au3> #include <MsgBoxConstants.au3> #include <GuiListBox.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <GuiListView.au3> HotKeySet("{ESC}", "Terminate") $color_normal = "0x" & StringLeft(StringRight(RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent", "AccentPalette"), 24), 6) $color_trans = "0x" & StringLeft(StringRight(RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent", "AccentPalette"), 16), 6) $trans = RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize", "EnableTransparency") ConsoleWrite("Transpart = " & $trans & @CRLF) ConsoleWrite("Color normal = " & $color_normal & @CRLF) ConsoleWrite("Color trans = " & $color_trans & @CRLF) ConsoleWrite(_Get_taskbar_color()); It return AARRGGBB $taskbarColor = _Get_taskbar_color() Global $gui = GUICreate("Test", 150, 58,@DesktopWidth-300,@DesktopHeight-58,$WS_POPUP,BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW)) Global $idListview = GUICtrlCreateListView("", 0, 0, 150, 58,BitOR($LBS_NOTIFY,$LBS_SORT), 0) ;_GuiCtrlMakeTrans(-1,100) ; Add column _GUICtrlListView_AddColumn($idListview, "Msgs", 100) GUICtrlSetFont(-1, 7, 400, 0, "Segoe UI") GUICtrlSetColor(-1, 0x470C4F) GUICtrlSetBkColor($idListview, 0x310638) GUISetState() While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func Terminate() Exit EndFunc Func _Get_taskbar_color() If RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize", "ColorPrevalence") Then If RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize", "EnableTransparency") Then Return "0xD9" & StringLeft(StringRight(RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent", "AccentPalette"), 16), 6) Else Return "0xFF" & StringLeft(StringRight(RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Accent", "AccentPalette"), 24), 6) EndIf Else If RegRead("HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize", "EnableTransparency") Then Return "0xD9000000" Else Return "0xFF000000" EndIf EndIf EndFunc  
    • By kurtykurtyboy
      GuiFlatButton is a UDF to easily create regular buttons with different colors for background, foreground, border, hover, focus, etc..
      This started as an effort to change the background color of a button and eventually grew into a full UDF.
      If you've looked around forums for changing button background colors, you have probably noticed that each proposed workaround has its own set of issues/side-effects. The answers usually circle back to 'use ownerdrawn buttons' and 'not worth it'. Well, now it is possible for anyone to easily create ownerdrawn buttons - totally worth it!
      Some issues with other workarounds such as drawing with GDI+ or using a colored label as a 'button':
      Not 'real' buttons so you lose built-in functionality that windows gives to buttons Messy / inefficient code in the main while loop to check for mouse position Slow to respond to click, paint, etc... Having to deal with GUIRegisterMsg messages Not straight-forward to implement GuiFlatButton is not a workaround; it is a technique to respond to Windows' built-in owner-drawn button events.
      With minimal effort, we can now create true simple colored buttons.
      The idea is to create an owner-drawn button using GUICtrlCreateButton then subclass the GUI and controls to handle the button-specific events to paint it however we want.
      This UDF magically does all of this for us! No need to worry about event handling or main while loop logic.
       
      How to use
      It couldn't be any easier! Simply create a new button using the familiar syntax. This creates an ownerdrawn button with default colors.
      $mybutton1 = GuiFlatButton_Create("Button 1", 78, 20, 120, 40) If you want to change the background and text colors:
      GuiFlatButton_SetBkColor(-1, 0x5555FF) GuiFlatButton_SetColor(-1, 0xFFFFFF) Advanced Usage
      Set background/text/border all at once
      GuiFlatButton_SetColors(-1, 0x0000FF, 0xFFFFFF, 0x9999FF) Set ALL colors for ALL button states! (normal, focus, hover, selected)
      Local $aColorsEx = [0x0000FF, 0xFFFFFF, -2, 0x4444FF, 0xFFFFFF, 0xAAAAFF, 0x6666FF, 0xFFFFFF, 0xCCCCFF, 0x0000EE, 0xFFFFFF, 0x7777EE] GuiFlatButton_SetColorsEx(-1, $aColorsEx) Set default colors to apply to any future buttons
      ;set colors GuiFlatButton_SetDefaultColors(0x0000FF, 0xFFFFFF, 0x9999FF) ;create buttons $mybutton1 = GuiFlatButton_Create("Button 1", 12, 20, 120, 40) $mybutton2 = GuiFlatButton_Create("Button 2", 143, 20, 120, 40) Set ALL color defaults
      ;set colors Local $aColorsEx = [0x0000FF, 0xFFFFFF, -2, 0x4444FF, 0xFFFFFF, 0xAAAAFF, 0x6666FF, 0xFFFFFF, 0xCCCCFF, 0x0000EE, 0xFFFFFF, 0x7777EE] GuiFlatButton_SetDefaultColorsEx($aColorsEx) ;create buttons $mybutton1 = GuiFlatButton_Create("Button 1", 12, 20, 120, 40) $mybutton2 = GuiFlatButton_Create("Button 2", 143, 20, 120, 40)  
      Available Functions
       
      Simple Example

      #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include "GuiFlatButton.au3" Example() ;GUI with one button Func Example() Local $hGUI, $mybutton1 $hGUI = GUICreate("GuiFlatButton Ex0", 275, 120) GUISetBkColor(0x333333) $idLabel = GUICtrlCreateLabel("Click the button", 10, 100, 150, 30) GUICtrlSetColor(-1, 0xFFFFFF) ;create new button then set the background and foreground colors $mybutton1 = GuiFlatButton_Create("Button 1", 78, 20, 120, 40) GuiFlatButton_SetBkColor(-1, 0x5555FF) GuiFlatButton_SetColor(-1, 0xFFFFFF) GUISetState(@SW_SHOW, $hGUI) Local $i = 0 Local $iMsg While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop Case $mybutton1 $i += 1 GUICtrlSetData($idLabel, $i) ConsoleWrite($i & @CRLF) EndSwitch Sleep(10) WEnd GUIDelete() EndFunc ;==>Example
      Menu/Toolbar Example

      #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include "GuiFlatButton.au3" Example() ;Example GUI with toolbar Func Example() Local $hGUI, $idLabel, $aButtons, $iTbSize $hGUI = GUICreate("GuiFlatButton Ex2", 300, 200) GUISetBkColor(0x444444) $idLabel = GUICtrlCreateLabel("Click a button", 10, 180, 150, 30) GUICtrlSetColor(-1, 0xFFFFFF) $aButtons = createToolbar() $iTbSize = UBound($aButtons) GUISetState(@SW_SHOW, $hGUI) Local $i = 0 Local $iMsg While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop Case $aButtons[0] To $aButtons[$iTbSize - 1] ConsoleWrite("1") GUICtrlSetData($idLabel, GuiFlatButton_Read($iMsg)) EndSwitch Sleep(10) WEnd GUIDelete() EndFunc ;==>Example Func createToolbar() Local $aButtons[6] Local $bkColor = 0x777777 Local $textColor = 0xFFFFFF Local $borderColor = 0x999999 Local $aBtnClrs[12] = [0x777777, 0xFFFFFF, $GUI_BKCOLOR_TRANSPARENT, 0x888888, 0xFFFFFF, $GUI_BKCOLOR_TRANSPARENT, 0x999999, 0xFFFFFF, $GUI_BKCOLOR_TRANSPARENT, 0x666666, 0xFFFFFF, $GUI_BKCOLOR_TRANSPARENT] For $i = 0 To UBound($aButtons) - 1 $aButtons[$i] = GuiFlatButton_Create("B" & $i, $i * 50, 0, 50, 17) GuiFlatButton_SetColorsEx($aButtons[$i], $aBtnClrs) Next Return $aButtons EndFunc ;==>createToolbar  
      Icon Example
      You can even easily add icons to your buttons -- just create a new button and send it an icon!

      #include <GDIPlus.au3> #include "GuiFlatButton.au3" Example() ;buttons with Icon images Func Example() ;get images for demonstration _GDIPlus_Startup() ;initialize GDI+ Local $hIcon = _WinAPI_ShellExtractIcon(@SystemDir & '\shell32.dll', 258, 24, 24) ;extract the 'Save' icon Local $hBitmap = _GDIPlus_BitmapCreateFromHICON($hIcon) ;Create Bitmap from Icon (for demonstration) Local $hHBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hBitmap) ;Create HBitmap from Bitmap _GDIPlus_BitmapDispose($hBitmap) ;dispose the bitmap _GDIPlus_Shutdown() ;done with GDI+ Local $hGUI = GUICreate("GuiFlatButton Ex5", 255, 400) GUISetBkColor(0xEEEEEE) ;set default colors of future buttons Local $aColorsEx = _ [0xE2E5E8, 0X000000, 0x888888, _ ; normal : Background, Text, Border 0xE2E5E8, 0X000000, 0x333333, _ ; focus : Background, Text, Border 0xE8E8E8, 0X000000, 0x666666, _ ; hover : Background, Text, Border 0xDDDDDD, 0X000000, 0xAAAAAA] ; selected : Background, Text, Border GuiFlatButton_SetDefaultColorsEx($aColorsEx) ;normal button with icon $label1 = GUICtrlCreateLabel( "$BS_TOOLBUTTON -->", 5, 10) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) Local $mybutton1 = GuiFlatButton_Create("Save", 130, 5, 50, 48, $BS_TOOLBUTTON) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybutton1), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align top Local $mybuttonT = GuiFlatButton_Create("Top", 5, 65, 120, 55, $BS_TOP) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonT), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align top-left Local $mybuttonTL = GuiFlatButton_Create("Top-Left", 5, 125, 120, 55, BITOR($BS_TOP, $BS_LEFT)) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonTL), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align top-right Local $mybuttonTR = GuiFlatButton_Create("Top-Right", 5, 185, 120, 55, BITOR($BS_TOP, $BS_RIGHT)) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonTR), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align left Local $mybuttonL = GuiFlatButton_Create("Left", 5, 245, 120, 55, $BS_LEFT) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonL), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align bottom Local $mybuttonB = GuiFlatButton_Create("Bottom", 130, 65, 120, 55, $BS_BOTTOM) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonB), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align bottom-left Local $mybuttonBL = GuiFlatButton_Create("Bottom-Left", 130, 125, 120, 55, BITOR($BS_BOTTOM, $BS_LEFT)) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonBL), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align bottom-right Local $mybuttonBR = GuiFlatButton_Create("Bottom-Right", 130, 185, 120, 55, BITOR($BS_BOTTOM, $BS_RIGHT)) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonBR), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) ;align right Local $mybuttonR = GuiFlatButton_Create("Right", 130, 245, 120, 55, $BS_RIGHT) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonR), $BM_SETIMAGE, $IMAGE_ICON, $hIcon)) GuiFlatButton_SetState($mybuttonR, $GUI_DISABLE ) ;disabled Local $mybuttonDisable = GuiFlatButton_Create("Disabled", 130, 310, 120, 55, $BS_TOOLBUTTON) _WinAPI_DeleteObject(_SendMessage(GUICtrlGetHandle($mybuttonDisable), $BM_SETIMAGE, $IMAGE_BITMAP, $hHBitmap)) GuiFlatButton_SetState($mybuttonDisable, $GUI_DISABLE ) ;clean up! _WinAPI_DestroyIcon( $hIcon ) _WinAPI_DeleteObject( $hHBitmap ) GUISetState(@SW_SHOW, $hGUI) Local $iMsg While 1 $iMsg = GUIGetMsg() Switch $iMsg Case $GUI_EVENT_CLOSE ExitLoop EndSwitch Sleep(10) WEnd GUIDelete() EndFunc ;==>Example  
      I'm sure there are some use-cases I've forgotten, so feedback is welcome!
       
      Download the UDF and several more examples: GuiFlatButton_20190414.zip
      Update 2019-04-14
      Fixed bug, not showing pressed down state when clicking rapidly
      Added Icon/Bitmap support!
      Added function GuiFlatButton_SetPos to change the position and/or size of a button
      Update 2019-02-09
      Added 2 new functions to set the button colors globally for all future buttons.
      GuiFlatButton_SetDefaultColors 
      GuiFlatButton_SetDefaultColorsEx

      Credits to:
      Melba23 (UDF template)
      LarsJ (general subclassing code)
      4ggr35510n (TrackMouseEvent example)
      binhnx (disable dragging with $WS_EX_CONTROLPARENT)
      GUIRegisterMsg in AutoIt Help (owner-draw button example)
      funkey (_WinAPI_DrawState example)
    • By Slipk
      Hello everybody,
      #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> #include <GUIListViewEx.au3> $Form1 = GUICreate("Form1", 539, 350, 192, 124) $ListView1 = GUICtrlCreateListView("CLM1|CLM2", 0, 0, 538, 326) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 150) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 150) Local $dynamic = GUICtrlCreateListViewItem("Example1|Example2", $ListView1) $SubMenu = GUICtrlCreateContextMenu($dynamic) $Run = GUICtrlCreateMenuItem("Run", $SubMenu) $Edit = GUICtrlCreateMenuItem("Edit", $SubMenu) $Delete = GUICtrlCreateMenuItem("Delete", $SubMenu) Local $dynamic2 = GUICtrlCreateListViewItem("Example3|Example6", $ListView1) $SubMenu = GUICtrlCreateContextMenu($dynamic2) $Run = GUICtrlCreateMenuItem("Run", $SubMenu) $Edit = GUICtrlCreateMenuItem("Edit", $SubMenu) $Delete = GUICtrlCreateMenuItem("Delete", $SubMenu) _GUIListViewEx_Init($ListView1, "", 0, 0, True, 64) _GUIListViewEx_MsgRegister() GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd I use GUIListViewEx.au3 for position of items in listview but when I move one the context menu disappear. Any solution of this?
      Any method than array it is possible?
      Thank you, appreciate it.
       
       
    • By Slipk
      Hello everybody,
      I download the GUIListViewEx.au3 by Melba23 in order to move up or down my items from a listview.
      Everything it's looking good in script but when I move an item it will crash.
      Any suggestions?
      Thank you! 

    • By Slipk
      Hello everybody,
      Sorry for my bad english.
       
      I try to figure out if I have a dynamic listview with as many items as I want, how to save to a text file all the data listview contains in the same form that you put when you create a listviewitem. I will give you an example.
      When the script is running it will show you the listview and some items. How to take the items data "Data1|Data1_Sub1|Data1_Sub2" in this format and paste into a text file? All of them.
      I tried to explain as good as I can.
      Thank you for your attention!
      #include <GUIConstantsEx.au3> #include <ListViewConstants.au3> #include <WindowsConstants.au3> $Form_Menu = GUICreate("Form Example", 351, 234, -1, -1) $Form_Menu_ListView1 = GUICtrlCreateListView("Column #1|Column #2|Column #3", 0, 0, 346, 230) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 75) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 75) GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 2, 75) GUICtrlCreateListViewItem("Data1|Data1_Sub1|Data1_Sub2", $Form_Menu_ListView1) GUICtrlCreateListViewItem("Data2|Data2_Sub1|Data2_Sub2", $Form_Menu_ListView1) GUICtrlCreateListViewItem("DataN|DataN_SubN|DataN_SubN", $Form_Menu_ListView1) ;The data that appear in the listview be saved in a file like that : #cs Data1|Data1_Sub1|Data1_Sub2 Data2|Data2_Sub1|Data2_Sub2 DataN|DataN_SubN|DataN_SubN #ce GUISetState(@SW_SHOW, $Form_Menu) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd
×
×
  • Create New...