sirWimelef Posted October 22, 2013 Share Posted October 22, 2013 hello again this time, I’m trying to use treeviews with the click detection, after a couple of days of search on the help file, the forums and example files, i found the best way is use the WM_NOTIFY function, but i cant make it work how i want expandcollapse popupGlobal $abreinci,$abremat,$abrefalta,$etidescipcio #include <GUIConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <GUIConstantsEx.au3> #include <GuiTreeView.au3> #include <GuiTab.au3> incidencia() func incidencia() Local $msg,$rs,$rs1,$li[16],$ci[16],$i,$error,$observacio,$codimat[1000],$codifalta[1000],$codiinci[1000],$fam,$parefalta,$pareinci,$paremat,$of,$material,$temp=0,$codi,$tab[5] Local $clikedfalta,$clikedinci,$clikedmat local $guiinci=GUICreate("incidencies:",500,550,@DesktopWidth/2-250,@DesktopHeight/2-300,bitor($GUI_SS_DEFAULT_GUI,$WS_VISIBLE)) GUISetBkColor(0xffcc99) local $butcancelar=GUICtrlCreateButton("Cancelar",10,485,100,55) Local $butmes =GUICtrlCreateButton("+",250-50-10,485,50,50) GUICtrlSetFont(-1,17) Local $butmenys =GUICtrlCreateButton("-",250+10,485,50,50) GUICtrlSetFont(-1,17) $etidescipcio=GUICtrlCreateInput("",10,450,480,25,0x0001) GUICtrlSetState(-1,$gui_disable) GUICtrlSetFont(-1,15) $tab[0]=GUICtrlCreateTab(10,10,480,430) GUICtrlSetFont(-1,15) $tab[1]=GUICtrlCreateTabItem("Incidencia") GUICtrlSetFont(-1,15) $abreinci=GUICtrlCreateTreeView(20,50,460,380,BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES), $WS_EX_CLIENTEDGE) GUICtrlSetFont(-1,14) $tab[2]=GUICtrlCreateTabItem("Incorrecte") $abremat=GUICtrlCreateTreeView(20,50,460,380,BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES), $WS_EX_CLIENTEDGE) GUICtrlSetFont(-1,14) $tab[3]=GUICtrlCreateTabItem("Falta") $abrefalta=GUICtrlCreateTreeView(20,50,460,380,BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES), $WS_EX_CLIENTEDGE) GUICtrlSetFont(-1,14) $tab[4]=GUICtrlCreateTabItem("Altres") $observacio=GUICtrlCreateInput("",20,50,460,380,0x0004) GUICtrlSetFont(-1,14) GUICtrlCreateTabItem("") _GUICtrlTab_SetCurFocus($tab[0],0) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") $i=0 while $i < 100 $fam=int($i/10) $parefalta=GUICtrlCreateTreeViewItem($fam&": text", $abrefalta) $pareinci =GUICtrlCreateTreeViewItem($fam&": text", $abreinci) $paremat =GUICtrlCreateTreeViewItem($fam&": text", $abremat) While $fam=int($i/10) $codiinci[$i] = GUICtrlCreateTreeViewItem("1x "&$i, $pareinci) $codifalta[$i]= GUICtrlCreateTreeViewItem("1x "&$i, $parefalta) $codimat[$i] = GUICtrlCreateTreeViewItem("1x "&$i, $paremat) $i=$i+5 WEnd WEnd $codifalta[0]=$i $codiinci[0]=$i $codimat[0]=$i While 1 $msg=GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE GUIDelete($guiinci) ExitLoop case $butcancelar GUIDelete($guiinci) ExitLoop EndSwitch WEnd EndFunc Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndabreinci,$hWndabremat,$hWndabrefalta,$temp Local $clikedinci,$codi,$rs $hWndabremat = $abremat $hWndabreinci = $abreinci $hWndabrefalta= $abrefalta If Not IsHWnd($abremat) Then $hWndabremat = GUICtrlGetHandle($abremat) If Not IsHWnd($abreinci) Then $hWndabreinci = GUICtrlGetHandle($abreinci) If Not IsHWnd($abrefalta) Then $hWndabrefalta = GUICtrlGetHandle($abrefalta) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom case $hWndabreinci Switch $iCode Case $NM_CLICK ; The user has clicked the left mouse button within the control if not StringInStr(_GUICtrlTreeView_GetText($abreinci,_GUICtrlTreeView_GetSelection($abreinci)),':') then $clikedinci=_GUICtrlTreeView_GetSelection($abreinci) $codi=_GUICtrlTreeView_GetText($abreinci,$clikedinci) GUICtrlSetData($etidescipcio,"u selected"&$codi) if _GUICtrlTreeView_GetChecked($abreinci, $clikedinci) Then _GUICtrlTreeView_SetChecked($abreinci, $clikedinci,False) Else _GUICtrlTreeView_SetChecked($abreinci, $clikedinci,true) EndIf EndIf Return 0 EndSwitch Case $hWndabremat Switch $iCode Case $NM_CLICK ; The user has clicked the left mouse button within the control Return 0 ; zero to allow the default processing EndSwitch case $hWndabrefalta Switch $iCode Case $NM_CLICK ; The user has clicked the left mouse button within the control Return 0 ; zero to allow the default processing EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc but for what i see this function it's pre-processed before the click, and it mark the last item instead the actual one I had to seek for info because I started to make a similar thing: expandcollapse popupGlobal $abreinci,$abremat,$abrefalta,$etidescipcio #include <GUIConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <GUIConstantsEx.au3> #include <GuiTreeView.au3> #include <GuiTab.au3> incidencia() func incidencia() Local $msg,$rs,$rs1,$li[16],$ci[16],$i,$error,$observacio,$codimat[1000],$codifalta[1000],$codiinci[1000],$fam,$parefalta,$pareinci,$paremat,$of,$material,$temp=0,$codi,$tab[5] Local $clikedfalta,$clikedinci,$clikedmat local $guiinci=GUICreate("incidencies:",500,550,@DesktopWidth/2-250,@DesktopHeight/2-300,bitor($GUI_SS_DEFAULT_GUI,$WS_VISIBLE)) GUISetBkColor(0xffcc99) local $butcancelar=GUICtrlCreateButton("Cancelar",10,485,100,55) Local $butmes =GUICtrlCreateButton("+",250-50-10,485,50,50) GUICtrlSetFont(-1,17) Local $butmenys =GUICtrlCreateButton("-",250+10,485,50,50) GUICtrlSetFont(-1,17) $etidescipcio=GUICtrlCreateInput("",10,450,480,25,0x0001) GUICtrlSetState(-1,$gui_disable) GUICtrlSetFont(-1,15) $tab[0]=GUICtrlCreateTab(10,10,480,430) GUICtrlSetFont(-1,15) $tab[1]=GUICtrlCreateTabItem("Incidencia") GUICtrlSetFont(-1,15) $abreinci=GUICtrlCreateTreeView(20,50,460,380,BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES), $WS_EX_CLIENTEDGE) GUICtrlSetFont(-1,14) $tab[2]=GUICtrlCreateTabItem("Incorrecte") $abremat=GUICtrlCreateTreeView(20,50,460,380,BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES), $WS_EX_CLIENTEDGE) GUICtrlSetFont(-1,14) $tab[3]=GUICtrlCreateTabItem("Falta") $abrefalta=GUICtrlCreateTreeView(20,50,460,380,BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES), $WS_EX_CLIENTEDGE) GUICtrlSetFont(-1,14) $tab[4]=GUICtrlCreateTabItem("Altres") $observacio=GUICtrlCreateInput("",20,50,460,380,0x0004) GUICtrlSetFont(-1,14) GUICtrlCreateTabItem("") _GUICtrlTab_SetCurFocus($tab[0],0) $i=0 while $i < 100 $fam=int($i/10) $parefalta=GUICtrlCreateTreeViewItem($fam&": text", $abrefalta) $pareinci =GUICtrlCreateTreeViewItem($fam&": text", $abreinci) $paremat =GUICtrlCreateTreeViewItem($fam&": text", $abremat) While $fam=int($i/10) $codiinci[$i] = GUICtrlCreateTreeViewItem("1x "&$i, $pareinci) $codifalta[$i]= GUICtrlCreateTreeViewItem("1x "&$i, $parefalta) $codimat[$i] = GUICtrlCreateTreeViewItem("1x "&$i, $paremat) $i=$i+5 WEnd WEnd $codifalta[0]=$i $codiinci[0]=$i $codimat[0]=$i While 1 $msg=GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE GUIDelete($guiinci) ExitLoop case $butcancelar GUIDelete($guiinci) ExitLoop case $butmes sleep(10) case $butmenys sleep(10) Case $NM_KILLFOCUS if _GUICtrlTab_GetCurFocus($tab[0])+1 =1 Then if not StringInStr(_GUICtrlTreeView_GetText($abreinci,_GUICtrlTreeView_GetSelection($abreinci)),':') then $clikedinci=_GUICtrlTreeView_GetSelection($abreinci) $codi=_GUICtrlTreeView_GetText($abreinci,$clikedinci) GUICtrlSetData($etidescipcio,"u selected"&$codi) if _GUICtrlTreeView_GetChecked($abreinci, $clikedinci) Then _GUICtrlTreeView_SetChecked($abreinci, $clikedinci,False) Else _GUICtrlTreeView_SetChecked($abreinci, $clikedinci,true) EndIf EndIf EndIf if _GUICtrlTab_GetCurFocus($tab[0])+1 =2 Then if not StringInStr(_GUICtrlTreeView_GetText($abremat,_GUICtrlTreeView_GetSelection($abremat)),':') then $clikedmat=_GUICtrlTreeView_GetSelection($abremat) $codi=_GUICtrlTreeView_GetText($abremat,$clikedmat) GUICtrlSetData($etidescipcio,"u selected"&$codi) if _GUICtrlTreeView_GetChecked($abremat, $clikedmat) Then _GUICtrlTreeView_SetChecked($abremat, $clikedmat,False) Else _GUICtrlTreeView_SetChecked($abremat, $clikedmat,true) EndIf EndIf EndIf if _GUICtrlTab_GetCurFocus($tab[0])+1 =3 Then if not StringInStr(_GUICtrlTreeView_GetText($abrefalta,_GUICtrlTreeView_GetSelection($abrefalta)),':') then $clikedfalta=_GUICtrlTreeView_GetSelection($abrefalta) $codi=_GUICtrlTreeView_GetText($abrefalta,$clikedfalta) GUICtrlSetData($etidescipcio,"u selected"&$codi) if _GUICtrlTreeView_GetChecked($abrefalta, $clikedfalta) Then _GUICtrlTreeView_SetChecked($abrefalta, $clikedfalta,False) Else _GUICtrlTreeView_SetChecked($abrefalta, $clikedfalta,true) EndIf EndIf EndIf EndSwitch WEnd EndFunc but the problem was that when i hit a button they not only do the button “case”, it do both, checking/unchecking the selected item on the tree well i dont have any ideas left so i come here to beg for some help XD Link to comment Share on other sites More sharing options...
DatMCEyeBall Posted October 22, 2013 Share Posted October 22, 2013 Help file example: http://www.autoitscript.com/autoit3/docs/libfunctions/_GUICtrlTreeView_Create.htm "Just be fred, all we gotta do, just be fred." -Vocaliod "That is a Hadouken. A KAMEHAMEHA would have taken him 13 days and 54 episodes to form." - Roden Hoxha @tabhooked Clock made of cursors ♣ Desktop Widgets ♣ Water Simulation Link to comment Share on other sites More sharing options...
Solution kylomas Posted October 23, 2013 Solution Share Posted October 23, 2013 sirWimelef, This seems to be what you want. Changed the notification to SELCHANGEDW. Have not looked at the checkbox problem as this may lead you to a solution for that. expandcollapse popupGlobal $abreinci,$abremat,$abrefalta,$etidescipcio #include <GUIConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <GUIConstantsEx.au3> #include <GuiTreeView.au3> #include <GuiTab.au3> incidencia() func incidencia() Local $msg,$rs,$rs1,$li[16],$ci[16],$i,$error,$observacio,$codimat[1000],$codifalta[1000],$codiinci[1000],$fam,$parefalta,$pareinci,$paremat,$of,$material,$temp=0,$codi,$tab[5] Local $clikedfalta,$clikedinci,$clikedmat local $guiinci=GUICreate("incidencies:",500,550,@DesktopWidth/2-250,@DesktopHeight/2-300,bitor($GUI_SS_DEFAULT_GUI,$WS_VISIBLE)) GUISetBkColor(0xffcc99) local $butcancelar=GUICtrlCreateButton("Cancelar",10,485,100,55) Local $butmes =GUICtrlCreateButton("+",250-50-10,485,50,50) GUICtrlSetFont(-1,17) Local $butmenys =GUICtrlCreateButton("-",250+10,485,50,50) GUICtrlSetFont(-1,17) $etidescipcio=GUICtrlCreateInput("",10,450,480,25,0x0001) GUICtrlSetState(-1,$gui_disable) GUICtrlSetFont(-1,15) $tab[0]=GUICtrlCreateTab(10,10,480,430) GUICtrlSetFont(-1,15) $tab[1]=GUICtrlCreateTabItem("Incidencia") GUICtrlSetFont(-1,15) $abreinci=GUICtrlCreateTreeView(20,50,460,380,BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES), $WS_EX_CLIENTEDGE) GUICtrlSetFont(-1,14) $tab[2]=GUICtrlCreateTabItem("Incorrecte") $abremat=GUICtrlCreateTreeView(20,50,460,380,BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES), $WS_EX_CLIENTEDGE) GUICtrlSetFont(-1,14) $tab[3]=GUICtrlCreateTabItem("Falta") $abrefalta=GUICtrlCreateTreeView(20,50,460,380,BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES), $WS_EX_CLIENTEDGE) GUICtrlSetFont(-1,14) $tab[4]=GUICtrlCreateTabItem("Altres") $observacio=GUICtrlCreateInput("",20,50,460,380,0x0004) GUICtrlSetFont(-1,14) GUICtrlCreateTabItem("") _GUICtrlTab_SetCurFocus($tab[0],0) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") $i=0 while $i < 100 $fam=int($i/10) $parefalta=GUICtrlCreateTreeViewItem($fam&": text", $abrefalta) $pareinci =GUICtrlCreateTreeViewItem($fam&": text", $abreinci) $paremat =GUICtrlCreateTreeViewItem($fam&": text", $abremat) While $fam=int($i/10) $codiinci[$i] = GUICtrlCreateTreeViewItem("1x "&$i, $pareinci) $codifalta[$i]= GUICtrlCreateTreeViewItem("1x "&$i, $parefalta) $codimat[$i] = GUICtrlCreateTreeViewItem("1x "&$i, $paremat) $i=$i+5 WEnd WEnd $codifalta[0]=$i $codiinci[0]=$i $codimat[0]=$i While 1 $msg=GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE GUIDelete($guiinci) ExitLoop case $butcancelar GUIDelete($guiinci) ExitLoop EndSwitch WEnd EndFunc Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndabreinci,$hWndabremat,$hWndabrefalta,$temp Local $clikedinci,$codi,$rs $hWndabremat = $abremat $hWndabreinci = $abreinci $hWndabrefalta= $abrefalta If Not IsHWnd($abremat) Then $hWndabremat = GUICtrlGetHandle($abremat) If Not IsHWnd($abreinci) Then $hWndabreinci = GUICtrlGetHandle($abreinci) If Not IsHWnd($abrefalta) Then $hWndabrefalta = GUICtrlGetHandle($abrefalta) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom case $hWndabreinci Switch $iCode Case $TVN_SELCHANGEDW ; <------- use the SELCHANGED notification if not StringInStr(_GUICtrlTreeView_GetText($abreinci,_GUICtrlTreeView_GetSelection($abreinci)),':') then $clikedinci=_GUICtrlTreeView_GetSelection($abreinci) $codi=_GUICtrlTreeView_GetText($abreinci,$clikedinci) GUICtrlSetData($etidescipcio,"u selected"&$codi) if _GUICtrlTreeView_GetChecked($abreinci, $clikedinci) Then _GUICtrlTreeView_SetChecked($abreinci, $clikedinci,False) Else _GUICtrlTreeView_SetChecked($abreinci, $clikedinci,true) EndIf EndIf Return 0 EndSwitch Case $hWndabremat Switch $iCode Case $NM_CLICK ; The user has clicked the left mouse button within the control Return 0 ; zero to allow the default processing EndSwitch case $hWndabrefalta Switch $iCode Case $NM_CLICK ; The user has clicked the left mouse button within the control Return 0 ; zero to allow the default processing EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
sirWimelef Posted October 23, 2013 Author Share Posted October 23, 2013 (edited) kylomas, these exactly what i was seeking, THX! from where you get that variable? it isn’t on the help files, there is somewhere where i can get all the valid triggers? DatMCEyeBall i reader it, and non of theme work for what i want, also with that function i cant hook the treeview to the tab and it hover over theme another question thas bugging me with this, there a way to use this function without using global variables? Edited October 23, 2013 by sirWimelef Link to comment Share on other sites More sharing options...
kylomas Posted October 23, 2013 Share Posted October 23, 2013 sirWimelef, from where you get that variable? it isn’t on the help files, there is somewhere where i can get all the valid triggers? These variables are call "notifications" and are documented in MSDN for each control. another question thas bugging me with this, there a way to use this function without using global variables? That depends on what you want to do. The notification function operates like all other funcitons with regard to variable scope. If you want to use a value from the notification funciton then you need to set a "global" variable to that value or pass it as a parameter. Lastly, the Help file covers definition and syntax, often with an accompanying example. It is not meant to cover all possible uses of the definition. I agree, however, that pointing you back at the Help file was useless as you had obviously been there and your issue was beyond it's scope. Good Luck, kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
sirWimelef Posted October 23, 2013 Author Share Posted October 23, 2013 thx for all now i have another "help file" to check before seek here XD if someone read this and don’t want too seek on msdn here is the link http://msdn.microsoft.com/en-us/library/windows/desktop/bb773169(v=vs.85).aspx for the second part, i hate global variables, they are "patches" on the code to make things work when i call the function with GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") in the help file say explicit that u can only call it with a max 4 predefined parameters so i cand send the 3 treeviews variables to it but well this work and I’m hapy with it XD Link to comment Share on other sites More sharing options...
kylomas Posted October 23, 2013 Share Posted October 23, 2013 sirWimelef, Don't confuse parameters required with "global" vars. The "message" routines (notiification, command, etc) have a strict calling convention. This does not mean that you cannot set a global var while in the function for use outside of the funciton. In fact, it is advised to exit these functions as soon as possible so as not to block script execution. Therefore you will often use a "switch" to indicate some sort of processing in the main part of the code (message loop, generally). they are "patches" on the code to make things work I'm not sure that I agree with this, this is simply a matter of variable scoping (my opinion only). kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill 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