Jump to content

Listview lose focus [SOLVED]


Recommended Posts

When I open the second GUI I lose focus and the list box does not change background, Why? THX :)

 

#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

 

0.jpg

1.jpg

2.jpg

Edited by rootx
Link to comment
Share on other sites

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 by rootx
Link to comment
Share on other sites

Link to comment
Share on other sites

It works for me:

#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

 

Link to comment
Share on other sites

I forgot the up/down arrows. I think I would do something like this. But there is still room for improvement.

#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

 

Link to comment
Share on other sites

Make it this way:

#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

 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...