rootx Posted May 24, 2016 Posted May 24, 2016 (edited) When I open the second GUI I lose focus and the list box does not change background, Why? THX expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIListView.au3> Global $bChanged = False,$hGUI2 $hGUI = GUICreate("Test", 500, 500) GUISetBkColor(0xE0FFFF) $Pic = GUICtrlCreatePic(@ScriptDir&"\1.jpg", 0, 0, 1024, 600) GUICtrlSetState(-1, $GUI_DISABLE) $Button1 = GUICtrlCreateButton("Button1", 5,250, 200, 50) $cLV = GUICtrlCreateListView("Column 1", 10, 10, 200, 200) $hLV = GUICtrlGetHandle($cLV) GUICtrlCreateListViewItem("Item " & 0, $cLV) GUICtrlCreateListViewItem("Item " & 1, $cLV) GUICtrlCreateListViewItem("Item " & 2, $cLV) GUISetState() GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") While 1 $aMsg = GUIGetMsg(1) Switch $aMsg[1] Case $hGUI Switch $aMsg[0] Case $GUI_EVENT_CLOSE ExitLoop GUIDelete($hGUI) case $Button1 _gui() EndSwitch Case $hGUI2 Switch $aMsg[0] Case $GUI_EVENT_CLOSE GUISetState(@SW_ENABLE,$hGUI) GUIDelete($hGUI2) EndSwitch If $bChanged Then $litem = _GUICtrlListView_GetSelectedIndices($hLV) ConsoleWrite($litem & @CRLF) $bChanged = False Switch $litem Case "0" GUICtrlSetImage($Pic, @ScriptDir&"\0.jpg") Case "1" GUICtrlSetImage($Pic, @ScriptDir&"\1.jpg") Case "2" GUICtrlSetImage($Pic, @ScriptDir&"\2.jpg") EndSwitch $bChanged = False EndIf EndSwitch WEnd Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $hWndListView = $hLV $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_CLICK $tStruct = DllStructCreate($tagNMITEMACTIVATE, $lParam) $Index = DllStructGetData($tStruct, "Index") Local $iItemText = _GUICtrlListView_GetItemText($cLV, DllStructGetData($tStruct, "Index"), 1) $item = StringSplit(_GUICtrlListView_GetItemTextString($cLV, $Index), '|') $item = $item[1] ConsoleWrite($item & @CRLF) $bChanged = True Case $LVN_KEYDOWN $tStruct = DllStructCreate($tagNMLVKEYDOWN, $lParam) $iKey = DllStructGetData($tStruct, "VKey") Switch $iKey Case 38, 40 $bChanged = True EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>_WM_NOTIFY Func _gui() $hGUI2 = GUICreate("Test", 100, 100) GUISetState(@SW_SHOW) GUISetState(@SW_DISABLE,$hGUI) EndFunc Edited May 25, 2016 by rootx
rootx Posted May 24, 2016 Author Posted May 24, 2016 (edited) THX, but I have not explained well my question.... 1.Run the script, if I select an item in the listview consequently the Gui the background changes 2. Click on the button and open the second gui and then close it 3. Now if you try to select the item on the listview the control background change no longer works. What happens to GUIRegisterMsg ($ WM_NOTIFY, "WM_NOTIFY") ? THX. PS. This way was suggested to me by Melba ("THX"), because before when I changed the background the listview will disappear Edited May 25, 2016 by rootx
LarsJ Posted May 25, 2016 Posted May 25, 2016 Place the "If $bChanged Then ... EndIf" block immediately above the "Case $hGUI2" line. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions
LarsJ Posted May 25, 2016 Posted May 25, 2016 It works for me: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIListView.au3> Global $bChanged = False,$hGUI2 $hGUI = GUICreate("Test", 500, 500) GUISetBkColor(0xE0FFFF) $Pic = GUICtrlCreatePic(@ScriptDir&"\1.jpg", 0, 0, 1024, 600) GUICtrlSetState(-1, $GUI_DISABLE) $Button1 = GUICtrlCreateButton("Button1", 5,250, 200, 50) $cLV = GUICtrlCreateListView("Column 1", 10, 10, 200, 200) $hLV = GUICtrlGetHandle($cLV) GUICtrlCreateListViewItem("Item " & 0, $cLV) GUICtrlCreateListViewItem("Item " & 1, $cLV) GUICtrlCreateListViewItem("Item " & 2, $cLV) GUISetState() GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") While 1 $aMsg = GUIGetMsg(1) Switch $aMsg[1] Case $hGUI Switch $aMsg[0] Case $GUI_EVENT_CLOSE ExitLoop GUIDelete($hGUI) case $Button1 _gui() EndSwitch If $bChanged Then $litem = _GUICtrlListView_GetSelectedIndices($hLV) ConsoleWrite($litem & @CRLF) $bChanged = False Switch $litem Case "0" GUICtrlSetImage($Pic, @ScriptDir&"\0.jpg") Case "1" GUICtrlSetImage($Pic, @ScriptDir&"\1.jpg") Case "2" GUICtrlSetImage($Pic, @ScriptDir&"\2.jpg") EndSwitch $bChanged = False EndIf Case $hGUI2 Switch $aMsg[0] Case $GUI_EVENT_CLOSE GUISetState(@SW_ENABLE,$hGUI) GUIDelete($hGUI2) EndSwitch EndSwitch WEnd Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $hWndListView = $hLV $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_CLICK $tStruct = DllStructCreate($tagNMITEMACTIVATE, $lParam) $Index = DllStructGetData($tStruct, "Index") Local $iItemText = _GUICtrlListView_GetItemText($cLV, DllStructGetData($tStruct, "Index"), 1) $item = StringSplit(_GUICtrlListView_GetItemTextString($cLV, $Index), '|') $item = $item[1] ConsoleWrite($item & @CRLF) $bChanged = True Case $LVN_KEYDOWN $tStruct = DllStructCreate($tagNMLVKEYDOWN, $lParam) $iKey = DllStructGetData($tStruct, "VKey") Switch $iKey Case 38, 40 $bChanged = True EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>_WM_NOTIFY Func _gui() $hGUI2 = GUICreate("Test", 100, 100) GUISetState(@SW_SHOW) GUISetState(@SW_DISABLE,$hGUI) EndFunc rootx 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions
rootx Posted May 25, 2016 Author Posted May 25, 2016 (edited) LarsJ Its not working correctly yet, $LVN_KEYDOWN It changes when I move the mouse. Edited May 25, 2016 by rootx
LarsJ Posted May 25, 2016 Posted May 25, 2016 I forgot the up/down arrows. I think I would do something like this. But there is still room for improvement. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIListView.au3> Global $bChanged = False,$hGUI2 $hGUI = GUICreate("Test", 500, 500) GUISetBkColor(0xE0FFFF) $Pic = GUICtrlCreatePic(@ScriptDir&"\1.jpg", 0, 0, 1024, 600) GUICtrlSetState(-1, $GUI_DISABLE) $Button1 = GUICtrlCreateButton("Button1", 5,250, 200, 50) $idLvEvent = GUICtrlCreateDummy() ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $cLV = GUICtrlCreateListView("Column 1", 10, 10, 200, 200) $hLV = GUICtrlGetHandle($cLV) GUICtrlCreateListViewItem("Item " & 0, $cLV) GUICtrlCreateListViewItem("Item " & 1, $cLV) GUICtrlCreateListViewItem("Item " & 2, $cLV) GUISetState() GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") While 1 $aMsg = GUIGetMsg(1) Switch $aMsg[1] Case $hGUI Switch $aMsg[0] Case $GUI_EVENT_CLOSE ExitLoop GUIDelete($hGUI) case $Button1 _gui() Case $idLvEvent ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $litem = _GUICtrlListView_GetSelectedIndices($hLV) ConsoleWrite($litem & @CRLF) Switch $litem Case "0" GUICtrlSetImage($Pic, @ScriptDir&"\0.jpg") Case "1" GUICtrlSetImage($Pic, @ScriptDir&"\1.jpg") Case "2" GUICtrlSetImage($Pic, @ScriptDir&"\2.jpg") EndSwitch EndSwitch Case $hGUI2 Switch $aMsg[0] Case $GUI_EVENT_CLOSE GUISetState(@SW_ENABLE,$hGUI) GUIDelete($hGUI2) EndSwitch EndSwitch WEnd Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local Static $item Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $hWndListView = $hLV $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $LVN_ITEMCHANGED Local $tNMListView = DllStructCreate( $tagNMLISTVIEW, $lParam ) Local $iNewState = DllStructGetData( $tNMListView, "NewState" ) If BitAND( $iNewState, $LVIS_FOCUSED ) Then Local $iLvItem = DllStructGetData( $tNMListView, "Item" ) $item = _GUICtrlListView_GetItemText( $hWndListView, $iLvItem, 0 ) EndIf Case $NM_CLICK ;$tStruct = DllStructCreate($tagNMITEMACTIVATE, $lParam) ;$Index = DllStructGetData($tStruct, "Index") ;Local $iItemText = _GUICtrlListView_GetItemText($cLV, DllStructGetData($tStruct, "Index"), 1) ;$item = StringSplit(_GUICtrlListView_GetItemTextString($cLV, $Index), '|') ;$item = $item[1] ConsoleWrite($item & @CRLF) GUICtrlSendToDummy( $idLvEvent ) Case $LVN_KEYDOWN $tStruct = DllStructCreate($tagNMLVKEYDOWN, $lParam) $iKey = DllStructGetData($tStruct, "VKey") Switch $iKey Case 38, 40 ConsoleWrite($item & @CRLF) GUICtrlSendToDummy( $idLvEvent ) EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>_WM_NOTIFY Func _gui() $hGUI2 = GUICreate("Test", 100, 100) GUISetState(@SW_SHOW) GUISetState(@SW_DISABLE,$hGUI) EndFunc rootx 1 Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions
AutoBert Posted May 25, 2016 Posted May 25, 2016 Make it this way: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIListView.au3> Global $bChanged = False, $hGUI2 $hGUI = GUICreate("Test", 500, 500) GUISetBkColor(0xE0FFFF) $Pic = GUICtrlCreatePic(@ScriptDir & "\1.jpg", 0, 0, 1024, 600) GUICtrlSetState(-1, $GUI_DISABLE) $Button1 = GUICtrlCreateButton("Button1", 5, 250, 200, 50) $cLV = GUICtrlCreateListView("Column 1", 10, 10, 200, 200) $hLV = GUICtrlGetHandle($cLV) GUICtrlCreateListViewItem("Item " & 0, $cLV) GUICtrlCreateListViewItem("Item " & 1, $cLV) GUICtrlCreateListViewItem("Item " & 2, $cLV) GUISetState() GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") While 1 If $bChanged Then $litem = _GUICtrlListView_GetSelectedIndices($hLV) ;ConsoleWrite('Loop: ' & $litem & @CRLF) $bChanged = False Switch $litem Case "0" GUICtrlSetImage($Pic, @ScriptDir & "\0.jpg") Case "1" GUICtrlSetImage($Pic, @ScriptDir & "\1.jpg") Case "2" GUICtrlSetImage($Pic, @ScriptDir & "\2.jpg") EndSwitch $bChanged = False EndIf $aMsg = GUIGetMsg(1) Switch $aMsg[1] Case $hGUI Switch $aMsg[0] Case $GUI_EVENT_CLOSE ExitLoop GUIDelete($hGUI) Case $Button1 _gui() EndSwitch Case $hGUI2 Switch $aMsg[0] Case $GUI_EVENT_CLOSE GUISetState(@SW_ENABLE, $hGUI) GUIDelete($hGUI2) EndSwitch EndSwitch WEnd Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $hWndListView = $hLV $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_CLICK $tStruct = DllStructCreate($tagNMITEMACTIVATE, $lParam) $Index = DllStructGetData($tStruct, "Index") Local $iItemText = _GUICtrlListView_GetItemText($cLV, DllStructGetData($tStruct, "Index"), 1) $item = StringSplit(_GUICtrlListView_GetItemTextString($cLV, $Index), '|') $item = $item[1] $bChanged = True ;ConsoleWrite('WM_Click: ' & $item & @TAB & $bChanged & @CRLF) Case $LVN_KEYDOWN $tStruct = DllStructCreate($tagNMLVKEYDOWN, $lParam) $iKey = DllStructGetData($tStruct, "VKey") Switch $iKey Case 38, 40 $bChanged = True ;ConsoleWrite('Keydown: ' & $iKey & @TAB & $bChanged & @CRLF) EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>_WM_NOTIFY Func _gui() $hGUI2 = GUICreate("Test", 100, 100) GUISetState(@SW_SHOW) GUISetState(@SW_DISABLE, $hGUI) EndFunc ;==>_gui rootx 1
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