Jump to content
kklee69

When listview loses focus,the selected item,How to keep blue

Recommended Posts

kklee69

When LISTVIEW loses focus,the selected item will turn gray.

How can I change It . Let it continue to stay blue

Do not gray

5aba436369b91_A1.jpg.f3c38b5351225a2208c532b4d64a756b.jpg

 

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    Local $listview, $button, $item1, $item2, $item3, $msg

    GUICreate("LISTVIEW", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)

    $listview = GUICtrlCreateListView("NO1  |NO2|NO3  ", 10, 10, 200, 150);,$LVS_SORTDESCENDING)
    $button = GUICtrlCreateButton("BUTTON", 75, 170, 70, 20)
    $item1 = GUICtrlCreateListViewItem ("A1|A2|A3", $listview)
    $item2 = GUICtrlCreateListViewItem ("B1|B2|B3", $listview)
    $item3 = GUICtrlCreateListViewItem ("C1|C2|C3", $listview)
    $item4 = GUICtrlCreateListViewItem ("D1|D2|D3", $listview)
    $item5 = GUICtrlCreateListViewItem ("E1|E2|E3", $listview)
    GUICtrlCreateInput("", 20, 200, 150)
    GUISetState()


    Do
        $msg = GUIGetMsg()

        Select
            Case $msg = $button
                MsgBox(0, "", GUICtrlRead(GUICtrlRead($listview)), 2)
            Case $msg = $listview
                MsgBox(0, "", "" & GUICtrlGetState($listview), 2)
        EndSelect
    Until $msg = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

 

Share this post


Link to post
Share on other sites
Subz
Posted (edited)

Never could figure out a clean way to do this, so used the following hack:

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <ColorConstants.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>
Global $listview

Example()

Func Example()
    Local $button, $item1, $item2, $item3, $msg

    GUICreate("LISTVIEW", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)

    $listview = GUICtrlCreateListView("NO1  |NO2|NO3  ", 10, 10, 200, 150, $LVS_SINGLESEL, $LVS_EX_FULLROWSELECT)
    $button = GUICtrlCreateButton("BUTTON", 75, 170, 70, 20)
    $item1 = GUICtrlCreateListViewItem ("A1|A2|A3", $listview)
    $item2 = GUICtrlCreateListViewItem ("B1|B2|B3", $listview)
    $item3 = GUICtrlCreateListViewItem ("C1|C2|C3", $listview)
    $item4 = GUICtrlCreateListViewItem ("D1|D2|D3", $listview)
    $item5 = GUICtrlCreateListViewItem ("E1|E2|E3", $listview)
    GUICtrlCreateInput("", 20, 200, 150)
    GUISetState()

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    Do
        $msg = GUIGetMsg()

        Select
            Case $msg = $button
                MsgBox(0, "", GUICtrlRead(GUICtrlRead($listview)), 2)
            Case $msg = $listview
                MsgBox(0, "", "" & GUICtrlGetState($listview), 2)
        EndSelect
    Until $msg = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    ; Local $tBuffer
    $hWndListView = $listview
    If Not IsHWnd($listview) Then $hWndListView = GUICtrlGetHandle($listview)

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $iIDFrom
        Case $listview
            Switch $iCode
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    For $i = 0 To _GUICtrlListView_GetItemCount($listview)
                        _GUICtrlListView_SetItemDropHilited($listview, $i, False)
                    Next
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    _GUICtrlListView_SetItemDropHilited($listview, DllStructGetData($tInfo, "Index"))
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

Edited by Subz

Share this post


Link to post
Share on other sites
kklee69
9 minutes ago, Subz said:

Never could figure out a clean way to do this, so used the following hack:

 

Thank you for your reply

It's still turn grayed When I Click on Input BOX

 

Share this post


Link to post
Share on other sites
BrewManNH

Listviews, by design, work this way. The only way you could possibly get this to work is with an owner drawn listview. The standard listview can't work like this.

 


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites
Subz

