Jump to content
Sign in to follow this  
FaridAgl

No Context Menu on Header of ListView

Recommended Posts

FaridAgl

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

Share this post


Link to post
Share on other sites
FireFox

Yes we did.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
FireFox

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

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
FaridAgl

Well, thank you and yes, that's quite nice, ignoring the right-click on no item is great.

Selecting the first item on header right-click is a tricky way, but I'm more interested to disable the right-click for the header.

Any idea?

Share this post


Link to post
Share on other sites
FireFox

It's not an issue, it redirects the right click on the first listview item.

I will take a look at it.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites
FireFox

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.


 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

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  

×