MrCreatoR Posted January 19, 2008 Share Posted January 19, 2008 Hi, I am trying to check if user has clicked with right mouse button ("rmb" ) on the list view item's checkbox, but i have problem(s?): expandcollapse popup#include <GuiConstants.au3> #include <GuiListView.au3> Opt("MouseCoordMode", 2) GUICreate("ListView Test", 400, 300) $hListView = GUICtrlCreateListView("", 2, 2, 394, 268) _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $LVS_EX_REGIONAL)) $Context = GUICtrlCreateContextMenu($hListView) $Item = GUICtrlCreateMenuItem("Test Item", $Context) GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") _GUICtrlListView_AddColumn($hListView, "Items", 100) _GUICtrlListView_AddItem($hListView, "Item 1") _GUICtrlListView_AddItem($hListView, "Item 2") _GUICtrlListView_AddItem($hListView, "Item 3") Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView $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 $LVN_HOTTRACK Case $LVN_ITEMACTIVATE; Sent by a list-view control when the user activates an item Case $LVN_ITEMCHANGED; An item has changed Case $LVN_ITEMCHANGING; An item is changing Case $NM_HOVER; Sent by a list-view control when the mouse hovers over an item Case $NM_RCLICK, $NM_RDBLCLK; Sent by a list-view control when the user clicks/dowble clicks an item with the right mouse button $iHot_Item = _GUICtrlListView_GetHotItem($hListView) If $iHot_Item = -1 Then ;the idea here is to check last item Y position, and the current mouse Y position, ;so if mouse is bellow item, i will "know" that it is an empty click on list view control. $iCount_Items = _GUICtrlListView_GetItemCount($hListView) $iYPos = _GUICtrlListView_GetItemPositionY($hListView, $iCount_Items-1) $iMouseYPos = MouseGetPos(1) If $iMouseYPos < $iYPos+15 Then Return 1 ;so the menu will not popup _DebugPrint(StringFormat("yMouse=%d : yLastItem=%d", $iMouseYPos, $iYPos)) EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Func _DebugPrint($s_text, $line = @ScriptLineNumber) ConsoleWrite( _ "!===========================================================" & @LF & _ "+======================================================" & @LF & _ "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _ "+======================================================" & @LF) EndFunc If you run this example, and click with right mouse button on the lv item checkbox, then you will see no menu (as i expecting/needs), but if you click the item text (with right mouse button), and then right a way click on the checkbox (also with right mouse button), you do see the menu, wich is not what i need basicaly i need that the menu will popup ONLY if i press the empty space (on list view control, but not on the items), or if i press the item itself, not his checkbox. Anyone has handle with such problem? i need advice here, i spent a few hours on trying to solve this one out, but no success at all! Thanks. Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
MrCreatoR Posted January 19, 2008 Author Share Posted January 19, 2008 I think i found a solution (finally! ) ... expandcollapse popup#include <GuiConstants.au3> #include <GuiListView.au3> Opt("MouseCoordMode", 2) Global Const $WM_ENTERMENULOOP = 0x0211 Global $MenuIsOpen = False GUICreate("ListView Test", 400, 300) $hListView = GUICtrlCreateListView("", 2, 2, 394, 268) _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $LVS_EX_REGIONAL)) $Context = GUICtrlCreateContextMenu($hListView) $Item = GUICtrlCreateMenuItem("Test Item", $Context) GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUIRegisterMsg($WM_ENTERMENULOOP, "WM_ENTERMENULOOP") _GUICtrlListView_AddColumn($hListView, "Items", 100) _GUICtrlListView_AddItem($hListView, "Item 1") _GUICtrlListView_AddItem($hListView, "Item 2") _GUICtrlListView_AddItem($hListView, "Item 3") Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView $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 $LVN_ITEMCHANGING, $LVN_ITEMCHANGED $MenuIsOpen = False Case $NM_RCLICK, $NM_RDBLCLK $iHot_Item = _GUICtrlListView_GetHotItem($hListView) If $iHot_Item = -1 Then ;the idea here is to check last item X/Y position, and the current mouse X/Y position, ;so if mouse is bellow the item, or it is on the checkbox position, then we return 1 to show no menu. $iCount_Items = _GUICtrlListView_GetItemCount($hListView) $aItemPos = _GUICtrlListView_GetItemPosition($hListView, $iCount_Items-1) $aMousePos = MouseGetPos() If $aMousePos[0]-20 < $aItemPos[0] And $aMousePos[1]-22 < $aItemPos[1] Then Return 1 _DebugPrint(StringFormat("xMouse=%d, yMouse=%d, xLastItem=%d, yLastItem=%d", _ $aMousePos[0], $aMousePos[1], $aItemPos[0], $aItemPos[1])) ElseIf $MenuIsOpen Then $MenuIsOpen = False Return 1 ;so the menu will not popup EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Func WM_ENTERMENULOOP($hWndGUI, $MsgID, $WParam, $LParam) $MenuIsOpen = True EndFunc Func _DebugPrint($s_text, $line = @ScriptLineNumber) ConsoleWrite( _ "!===========================================================" & @LF & _ "+======================================================" & @LF & _ "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _ "+======================================================" & @LF) EndFunc but it would be better if there will be more practic solution, for example, one that will not involve MouseGetPos() function usage (because of "MouseCoordMode" option, and also because of defferent system themes). Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
Siao Posted January 19, 2008 Share Posted January 19, 2008 (edited) Do it this way. Case $NM_RCLICK, $NM_RDBLCLK Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) Local $iIndex = DllStructGetData($tInfo, "Index") If $iIndex <> -1 Then Local $iX = DllStructGetData($tInfo, "X") Local $aIconRect = _GUICtrlListView_GetItemRect($hWndFrom, $iIndex, 1) If $iX < $aIconRect[0] Then Return 1 EndIf Edited January 19, 2008 by Siao "be smart, drink your wine" Link to comment Share on other sites More sharing options...
MrCreatoR Posted January 19, 2008 Author Share Posted January 19, 2008 (edited) @SiaoIt's ingeniously!Thank you very much, even the global variable not needed anymore Edit: typo... my 'b' letter is broken on the keyoard Edited January 19, 2008 by MsCreatoR Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
MrCreatoR Posted January 22, 2008 Author Share Posted January 22, 2008 @Siao It seems that when we use icons (large icons) listview style, this not working anymore expandcollapse popup#include <GuiConstants.au3> #include <GuiListView.au3> GUICreate("ListView NOT RMB Click on checkbox", 400, 300) $hListView = GUICtrlCreateListView("Column", 2, 2, 394, 268) _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $LVS_EX_REGIONAL)) GUICtrlSendMsg($hListView, $LVM_SETVIEW, $LV_VIEW_ICON, 0) $Context = GUICtrlCreateContextMenu($hListView) $Item = GUICtrlCreateMenuItem("Test Item", $Context) GUICtrlCreateListViewItem("Item1", $hListView) GUICtrlSetImage(-1, "shell32.dll", 3) GUICtrlCreateListViewItem("Item2", $hListView) GUICtrlSetImage(-1, "shell32.dll", 4) GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") Do Until GUIGetMsg() = $GUI_EVENT_CLOSE Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView $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, $NM_RDBLCLK Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) Local $iIndex = DllStructGetData($tInfo, "Index") If $iIndex <> -1 Then Local $iX = DllStructGetData($tInfo, "X") Local $aIconRect = _GUICtrlListView_GetItemRect($hWndFrom, $iIndex, 1) If $iX < $aIconRect[0] Then Return 1 EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc Any ideas? Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
Siao Posted January 22, 2008 Share Posted January 22, 2008 (edited) Case $NM_RCLICK, $NM_RDBLCLK Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) Local $iIndex = DllStructGetData($tInfo, "Index") If $iIndex <> -1 Then Local $iX = DllStructGetData($tInfo, "X"), $iPart = 1 If _GUICtrlListView_GetView($hWndFrom) = 1 Then $iPart = 2 Local $aIconRect = _GUICtrlListView_GetItemRect($hWndFrom, $iIndex, $iPart) If $iX < $aIconRect[0] Then Return 1 EndIf Edited January 22, 2008 by Siao "be smart, drink your wine" Link to comment Share on other sites More sharing options...
MrCreatoR Posted January 22, 2008 Author Share Posted January 22, 2008 You are the best! Thanks. Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now