Sorry you need to remove $LVS_SHOWSELALWAYS i.e.

$listview = GUICtrlCreateListView("NO1  |NO2|NO3  ", 10, 10, 200, 150, $LVS_SINGLESEL , $LVS_EX_FULLROWSELECT)

 

Share this post


Link to post
Share on other sites
kklee69
1 hour ago, Subz said:

Sorry you need to remove $LVS_SHOWSELALWAYS i.e.

$listview = GUICtrlCreateListView("NO1  |NO2|NO3  ", 10, 10, 200, 150, $LVS_SINGLESEL , $LVS_EX_FULLROWSELECT)

 

OK!!  it works very well

But it doesn't Work in multi-selection mode

After losing focus, only one item Keep blue

I still want to thank you for providing such good code

Share this post


Link to post
Share on other sites
LarsJ

This can be done by drawing selected back and fore colors with GDI functions in custom draw post paint stage:

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

Opt( "MustDeclareVars", 1 )

Global $idListView, $hListView

Example()

Func Example()
  GUICreate("Listview", 220, 250, 300, 200, -1, $WS_EX_ACCEPTFILES)

  $idListView = GUICtrlCreateListView("NO1  |NO2|NO3  ", 10, 10, 200, 150, $GUI_SS_DEFAULT_LISTVIEW-$LVS_SINGLESEL)
  GUICtrlCreateListViewItem ("A1|A2|A3", $idListView)
  GUICtrlCreateListViewItem ("B1|B2|B3", $idListView)
  GUICtrlCreateListViewItem ("C1|C2|C3", $idListView)
  GUICtrlCreateListViewItem ("D1|D2|D3", $idListView)
  GUICtrlCreateListViewItem ("E1|E2|E3", $idListView)
  $hListView = GUICtrlGetHandle( $idListView )

  Local $idButton = GUICtrlCreateButton("Button", 75, 170, 70, 20)
  GUICtrlCreateInput("", 20, 200, 150)

  GUISetState()
  GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

  While 1
    Switch GUIGetMsg()
      Case $idButton
        MsgBox(0, "", GUICtrlRead(GUICtrlRead($idListView)), 2)
      Case $idListView
        MsgBox(0, "", "" & GUICtrlGetState($idListView), 2)
      Case $GUI_EVENT_CLOSE
        ExitLoop
    EndSwitch
  WEnd
EndFunc

