Sign in to follow this  
Followers 0
phew

GuiCreateListView() & GuiCreateListViewItems

7 posts in this topic

hellow thar!

i got some problems playing with the guictrl-functions. i created an ListView with 2 columns - but is there any possibility to add ie. 'www.autoitscript.com' to the first column in the first line by using right-mouse on the ListView and there popps up an mouse-menu with the option "insert"?

just like this:

Posted Image

greetings

Share this post


Link to post
Share on other sites



no one who can give me just a point into the right direction?

Share this post


Link to post
Share on other sites

Hi!

Try this:

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

Global $idMenuInsert = 1000

$Gui = GUICreate("Test", 320, 200)

$hListView = _GUICtrlListView_Create($GUI, "Links(0)", 10, 10, 300, 180, -1, $WS_EX_CLIENTEDGE)

_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))

_GUICtrlListView_SetColumnWidth($hListView, 0, 295)

$hMenu = _GUICtrlMenu_CreatePopup()

_GUICtrlMenu_InsertMenuItem($hMenu, 0, "Insert link", $idMenuInsert)

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $GUI_EVENT_CLOSE
        ExitLoop
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $iItemCount
    $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
                If _GUICtrlMenu_TrackPopupMenu($hMenu, $hListView, -1, -1, 1, 1, 2) = $idMenuInsert Then
                    _GUICtrlListView_InsertItem($hListView, "www.autoitscript.com")
                    $iItemCount = _GUICtrlListView_GetItemCount($hListView)
                    _GuiCtrlListView_SetColumn($hListView, 0, "Links(" & $iItemCount & ")")
                EndIf
        EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc
:)

Share this post


Link to post
Share on other sites

Hi!

Try this:

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

Global $idMenuInsert = 1000

$Gui = GUICreate("Test", 320, 200)

$hListView = _GUICtrlListView_Create($GUI, "Links(0)", 10, 10, 300, 180, -1, $WS_EX_CLIENTEDGE)

_GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT))

_GUICtrlListView_SetColumnWidth($hListView, 0, 295)

$hMenu = _GUICtrlMenu_CreatePopup()

_GUICtrlMenu_InsertMenuItem($hMenu, 0, "Insert link", $idMenuInsert)

GUISetState()

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    $msg = GUIGetMsg()
    Switch $msg
    Case $GUI_EVENT_CLOSE
        ExitLoop
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iCode, $tNMHDR, $hWndListView, $iItemCount
    $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
                If _GUICtrlMenu_TrackPopupMenu($hMenu, $hListView, -1, -1, 1, 1, 2) = $idMenuInsert Then
                    _GUICtrlListView_InsertItem($hListView, "www.autoitscript.com")
                    $iItemCount = _GUICtrlListView_GetItemCount($hListView)
                    _GuiCtrlListView_SetColumn($hListView, 0, "Links(" & $iItemCount & ")")
                EndIf
        EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc
:)
thanks a lot, that was exactly what i was looking for!

Share this post


Link to post
Share on other sites

mhh thanks, that helped a lot, but could you please explain where the WM_NOTIFY function is called?

i can't find the place that calls the function and sends the parameters to it, so i don't really understand

what the parameters have to look like

greetings

Share this post


Link to post
Share on other sites

@phew

i can't find the place that calls the function and sends the parameters to it

Here we registered a function:

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

Share this post


Link to post
Share on other sites

okay had to read a lot about this - i did not really work too much with GUI stuff yet - but i think now its all clear to me, thank you :)

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