mark2004 Posted December 20, 2006 Posted December 20, 2006 I was looking into how to react to a double-click event within a listbox and I came across a method using $WM_NOTIFY. I modified some code (apparently originally created by GaFrost) to do this and it works well. My question is why do you need to also make use of the AutoIt event handler (the switch/$Event_Code block) when you already have the switch block in the WM_Notify_Events function. It seems like you could just put your code within the WM_Notify_Events function and be done with it. But, I know there must be a reason. If GaFrost or anyone else can enlighten me I'd sure appreciate it. Mark -------------------------------------------------------------- #include <GuiConstants.au3>;Inclusion file for the GUI interface controls #include <GuiListView.au3> Global $Event_On_Control Global $Event_Code Global Const $WM_NOTIFY = 0x004E Global Const $DebugIt = 1 ;ListView Events Global Const $NM_CLICK = -2 Global Const $NM_DBLCLK = -3 Global Const $NM_RETURN = -4 Global Const $NM_RCLICK = -5 ;#endregion End Global variables Opt("WinTitleMatchMode", 2) $main_GUI = GUICreate("GuiRegisterMsg Test", 225, 400, 300, 10, BitOR($WS_THICKFRAME, $WS_SIZEBOX)) $Event_On_Control = GUICtrlCreateListView("Entry Name|Category", 5, 75, 195, 280, BitOR($LVS_SORTASCENDING, $LVS_SINGLESEL)) ;~ $Event_On_Control = $CodeListView _GUICtrlListViewSetColumnWidth ($Event_On_Control, 0, 100) _GUICtrlListViewSetColumnWidth ($Event_On_Control, 1, 100) GUICtrlSendMsg($Event_On_Control, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES) GUICtrlSendMsg($Event_On_Control, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT) $Trans_slider = GUICtrlCreateSlider(203, 75, 20, 280, $TBS_VERT, $WS_EX_CLIENTEDGE) GUICtrlSetLimit($Trans_slider, 255, 62); change min/max value GUICtrlSetData($Trans_slider, 255) $Transparency = Int((((Int(GUICtrlRead($Trans_slider)) / 255) * 100) - 100) * - 1) GUISetState() ;Register WM_NOTIFY events GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events") While 1 $msg = GUIGetMsg() Switch $msg ;----------------------------------------------------------------------------------------- ;This case statement exits and updates code if needed Case $GUI_EVENT_CLOSE Exit ;----------------------------------------------------------------------------------------- ;put all the misc. stuff here Case Else If $Transparency <> Int((((Int(GUICtrlRead($Trans_slider)) / 255) * 100) - 100) * - 1) Then $Transparency = Int((((Int(GUICtrlRead($Trans_slider)) / 255) * 100) - 100) * - 1) WinSetTrans($main_GUI, "", Int(GUICtrlRead($Trans_slider))) EndIf Switch $Event_Code Case $NM_DBLCLK $Event_Code = 0 ;ContinueLoop Case $NM_CLICK $Event_Code = 0 ;ContinueLoop Case Else $Event_Code = 0 EndSwitch EndSwitch WEnd ; WM_NOTIFY event handler Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam) #forceref $hWndGUI, $MsgID Local $tagNMHDR, $event Switch $wParam Case $Event_On_Control $tagNMHDR = DllStructCreate("int;int;int", $lParam);NMHDR (hwndFrom, idFrom, code) If @error Then Return $event = DllStructGetData($tagNMHDR, 3) Switch $event Case $NM_CLICK $Event_Code = $event If $DebugIt Then ConsoleWrite("-->$NM_CLICK" & @LF) Case $NM_DBLCLK $Event_Code = $event If $DebugIt Then ConsoleWrite("-->$NM_DBLCLK" & @LF) EndSwitch EndSwitch $tagNMHDR = 0 EndFunc ;==>WM_Notify_Events
GaryFrost Posted December 20, 2006 Posted December 20, 2006 You had to of gone a ways back for that one, that was early on. btw use code tags expandcollapse popup#include <GuiConstants.au3> Global Const $DebugIt = 1 Global Const $WM_COMMAND = 0x0111 GuiCreate("MyGUI", 460, 260,-1, -1) $Edit_1 = GuiCtrlCreateEdit("Edit1", 10, 10, 360, 210) $Input_2 = GuiCtrlCreateInput("Input2", 10, 230, 360, 20) $List_3 = GuiCtrlCreateList("List3", 380, 10, 70, 240, BitOR($LBS_SORT, $LBS_NOINTEGRALHEIGHT, $LBS_NOTIFY, $WS_TABSTOP)) GUICtrlSetData($List_3,"item2") GuiSetState() GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND") While 1 $msg = GuiGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ExitLoop Case Else ;;; EndSelect WEnd Exit Func List_DoubleClick() ;---------------------------------------------------------------------------------------------- If $DebugIt Then _DebugPrint ("$LBN_DBLCLK: " & GUICtrlRead($List_3)) ;---------------------------------------------------------------------------------------------- EndFunc ;==>ListView_DoubleClick Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam) Local $nNotifyCode = _HiWord($wParam) Local $nID = _LoWord($wParam) Local $hCtrl = $lParam Local Const $LBN_ERRSPACE = (-2); Local Const $LBN_SELCHANGE = 1; Local Const $LBN_DBLCLK = 2; Local Const $LBN_SELCANCEL = 3; Local Const $LBN_SETFOCUS = 4; Local Const $LBN_KILLFOCUS = 5; Switch $nID Case $List_3 Switch $nNotifyCode Case $LBN_ERRSPACE _DebugPrint ("$LBN_ERRSPACE") Case $LBN_SELCHANGE _DebugPrint ("$LBN_SELCHANGE") Case $LBN_SELCANCEL _DebugPrint ("$LBN_SELCANCEL") Case $LBN_SETFOCUS _DebugPrint ("$LBN_SETFOCUS") Case $LBN_KILLFOCUS _DebugPrint ("$LBN_KILLFOCUS") Case $LBN_DBLCLK List_DoubleClick() EndSwitch EndSwitch ; Proceed the default Autoit3 internal message commands. ; You also can complete let the line out. ; !!! But only 'Return' (without any value) will not proceed ; the default Autoit3-message in the future !!! Return $GUI_RUNDEFMSG EndFunc ;==>MY_WM_COMMAND Func _DebugPrint($s_text) $s_text = StringReplace($s_text, @LF, @LF & "-->") ConsoleWrite("!===========================================================" & @LF & _ "+===========================================================" & @LF & _ "-->" & $s_text & @LF & _ "+===========================================================" & @LF) EndFunc ;==>_DebugPrint Func _HiWord($x) Return BitShift($x, 16) EndFunc ;==>_HiWord Func _LoWord($x) Return BitAND($x, 0xFFFF) EndFunc ;==>_LoWord SciTE for AutoItDirections for Submitting Standard UDFs  Don't argue with an idiot; people watching may not be able to tell the difference. Â
mark2004 Posted December 20, 2006 Author Posted December 20, 2006 That's why its dangerous to rely just on what you get in a search of the archives!!! So, I take it that the reliance on the Autoit event handler is redundant since I didn't see it in your modified version. Cool. And by "code tags" do you mean commenting??
JoshDB Posted December 20, 2006 Posted December 20, 2006 Code tags: <CODE HERE> It will look like this: $var = 'a' Ha, I haven't been on these forums since... 2006, almost. Behold, my legacy signature:My AutoIt idol is Valuater. You know you love him, too.My Stuff: D&D AGoT Tools Suite
mark2004 Posted December 20, 2006 Author Posted December 20, 2006 GaFrost, Well, I tried to add your new notification code and can't seem to get it to work for my listview. I must have looked at this thing over 100 times and can't figure it out. I don't know if it has something to do with the lack of a listview style equivalent to $LBS_NOTIFY or what. Any help would be appreciated. expandcollapse popup#include <GuiListView.au3> #include <GUIConstants.au3> #include <file.au3> Global $Event_Code Global $Event_On_Control Global Const $WM_COMMAND = 0x0111 Global Const $DebugIt = 1 ;ListView Events Global Const $NM_FIRST = 0 Global Const $NM_CLICK = $NM_FIRST-2 Global Const $NM_DBLCLK = $NM_FIRST-3 Global Const $NM_RETURN = -4 Global Const $NM_RCLICK = -5 $GUI = GUICreate("MyGUI", 1016, 687, 2, 11) $Opencaselist = GUICtrlCreateListView("Days|Case Name|Amount", 377, 122, 317, 533, BitOR($LVS_REPORT,$LVS_SINGLESEL,$LVS_SHOWSELALWAYS,$LVS_SORTDESCENDING)) GUISetState() GUICtrlCreateListViewItem("25|Daley/Hill|$566",$Opencaselist) GUICtrlCreateListViewItem("35|Daley/Watts|$800",$Opencaselist) GUICtrlCreateListViewItem("15|Daley/Winel|$750",$Opencaselist) GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case Else EndSwitch WEnd Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam) Local $nNotifyCode = _HiWord($wParam) Local $nID = _LoWord($wParam) Local $hCtrl = $lParam Local Const $NM_CLICK = -2 Local Const $NM_DBLCLK = -3 Local Const $NM_RETURN = -4 Local Const $NM_RCLICK = -5 MsgBox(0,"",$nID) Switch $nID Case $Opencaselist Switch $nNotifyCode Case $NM_CLICK _DebugPrint ("$NM_CLICK") Case $NM_RCLICK _DebugPrint ("$NM_RCLICK") Case $NM_DBLCLK _DebugPrint ("$NM_DBLCLK") Case $NM_RETURN _DebugPrint ("$NM_RETURN") EndSwitch EndSwitch ; Proceed the default Autoit3 internal message commands. ; You also can complete let the line out. ; !!! But only 'Return' (without any value) will not proceed ; the default Autoit3-message in the future !!! Return $GUI_RUNDEFMSG EndFunc ;==>MY_WM_COMMAND Func _DebugPrint($s_text) $s_text = StringReplace($s_text, @LF, @LF & "-->") ConsoleWrite("!===========================================================" & @LF & _ "+===========================================================" & @LF & _ "-->" & $s_text & @LF & _ "+===========================================================" & @LF) EndFunc ;==>_DebugPrint Func _HiWord($x) Return BitShift($x, 16) EndFunc ;==>_HiWord Func _LoWord($x) Return BitAND($x, 0xFFFF) EndFunc ;==>_LoWord
Polyphem Posted December 20, 2006 Posted December 20, 2006 (edited) What should happen on a double-click?Edit: I see. You'r talking about ListView, gafrosts example was for List only, guess for ListView the WM_COMMANDs are different, if there are any. Implemented the above code in a list here: http://www.autoitscript.com/forum/index.php?showtopic=38178, dont know if this works for ListView. According to the help-file, i dont see a Notify Style for ListView. Edited December 20, 2006 by Polyphem This post will be edited again by Polyphem: Tomorrow, 11:55 AM
GaryFrost Posted December 20, 2006 Posted December 20, 2006 (edited) GaFrost, Well, I tried to add your new notification code and can't seem to get it to work for my listview. I must have looked at this thing over 100 times and can't figure it out. I don't know if it has something to do with the lack of a listview style equivalent to $LBS_NOTIFY or what. Any help would be appreciated. It would help if I gave you the example for Listview instead of ListBox expandcollapse popup; Events - ListView #include <GuiConstants.au3>;Inclusion file for the GUI interface controls #include <GuiListView.au3> Global $ListView Global Const $WM_NOTIFY = 0x004E Global Const $DebugIt = 1 ;ListView Events Global Const $NM_FIRST = 0 Global Const $NM_LAST = (-99) Global Const $NM_OUTOFMEMORY = ($NM_FIRST - 1) Global Const $NM_CLICK = ($NM_FIRST - 2) Global Const $NM_DBLCLK = ($NM_FIRST - 3) ;~ Global Const $NM_RETURN = ($NM_FIRST - 4) ;~ Global Const $NM_RCLICK = ($NM_FIRST - 5) ;~ Global Const $NM_RDBLCLK = ($NM_FIRST - 6) ;~ Global Const $NM_SETFOCUS = ($NM_FIRST - 7) ;~ Global Const $NM_KILLFOCUS = ($NM_FIRST - 8) ;~ Global Const $NM_CUSTOMDRAW = ($NM_FIRST - 12) ;~ Global Const $NM_HOVER = ($NM_FIRST - 13) ;~ Global Const $NM_NCHITTEST = ($NM_FIRST - 14) ;~ Global Const $NM_KEYDOWN = ($NM_FIRST - 15) ;~ Global Const $NM_RELEASEDCAPTURE = ($NM_FIRST - 16) ;~ Global Const $NM_SETCURSOR = ($NM_FIRST - 17) ;~ Global Const $NM_CHAR = ($NM_FIRST - 18) ;~ Global Const $NM_TOOLTIPSCREATED = ($NM_FIRST - 19) #endregion End Global variables Opt("WinTitleMatchMode", 2) $main_GUI = GUICreate("GuiRegisterMsg Test", 225, 400, 300, 10, BitOR($WS_THICKFRAME, $WS_SIZEBOX)) $ListView = GUICtrlCreateListView("Entry Name|Category", 5, 75, 195, 280, BitOR($LVS_SORTASCENDING, $LVS_SINGLESEL)) _GUICtrlListViewSetColumnWidth ($ListView, 0, 100) _GUICtrlListViewSetColumnWidth ($ListView, 1, 100) GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_GRIDLINES, $LVS_EX_GRIDLINES) GUICtrlSendMsg($ListView, $LVM_SETEXTENDEDLISTVIEWSTYLE, $LVS_EX_FULLROWSELECT, $LVS_EX_FULLROWSELECT) GUICtrlCreateListViewItem("Name 1|Category 1", $ListView) GUICtrlCreateListViewItem("Name 2|Category 2", $ListView) GUISetState() ;Register WM_NOTIFY events GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events") While 1 $msg = GUIGetMsg() Switch $msg ;----------------------------------------------------------------------------------------- ;This case statement exits and updates code if needed Case $GUI_EVENT_CLOSE Exit ;----------------------------------------------------------------------------------------- ;put all the misc. stuff here Case Else ;;; EndSwitch WEnd Func ListView_Click() ;---------------------------------------------------------------------------------------------- If $DebugIt Then _DebugPrint ("$NM_CLICK") ;---------------------------------------------------------------------------------------------- EndFunc ;==>ListView_Click Func ListView_DoubleClick() ;---------------------------------------------------------------------------------------------- If $DebugIt Then _DebugPrint("$NM_DBLCLK") ;---------------------------------------------------------------------------------------------- MsgBox(0,"Double Clicked", _GUICtrlListViewGetItemText ($ListView, _GUICtrlListViewGetSelectedIndices($ListView))) EndFunc ;==>ListView_DoubleClick ; ; WM_NOTIFY event handler Func WM_Notify_Events($hWndGUI, $MsgID, $wParam, $lParam) #forceref $hWndGUI, $MsgID, $wParam Local $tagNMHDR, $event, $hwndFrom, $code $tagNMHDR = DllStructCreate("int;int;int", $lParam) ;NMHDR (hwndFrom, idFrom, code) If @error Then Return $event = DllStructGetData($tagNMHDR, 3) Select Case $wParam = $ListView Select Case $event = $NM_CLICK ListView_Click () Case $event = $NM_DBLCLK ListView_DoubleClick () EndSelect EndSelect ; Proceed the default Autoit3 internal message commands. ; You also can complete let the line out. ; !!! But only 'Return' (without any value) will not proceed ; the default Autoit3-message in the future !!! Return $GUI_RUNDEFMSG EndFunc ;==>WM_Notify_Events Func _DebugPrint($s_text) $s_text = StringReplace($s_text, @LF, @LF & "-->") ConsoleWrite("!===========================================================" & @LF & _ "+===========================================================" & @LF & _ "-->" & $s_text & @LF & _ "+===========================================================" & @LF) EndFunc ;==>_DebugPrint Edited December 20, 2006 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs  Don't argue with an idiot; people watching may not be able to tell the difference. Â
Polyphem Posted December 20, 2006 Posted December 20, 2006 Hu, i better shut up here... thats to hot for me (replace _DebugHeader with _DebugPrint)... gafrost, could you tell me what the equivalent for "Global Const $NM_RETURN = ($NM_FIRST - 4)" for the list example in your first post of this thread would be? This post will be edited again by Polyphem: Tomorrow, 11:55 AM
GaryFrost Posted December 20, 2006 Posted December 20, 2006 (edited) Hu, i better shut up here... thats to hot for me (replace _DebugHeader with _DebugPrint)... gafrost, could you tell me what the equivalent for "Global Const $NM_RETURN = ($NM_FIRST - 4)" for the list example in your first post of this thread would be? Yeah keep forgetting to update my snippet, fixed Global Const $NM_RETURN = -4 I just like to keep them the same way that I find it used in other languages. Edited December 20, 2006 by gafrost SciTE for AutoItDirections for Submitting Standard UDFs  Don't argue with an idiot; people watching may not be able to tell the difference. Â
Polyphem Posted December 20, 2006 Posted December 20, 2006 (edited) Thats for Listview, right? What to i need for a notification on RETURN in a ListBox? Edited December 20, 2006 by Polyphem This post will be edited again by Polyphem: Tomorrow, 11:55 AM
GaryFrost Posted December 20, 2006 Posted December 20, 2006 Thats for Listview, right? What to i need for a notification on RETURN in a ListBox?listbox is different from a listviewhttp://msdn.microsoft.com/library/shared/d...shellcc759_.xml SciTE for AutoItDirections for Submitting Standard UDFs  Don't argue with an idiot; people watching may not be able to tell the difference. Â
Polyphem Posted December 21, 2006 Posted December 21, 2006 Tried it / searched for it and failed. Guess it has something to do with "The WM_VKEYTOITEM message is sent by a list box with the LBS_WANTKEYBOARDINPUT style to its owner in response to a WM_KEYDOWN message." Guess I'll have to learn a lot more... This post will be edited again by Polyphem: Tomorrow, 11:55 AM
mark2004 Posted December 21, 2006 Author Posted December 21, 2006 listbox is different from a listviewhttp://msdn.microsoft.com/library/shared/d...shellcc759_.xmlHmmmm. so i wasn't that far off with your original snippet that I found way back. It would make more sense if the notificationprocedure weren't control dependent....i.e. WM_COMMAND versus WM_NOTIFY. Not to mention the way you get the eventis different within each of those functions too......very confusing. I'm up and running again so on to the next problem. Many thanks. Maybe someday I'll look back on these procedures and they will make moresense.
mark2004 Posted December 21, 2006 Author Posted December 21, 2006 listbox is different from a listviewhttp://msdn.microsoft.com/library/shared/d...shellcc759_.xmlOne last thing......I've tried using the $NM_RETURN=-4 and I cannot get that one to work. All the other notifications for click, double click, right click work fine.
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