Func WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam )
  Static $hDC, $iItem, $hBrush = DllCall( "gdi32.dll", "handle", "CreateSolidBrush", "int", _WinAPI_GetSysColor( $COLOR_HIGHLIGHT ) )[0] ; Selected back color, _WinAPI_CreateSolidBrush
  Static $tRect = DllStructCreate( $tagRECT ), $pRect = DllStructGetPtr( $tRect ), $tLVitem = DllStructCreate( $tagLVITEM ), $pLVitem = DllStructGetPtr( $tLVitem ), $tBuffer = DllStructCreate( "wchar Text[4096]" ), $pBuffer = DllStructGetPtr( $tBuffer )
  Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
  Switch HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    Case $hListView
      Switch DllStructGetData($tNMHDR, "Code")
        Case $NM_CUSTOMDRAW
          Local $tNMLVCUSTOMDRAW = DllStructCreate( $tagNMLVCUSTOMDRAW, $lParam )
          Switch DllStructGetData( $tNMLVCUSTOMDRAW, "dwDrawStage" )
            Case $CDDS_PREPAINT                              ; Before the paint cycle begins
              $hDC = DllStructGetData( $tNMLVCUSTOMDRAW, "hdc" )                              ; Device context
              DllCall( "gdi32.dll", "int", "SetBkMode", "handle", $hDC, "int", $TRANSPARENT ) ; Transparent background, _WinAPI_SetBkMode
              Return $CDRF_NOTIFYITEMDRAW                    ; Notify the parent window before an item is painted

            Case $CDDS_ITEMPREPAINT                          ; Before an item is painted
              $iItem = DllStructGetData( $tNMLVCUSTOMDRAW, "dwItemSpec" ) ; Item index
              If GUICtrlSendMsg( $idListView, $LVM_GETITEMSTATE, $iItem, $LVIS_SELECTED ) Then _ ; Selected item?
                Return $CDRF_NOTIFYPOSTPAINT                 ; Custom drawing of selected items
              Return $CDRF_NEWFONT                           ; Default drawing of other items

            Case $CDDS_ITEMPOSTPAINT                         ; After an item has been painted
              DllCall( "gdi32.dll", "int", "SetTextColor", "handle", $hDC, "int",  0xFFFFFF ) ; Selected fore color, white, _WinAPI_SetTextColor
              ; For each subitem
              For $iSubItem = 0 To 2
                ; Subitem rectangle
                DllStructSetData( $tRect, "Top", $iSubItem )
                DllStructSetData( $tRect, "Left", $LVIR_LABEL )
                GUICtrlSendMsg( $idListView, $LVM_GETSUBITEMRECT, $iItem, $pRect )
                DllStructSetData( $tRect, "Left", DllStructGetData( $tRect, "Left" ) )

                ; Selected back color
                DllCall( "user32.dll", "int", "FillRect", "handle", $hDC, "struct*", $tRect, "handle", $hBrush ) ; _WinAPI_FillRect

                ; Left and top margin of subitem text
                DllStructSetData( $tRect, "Left", DllStructGetData( $tRect, "Left" ) + ( $iSubItem ? 6 : 2 ) )
                DllStructSetData( $tRect, "Top", DllStructGetData( $tRect, "Top" ) + 2 )

                ; Extract subitem text from listview
                DllStructSetData( $tLVitem, "Mask", $LVIF_TEXT )
                DllStructSetData( $tLVitem, "SubItem", $iSubItem )
                DllStructSetData( $tLVitem, "Text", $pBuffer )
                DllStructSetData( $tLVitem, "TextMax", 4096 )
                GUICtrlSendMsg( $idListView, $LVM_GETITEMTEXTW, $iItem, $pLVitem )

                ; Draw subitem text with selected fore color and selected text font (through the device context, $hDC)
                DllCall( "user32.dll", "int", "DrawTextW", "handle", $hDC, "wstr", DllStructGetData( $tBuffer, "Text" ), "int", -1, "struct*", $tRect, "uint", $DT_WORD_ELLIPSIS ) ; _WinAPI_DrawText
              Next
              Return $CDRF_NEWFONT                           ; $CDRF_NEWFONT must be returned after changing font or colors
          EndSwitch
      EndSwitch
  EndSwitch
  #forceref $hWnd, $iMsg, $wParam
EndFunc

 

Share this post


Link to post
Share on other sites
kklee69
Posted (edited)
17 hours ago, LarsJ said:

This can be done by drawing selected back and fore colors with GDI functions in custom draw post paint stage:

#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiListView.au3>

Opt( "MustDeclareVars", 1 )

Global $idListView, $hListView

Example()

Func Example()
  GUICreate("Listview", 220, 250, 300, 200, -1, $WS_EX_ACCEPTFILES)

  $idListView = GUICtrlCreateListView("NO1  |NO2|NO3  ", 10, 10, 200, 150, $GUI_SS_DEFAULT_LISTVIEW-$LVS_SINGLESEL)
  GUICtrlCreateListViewItem ("A1|A2|A3", $idListView)
  GUICtrlCreateListViewItem ("B1|B2|B3", $idListView)
  GUICtrlCreateListViewItem ("C1|C2|C3", $idListView)
  GUICtrlCreateListViewItem ("D1|D2|D3", $idListView)
  GUICtrlCreateListViewItem ("E1|E2|E3", $idListView)
  $hListView = GUICtrlGetHandle( $idListView )

  Local $idButton = GUICtrlCreateButton("Button", 75, 170, 70, 20)
  GUICtrlCreateInput("", 20, 200, 150)

  GUISetState()
  GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

  While 1
    Switch GUIGetMsg()
      Case $idButton
        MsgBox(0, "", GUICtrlRead(GUICtrlRead($idListView)), 2)
      Case $idListView
        MsgBox(0, "", "" & GUICtrlGetState($idListView), 2)
      Case $GUI_EVENT_CLOSE
        ExitLoop
    EndSwitch
  WEnd
