Jump to content

control focus?


Recommended Posts

Hello all,

I've got a list, for simplicities sake, list 1 and list 2.

Now, i've got a question, when the user focuses on an item, in either list, I'd like to be able to use one button to manage it, so, the one list is in focus, and they click the delete button.

Is there a way to do this?

I seen controlfocus, but if the title ever changes, with some automation program managing my program or something, it will die.

Thanks,

~~TheCreator~~Visit http://tysdomain.com for personal software and website solutions.

Link to comment
Share on other sites

Hello all,

I've got a list, for simplicities sake, list 1 and list 2.

Now, i've got a question, when the user focuses on an item, in either list, I'd like to be able to use one button to manage it, so, the one list is in focus, and they click the delete button.

Is there a way to do this?

I seen controlfocus, but if the title ever changes, with some automation program managing my program or something, it will die.

Thanks,

You have a While/WEnd loop idling while the button is NOT clicked, right? Just have it keep track of the current focus in a separate variable. When the button hit happens, check that variable for the last list that was in focus.

:whistle:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

What do you mean have it keep track?

I don't know where they are moving, e.g, the user can move to something else, and the idling while loop won't catch it.

I mean:

Global $avRecentFocus[10]

; Build GUI here....
; $ListView_1 and $ListView_2 are the list view control IDs
; $DeleteButton is the delete button

While 1
    $CurrFocus = ControlGetFocus("WinTitle", "WinText")
    If $CurrFocus <> $avRecentFocus[0] Then
        For $n = 9 To 1 Step - 1
            $avRecentFocus[$n] = $avRecentFocus[$n - 1]
        Next
        $avRecentFocus[0] = $CurrFocus
    EndIf
    Sleep(20)
    
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $DeleteButton
            _ButtonHit()
    EndSwitch
WEnd

Func _ButtonHit()
    Local $i, $Focus = 0
    
    For $i = 0 To 9
        If $avRecentFocus[$i] = $ListView_1 Or $avRecentFocus[$i] = $ListView_2 Then
            $Focus = $avRecentFocus[$i]
            ExitLoop
        EndIf
    Next
    
    If $Focus Then
        MsgBox(64, "Result", "The most recent ListView with focus was ControlID: " & $Focus)
    Else
        MsgBox(16, "Error", "Neither ListView has recently had focus.")
    EndIf
EndFunc   ;==>_ButtonHit

The while loop keeps track of the last 10 controls that have had focus. When you get a button hit on your delete button, the function called finds the last ListView that had focus from that list.

:whistle:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Hello,

This is just a bit of my code.

Delete doesn't work btw. :whistle:

$msg=GuiGetMsg()
if ($msg==$del) then
$index=_GUICtrlListGetCaretIndex(ControlGetFocus("Startup manager"))
if ($index==$LB_ERR) then
continueLoop
endif
$program=_GUICtrlListGetText(ControlGetFocus("Startup manager"), $index)
$result=MsgBox(4+32, "Are you sure?", "Are you sure you want to remove "&$program&" from your startup items?"&@crlf&"Please note, this will delete it until a new instance is created.")
if ($result == 6) then
_GUICtrlListDeleteItem(ControlGetFocus("Startup manager"), $index)
EndIf

~~TheCreator~~Visit http://tysdomain.com for personal software and website solutions.

Link to comment
Share on other sites

I figured you were going to do that. I said in the origenal post that I didn't want to do that, mainly because if the title changes, via some automation, it's not stable, it will break the whole thing.

If you're ready to learn some deeper concepts, use window handles instead of "WinTitle", "WinText". Handles never change while the window still exists.

Read the help file for WinTitleMatchMode and WinGetHandle.

When working with your own GUI, just save the handle when you create your GUI, then use it in place of the "WinTitle" ("WinText" should always be defaulted "" if you are doing this):

$hGUI = GuiCreate("My GUI")

$CurrFocus = ControlGetFocus($hGUI, "")

:whistle:

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...