Jump to content

No Context Menu on Header of ListView


FaridAgl
 Share

Go to solution Solved by FireFox,

Recommended Posts

Here is a simple example:

#include <GUIConstantsEx.au3>


GUICreate("ListView", 600, 400)
    Global $lvwListView = GUICtrlCreateListView("Test 1|Test 2|Test 3", 10, 10, 580, 380)
    Global $mnuListView = GUICtrlCreateContextMenu($lvwListView)
    GUICtrlCreateMenuItem("ListView MenuItem 1", $mnuListView)
    GUICtrlCreateMenuItem("ListView MenuItem 2", $mnuListView)
    GUICtrlCreateMenuItem("", $mnuListView)
    GUICtrlCreateMenuItem("ListView MenuItem 3", $mnuListView)
GUISetState()


Do
Until (GUIGetMsg() = $GUI_EVENT_CLOSE)

I just want to see no context menu when right-clicking on the header.

Any one solved this before?

Edited by D4RKON3
Link to comment
Share on other sites

  • Solution

This will work on listview items only (not on the blank part), I can do it but too much tired for today sorry.

Of course if someone else wants to share his solution, I let my place ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
 
#include <GUIListView.au3>
#include <GUIMenu.au3>
 
;>>
Global Enum $_CM_ITEM1 = 1, $_CM_ITEM2
 
GUICreate("ListView", 600, 400)
Global $lvwListView = GUICtrlCreateListView("Test 1|Test 2|Test 3", 10, 10, 580, 380)
 
For $i = 1 To 10
    GUICtrlCreateListViewItem("1|2|3", $lvwListView)
Next
 
; >>
Global $iDyContextMenu = GUICtrlCreateDummy()
GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU")
 
GUISetState()
 
While 1
    Sleep(10)
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $iDyContextMenu
            _Dummy_ContextMenu()
    EndSwitch
WEnd
 
; >>
GUIDelete()
 
Func _Dummy_ContextMenu()
    Switch GUICtrlRead($iDyContextMenu)
        Case $_CM_ITEM1
            MsgBox($MB_SYSTEMMODAL, "", "Item1 clicked.")
        Case $_CM_ITEM2
            MsgBox($MB_SYSTEMMODAL, "", "Item2 clicked.")
    EndSwitch
EndFunc   ;==>_Dummy_ContextMenu
 
Func WM_CONTEXTMENU($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam, $ilParam
 
    Local $aCurInfo = GUIGetCursorInfo($hWnd)
 
    If $aCurInfo[4] <> $lvwListView Then Return $GUI_RUNDEFMSG
 
    Local $aHit = _GUICtrlListView_HitTest($iwParam)
    If $aHit[0] = -1 Then Return $GUI_RUNDEFMSG
 
    _GUICtrlListView_SetItemSelected($iwParam, $aHit[0])
 
    Local $hMenu = 0, $iMenuID = 0
 
    $hMenu = _GUICtrlMenu_CreatePopup()
 
    _GUICtrlMenu_AddMenuItem($hMenu, "ListView MenuItem 1", $_CM_ITEM1)
    _GUICtrlMenu_AddMenuItem($hMenu, "")
    _GUICtrlMenu_AddMenuItem($hMenu, "ListView MenuItem 2", $_CM_ITEM2)
 
    $iMenuID = _GUICtrlMenu_TrackPopupMenu($hMenu, $iwParam, -1, -1, 1, 1, 3)
    If $iMenuID Then GUICtrlSendToDummy($iDyContextMenu, $iMenuID)
 
    _GUICtrlMenu_DestroyMenu($hMenu)
 
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_CONTEXTMENU

Br, FireFox.

Edited by FireFox
Link to comment
Share on other sites

I tried some WM handling but I got nothing concluding.

You can create a listview with just the header and another listview without header and handle the column resize so that it looks like only one listview.

Br, FireFox.

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