EndFunc

Func WM_NOTIFY( $hWnd, $iMsg, $wParam, $lParam )
  Static $hDC, $iItem, $hBrush = DllCall( "gdi32.dll", "handle", "CreateSolidBrush", "int", _WinAPI_GetSysColor( $COLOR_HIGHLIGHT ) )[0] ; Selected back color, _WinAPI_CreateSolidBrush
  Static $tRect = DllStructCreate( $tagRECT ), $pRect = DllStructGetPtr( $tRect ), $tLVitem = DllStructCreate( $tagLVITEM ), $pLVitem = DllStructGetPtr( $tLVitem ), $tBuffer = DllStructCreate( "wchar Text[4096]" ), $pBuffer = DllStructGetPtr( $tBuffer )
  Local $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
  Switch HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    Case $hListView
      Switch DllStructGetData($tNMHDR, "Code")
        Case $NM_CUSTOMDRAW
          Local $tNMLVCUSTOMDRAW = DllStructCreate( $tagNMLVCUSTOMDRAW, $lParam )
          Switch DllStructGetData( $tNMLVCUSTOMDRAW, "dwDrawStage" )
            Case $CDDS_PREPAINT                              ; Before the paint cycle begins
              $hDC = DllStructGetData( $tNMLVCUSTOMDRAW, "hdc" )                              ; Device context
              DllCall( "gdi32.dll", "int", "SetBkMode", "handle", $hDC, "int", $TRANSPARENT ) ; Transparent background, _WinAPI_SetBkMode
              Return $CDRF_NOTIFYITEMDRAW                    ; Notify the parent window before an item is painted

            Case $CDDS_ITEMPREPAINT                          ; Before an item is painted
              $iItem = DllStructGetData( $tNMLVCUSTOMDRAW, "dwItemSpec" ) ; Item index
              If GUICtrlSendMsg( $idListView, $LVM_GETITEMSTATE, $iItem, $LVIS_SELECTED ) Then _ ; Selected item?
                Return $CDRF_NOTIFYPOSTPAINT                 ; Custom drawing of selected items
              Return $CDRF_NEWFONT                           ; Default drawing of other items

            Case $CDDS_ITEMPOSTPAINT                         ; After an item has been painted
              DllCall( "gdi32.dll", "int", "SetTextColor", "handle", $hDC, "int",  0xFFFFFF ) ; Selected fore color, white, _WinAPI_SetTextColor
              ; For each subitem
              For $iSubItem = 0 To 2
                ; Subitem rectangle
                DllStructSetData( $tRect, "Top", $iSubItem )
                DllStructSetData( $tRect, "Left", $LVIR_LABEL )
                GUICtrlSendMsg( $idListView, $LVM_GETSUBITEMRECT, $iItem, $pRect )
                DllStructSetData( $tRect, "Left", DllStructGetData( $tRect, "Left" ) )

                ; Selected back color
                DllCall( "user32.dll", "int", "FillRect", "handle", $hDC, "struct*", $tRect, "handle", $hBrush ) ; _WinAPI_FillRect

                ; Left and top margin of subitem text
                DllStructSetData( $tRect, "Left", DllStructGetData( $tRect, "Left" ) + ( $iSubItem ? 6 : 2 ) )
                DllStructSetData( $tRect, "Top", DllStructGetData( $tRect, "Top" ) + 2 )

                ; Extract subitem text from listview
                DllStructSetData( $tLVitem, "Mask", $LVIF_TEXT )
                DllStructSetData( $tLVitem, "SubItem", $iSubItem )
                DllStructSetData( $tLVitem, "Text", $pBuffer )
                DllStructSetData( $tLVitem, "TextMax", 4096 )
                GUICtrlSendMsg( $idListView, $LVM_GETITEMTEXTW, $iItem, $pLVitem )

                ; Draw subitem text with selected fore color and selected text font (through the device context, $hDC)
                DllCall( "user32.dll", "int", "DrawTextW", "handle", $hDC, "wstr", DllStructGetData( $tBuffer, "Text" ), "int", -1, "struct*", $tRect, "uint", $DT_WORD_ELLIPSIS ) ; _WinAPI_DrawText
              Next
              Return $CDRF_NEWFONT                           ; $CDRF_NEWFONT must be returned after changing font or colors
          EndSwitch
      EndSwitch
  EndSwitch
  #forceref $hWnd, $iMsg, $wParam
