rollo5 Posted November 1, 2013 Share Posted November 1, 2013 (edited) Hello community! a strange problem - see my script. There are some inputboxes and a listview. If i write something to the first input and leave it through tab-key, the listview item should get the name of the input content. The problem is, it only changes its name, after I move the mouse. Why is this? regard, rollo expandcollapse popup#include <WinAPI.au3> #include <WindowsConstants.au3> #include <GuiScrollBars_Ex.au3> #include <GuiListView.au3> gui_create() ; Create dummy for tabulator key to activate $tabulator= GUICtrlCreateDummy() ; Set accelerator for tabulator Local $AccelKeys[1][2] $AccelKeys[0][0]="{tab}" $AccelKeys[0][1]=$tabulator GUISetAccelerators($AccelKeys) Global $input_for_listview_item_active=0 While 1 $nMsg = GUIGetMsg(1) Switch $nMsg[1] Case $hGUI1 Switch $nMsg[0] Case $GUI_EVENT_CLOSE Exit Case $tabulator $focus_handle=_WinAPI_GetFocus() $focus_id = _WinAPI_GetDlgCtrlID($focus_handle) for $1=1 to UBound($input_id_array,1)-2 if $focus_id=$input_id_array[$1] Then _WinAPI_SetFocus(ControlGetHandle("", "", $input_id_array[$1+1])) EndIf Next case Else $active_id=_WinAPI_GetDlgCtrlID(ControlGetHandle($hGUI1, '', ControlGetFocus($hGUI1))) if $active_id=$input_id_array[1] Then $input_for_listview_item_active=1 EndIf if $input_for_listview_item_active=1 and $active_id<>$input_id_array[1] Then $item1_name=GUICtrlRead($input_id_array[1]) _GUICtrlListView_SetItemText($listview, 0, $item1_name) $input_for_listview_item_active=0 EndIf EndSwitch EndSwitch WEnd Func gui_create() Global $gui_width=400 Global $gui_heigt=300 Global $hGUI1=GUICreate("gui",$gui_width,$gui_heigt,0,0) GUISetState(@SW_SHOW, $hGui1) GUISwitch($hGUI1) $listview_width=100 $listview_heigth=$gui_heigt-10-10 Global $listview = GUICtrlCreateListView("items ", 10, 10,$listview_width , $listview_heigth);,$LVS_SORTDESCENDING) GUICtrlSetState(-1, $GUI_DROPACCEPTED) ; to allow drag and dropping GUISetState() Global $item1_name="no_name" Global $item1 = GUICtrlCreateListViewItem($item1_name, $listview) GUISwitch($hGUI1) Global $child1_width=$gui_width-$listview_width-10-10-10 $h_cGUI_left_pos=$listview_width+10+10 $h_cGUI_top_pos=10 $h_cGUI_height=$gui_heigt-10-10 Global $h_cGUI = GUICreate("Child GUI", $child1_width, $h_cGUI_height, $h_cGUI_left_pos, $h_cGUI_top_pos,BitOR($WS_CHILD, $WS_EX_TOPMOST, $WS_TABSTOP),$WS_EX_WINDOWEDGE, $hGUI1) ;BitOR($WS_CHILD, $WS_TABSTOP, $WS_EX_TOPMOST, $WS_EX_WINDOWEDGE),$hGUI1 ) GUISetBkColor(0xF5F5F5,$h_cGUI) _GUIScrollbars_Generate($h_cGUI, 0, 200) GUISetState(@SW_SHOW,$h_cGUI) Global $input_id_array[1] $input_id_array[0]="input_id_array" GUISwitch($h_cGUI) $vertical_space=30 for $i=0 to 5 $input_id=GUICtrlCreateInput("",10,10+$i*$vertical_space,$child1_width-10-10-16,25,$WS_TABSTOP) _arrayadd($input_id_array,$input_id) Next GUISwitch($hGUI1) GUICtrlSetState($hGUI1,$GUI_FOCUS) EndFunc Edited November 1, 2013 by rollo5 Link to comment Share on other sites More sharing options...
Solution mikell Posted November 1, 2013 Solution Share Posted November 1, 2013 Like this maybe Case $tabulator $focus_handle=_WinAPI_GetFocus() $focus_id = _WinAPI_GetDlgCtrlID($focus_handle) $item1_name=GUICtrlRead($focus_id) _GUICtrlListView_SetItemText($listview, 0, $item1_name) for $i=1 to UBound($input_id_array,1)-2 if $focus_id=$input_id_array[$i] Then _WinAPI_SetFocus(ControlGetHandle("", "", $input_id_array[$i+1])) EndIf Next ? Link to comment Share on other sites More sharing options...
rollo5 Posted November 1, 2013 Author Share Posted November 1, 2013 (edited) Thank you Polymath, there was still the problem, that the item name was only updated, after the mouse was moved. With your help I changed the "Case $tabulator" AND "case else" statements. Now it works! expandcollapse popup#include <WinAPI.au3> #include <WindowsConstants.au3> #include <GuiScrollBars_Ex.au3> #include <GuiListView.au3> gui_create() ; Create dummy for tabulator key to activate $tabulator= GUICtrlCreateDummy() ; Set accelerator for tabulator Local $AccelKeys[1][2] $AccelKeys[0][0]="{tab}" $AccelKeys[0][1]=$tabulator GUISetAccelerators($AccelKeys) Global $input_for_listview_item_active=0 While 1 $nMsg = GUIGetMsg(1) Switch $nMsg[1] Case $hGUI1 Switch $nMsg[0] Case $GUI_EVENT_CLOSE Exit case $tabulator $focus_handle=_WinAPI_GetFocus() $focus_id = _WinAPI_GetDlgCtrlID($focus_handle) if GUICtrlRead($input_id_array[1])="" Then _GUICtrlListView_SetItemText($listview,0, "no_name") Else $item1_name=GUICtrlRead($input_id_array[1]) _GUICtrlListView_SetItemText($listview, 0, $item1_name) EndIf for $i=1 to UBound($input_id_array,1)-2 if $focus_id=$input_id_array[$i] Then _WinAPI_SetFocus(ControlGetHandle("", "", $input_id_array[$i+1])) EndIf Next case Else $active_id=_WinAPI_GetDlgCtrlID(ControlGetHandle($hGUI1, '', ControlGetFocus($hGUI1))) if $active_id=$input_id_array[1] Then $input_for_listview_item_active=1 EndIf if $input_for_listview_item_active=1 and $active_id<>$input_id_array[1] Then $item1_name=GUICtrlRead($input_id_array[1]) _GUICtrlListView_SetItemText($listview, 0, $item1_name) $input_for_listview_item_active=0 EndIf if GUICtrlRead($input_id_array[1])="" Then _GUICtrlListView_SetItemText($listview,0, "no_name") EndIf EndSwitch EndSwitch WEnd Func gui_create() Global $gui_width=400 Global $gui_heigt=300 Global $hGUI1=GUICreate("gui",$gui_width,$gui_heigt,0,0) GUISetState(@SW_SHOW, $hGui1) GUISwitch($hGUI1) $listview_width=100 $listview_heigth=$gui_heigt-10-10 Global $listview = GUICtrlCreateListView("items ", 10, 10,$listview_width , $listview_heigth);,$LVS_SORTDESCENDING) GUICtrlSetState(-1, $GUI_DROPACCEPTED) ; to allow drag and dropping GUISetState() Global $item1_name="no_name" Global $item1 = GUICtrlCreateListViewItem($item1_name, $listview) GUISwitch($hGUI1) Global $child1_width=$gui_width-$listview_width-10-10-10 $h_cGUI_left_pos=$listview_width+10+10 $h_cGUI_top_pos=10 $h_cGUI_height=$gui_heigt-10-10 Global $h_cGUI = GUICreate("Child GUI", $child1_width, $h_cGUI_height, $h_cGUI_left_pos, $h_cGUI_top_pos,BitOR($WS_CHILD, $WS_EX_TOPMOST, $WS_TABSTOP),$WS_EX_WINDOWEDGE, $hGUI1) ;BitOR($WS_CHILD, $WS_TABSTOP, $WS_EX_TOPMOST, $WS_EX_WINDOWEDGE),$hGUI1 ) GUISetBkColor(0xF5F5F5,$h_cGUI) _GUIScrollbars_Generate($h_cGUI, 0, 200) GUISetState(@SW_SHOW,$h_cGUI) Global $input_id_array[1] $input_id_array[0]="input_id_array" GUISwitch($h_cGUI) $vertical_space=30 for $i=0 to 5 $input_id=GUICtrlCreateInput("",10,10+$i*$vertical_space,$child1_width-10-10-16,25,$WS_TABSTOP) _arrayadd($input_id_array,$input_id) Next GUISwitch($hGUI1) GUICtrlSetState($hGUI1,$GUI_FOCUS) EndFunc Edited November 1, 2013 by rollo5 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