EndFunc

 

Thank you for your reply
It solved my problem
Thank you for your help

Edited by kklee69

Share this post


Link to post
Share on other sites
kklee69

I have asked questions in your Virtual ListViews forum !!
I don’t know if you have time to help me

Share this post


Link to post
Share on other sites
JLogan3o13

@kklee69 in the future please just hit reply rather than quoting every single response. We know what we said (we were there when we said it), and it pads the thread unnecessarily.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
kklee69

Ok, I understand
I am Chinese
Not used to the English version of the website
I will pay attention next time

Share this post


Link to post
Share on other sites
Subz

Just wanted to add Multi-Selection mode method using my method above, I had to use it this week in a script so thought I'd share the code.

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <ColorConstants.au3>
#include <GuiListView.au3>
#include <MsgBoxConstants.au3>

Global $listview

Example()

Func Example()
    Local $button, $item1, $item2, $item3, $msg

    GUICreate("LISTVIEW", 220, 250, 100, 200, -1, $WS_EX_ACCEPTFILES)

    $listview = GUICtrlCreateListView("NO1  |NO2|NO3  ", 10, 10, 200, 150)
    $button = GUICtrlCreateButton("BUTTON", 75, 170, 70, 20)
    $item1 = GUICtrlCreateListViewItem ("A1|A2|A3", $listview)
    $item2 = GUICtrlCreateListViewItem ("B1|B2|B3", $listview)
    $item3 = GUICtrlCreateListViewItem ("C1|C2|C3", $listview)
    $item4 = GUICtrlCreateListViewItem ("D1|D2|D3", $listview)
    $item5 = GUICtrlCreateListViewItem ("E1|E2|E3", $listview)
    GUICtrlCreateInput("", 20, 200, 150)
    GUISetState()

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

    Do
        $msg = GUIGetMsg()

        Select
            Case $msg = $button
                MsgBox(0, "", GUICtrlRead(GUICtrlRead($listview)), 2)
            Case $msg = $listview
                MsgBox(0, "", "" & GUICtrlGetState($listview), 2)
        EndSelect
    Until $msg = $GUI_EVENT_CLOSE
EndFunc   ;==>Example

Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
    #forceref $hWnd, $iMsg, $wParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo
    ; Local $tBuffer
    $hWndListView = $listview
    If Not IsHWnd($listview) Then $hWndListView = GUICtrlGetHandle($listview)

    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $iIDFrom
        Case $listview
            Switch $iCode
                    Case $LVN_ITEMCHANGED ; An item has changed
                    $tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
                    _GUICtrlListView_SetItemSelected($listview, DllStructGetData($tInfo, "Item"), False, False)
                Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
                    $tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    If _GUICtrlListView_GetItemDropHilited($listview, DllStructGetData($tInfo, "Index")) = True Then
                        _GUICtrlListView_SetItemDropHilited($listview, DllStructGetData($tInfo, "Index"), False)
                    Else
                        _GUICtrlListView_SetItemDropHilited($listview, DllStructGetData($tInfo, "Index"), True)
                    EndIf
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

 

Share this post


Link to post
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

  • Similar Content

    • nacerbaaziz
      By nacerbaaziz
      Hello
      I have an inquiry please
      when i use the control get focus
      it don't detect the menu item
      there are any Method to do that?
      i'll use that to make a custom screen reader in my program
      please help me to do that
      I am waiting for your answers
      greetings to you
      Thank you in advance
       
    • nacerbaaziz
      By nacerbaaziz
      Hello
      I designed this code To help the blind
      Where screen readers users can  Identify the sefocus  item with audio files
      In this code i define some elements
      Unfortunately, I did not know how to define the other elements
      I am waiting for your initiative to  define the other elements
      Thank you in advance
      Global $CFocus = "" Func focus($window) Local $focusing = ControlGetFocus($window) Local $handle = ControlGetHandle($window, "", $focusing) If Not ($focusing = $CFocus) Then Switch StringTrimRight($focusing, 1) Case "button" If IsCheckBox($handle) Then play("checkBox") ElseIf IsRadio($handle) Then play("RadioButton") Else play("focus") EndIf $CFocus = $focusing Case "comboBox", "ListBox" play("list") $CFocus = $focusing Case "edit", "input" play("edit") $CFocus = $focusing Case Else play("focus") $CFocus = $focusing EndSwitch EndIf EndFunc ;==>focus Func IsCheckBox($ctrl_hwnd) $Style = _WinAPI_GetWindowLong($ctrl_hwnd, $GWL_STYLE) Return BitAND($Style, $BS_CHECKBOX) = $BS_CHECKBOX EndFunc ;==>IsCheckBox Func IsRadio($ctrl_hwnd) $Style = _WinAPI_GetWindowLong($ctrl_hwnd, $GWL_STYLE) Return BitAND($Style, $BS_AUTORADIOBUTTON) = $BS_AUTORADIOBUTTON EndFunc ;==>IsRadio Func play($name, $wait = 0) Local Const $SND_RESOURCE = 0x00040004 Local Const $SND_ASYNC = 1 ; Play the file - the script will pause as it sounds If $wait = 0 Then DllCall("winmm.dll", "int", "PlaySound", "str", $name, "hwnd", 0, "int", BitOR($SND_RESOURCE, $SND_ASYNC)) Else DllCall("winmm.dll", "int", "PlaySound", "str", $name, "hwnd", 0, "int", $SND_RESOURCE) EndIf Return 1 EndFunc ;==>play  
    • Comboku
      By Comboku
      Hi Guys,
      i am working on a translation app. There are a couple of regular input fields with text that the user is supposed to change to a new language. 
      I want to change the color of the input field  as soon as the user leaves the input field. Is there a way to do that? 
      I know how to do this with a button, but i don't know how i can work with focus. Has any of you done something like this before?
       
      Thanks!
    • Trolleule
      By Trolleule
      Hi,
      iam not able to "activate" (the blue border of the edit control should be displayed) the created input control when clicking on a listview item. All i want is, when the edit control is created, it's active (blue border displayed) and you can directly write in it (cursor at the end), but i can't get it work. Can someone help?
      #include <GuiConstantsEx.au3> #include <GuiListView.au3> #include <GuiImageList.au3> #include <WindowsConstants.au3> #include <GuiEdit.au3> #include <Misc.au3> Global $Debug_LV = False ; Check ClassName being passed to ListView functions, set to True and use a handle to another control to see it work Global $bChanged = False, $hDLL = DllOpen("user32.dll") Global $aClick_Info[2] Global $hListView, $hTmp_Edit Global $GUI, $hImage $GUI = GUICreate("(UDF Created) ListView Create", 400, 300) $hListView = _GUICtrlListView_Create($GUI, "", 2, 2, 394, 268) _GUICtrlListView_SetExtendedListViewStyle($hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") ; Load images $hImage = _GUIImageList_Create() _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0xFF0000, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x00FF00, 16, 16)) _GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($hListView, 0x0000FF, 16, 16)) _GUICtrlListView_SetImageList($hListView, $hImage, 1) ; Add columns _GUICtrlListView_InsertColumn($hListView, 0, "Column 1", 100) _GUICtrlListView_InsertColumn($hListView, 1, "Column 2", 100) _GUICtrlListView_InsertColumn($hListView, 2, "Column 3", 100) ; Add items _GUICtrlListView_AddItem($hListView, "Row 1: Col 1", 0) _GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 2", 1) _GUICtrlListView_AddSubItem($hListView, 0, "Row 1: Col 3", 2) _GUICtrlListView_AddItem($hListView, "Row 2: Col 1", 1) _GUICtrlListView_AddSubItem($hListView, 1, "Row 2: Col 2", 1) _GUICtrlListView_AddItem($hListView, "Row 3: Col 1", 2) ; Loop until user exits Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo $hWndListView = $hListView If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndListView Switch $iCode Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button Local $iIndex, $iSubItem, $sTmp_Text, $aRect, $aPos $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) $iIndex = DllStructGetData($tInfo, "Index") $iSubItem = DllStructGetData($tInfo, "SubItem") ; make sure user clicks on the listview & only the activate If $iIndex <> -1 And Not $bChanged Then $bChanged = True Local $iTimer = TimerInit() Local $iCounter = 1 Local $DOUBLE_CLICK_TIME_DELTA = 1200 While 1 If _IsPressed("01", $hDLL) Then $iCounter+=1 ConsoleWrite("_IsPressed - clicked." & @CRLF) ; Wait until key is released. While _IsPressed("01", $hDLL) WEnd ConsoleWrite("counter: " & $iCounter & " timer: " & TimerDiff($iTimer) & @CRLF) EndIf If $iCounter = 2 And TimerDiff($iTimer) < $DOUBLE_CLICK_TIME_DELTA Then ConsoleWrite("yes." & @CRLF) ExitLoop EndIf If TimerDiff($iTimer) > $DOUBLE_CLICK_TIME_DELTA Then ConsoleWrite("over." & @CRLF) $bChanged = False Return 1 EndIf WEnd GUICtrlDelete($hTmp_Edit) $aClick_Info[0] = $iIndex $aClick_Info[1] = $iSubItem ;~ GUISetAccelerators($aAccelKeys) $sTmp_Text = _GUICtrlListView_GetItemText($hWndListView, $iIndex, $iSubItem) ConsoleWrite("item: " & $iIndex & " subitem: " & $iSubItem & " text: " & $sTmp_Text & @CRLF) If $iSubItem = 0 Then $aRect = _GUICtrlListView_GetItemRect($hWndListView, $iIndex, 2) Else $aRect = _GUICtrlListView_GetSubItemRect($hWndListView, $iIndex, $iSubItem) EndIf $aPos = ControlGetPos("", "", $hWndListView) ConsoleWrite("Information :" & StringFormat("Item 2 Rectangle : [%d, %d, %d, %d]", $aRect[0]+ $aPos[0], $aRect[1]+ $aPos[1], $aRect[2], $aRect[3]) & @CRLF) $hTmp_Edit = GUICtrlCreateEdit($sTmp_Text, $aRect[0] + $aPos[0], $aRect[1] + $aPos[1], $aRect[2] - $aRect[0], $aRect[3] - $aRect[1], 0) GUICtrlSetState($hTmp_Edit, $GUI_FOCUS+$GUI_SHOW+$Gui_ontop) _GUICtrlEdit_SetSel(GUICtrlGetHandle($hTmp_Edit), 2, 15) EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY  
    • tarretarretarre
      By tarretarretarre
      As the title states, is there a way to detect which inputbox is "selected"
      like: 
      if IsSelectedForWritingEtc($MyInputBox) then xxxx
      i was searching some without success, all my results were like how to read or and write to a inputbox. 
       
       
      /T
×