Jump to content

Select a control?


Cyri
 Share

Recommended Posts

Is it possible for a user to click an AutoIT control and it highlights the entire control? For example, an input box. Instead of allowing the user to click in the input box I want it to highlight the entire input box control when they click over it. I'm guessing the only way to do this would be to change the color of the input box to something else to signify it has focus?

Edited by Cyri
Link to comment
Share on other sites

This selects the control ... and allows you to move it too!

#include<GuiConstants.au3>
#include<_ControlHover.au3>

Opt("MouseCoordMode", 2)

$Main_GUI = GuiCreate("DanGui", 400, 250)

$MoveMe = GuiCtrlCreateLabel("Move Me (Test)", 150, 70, 80, 20)
$OK_BUT = GuiCtrlCreateButton("OK", 70, 160, 80, 20)
$CANCEL_BUT = GuiCtrlCreateButton("CANCEL", 220, 160, 90, 20)
$Move_But = GUICtrlCreateButton("Unlock Controls", 150, 220)
$Allow_Move = 0
_ControlHover(2, "", $MoveMe)
_ControlHover(2, "", $OK_BUT)
_ControlHover(2, "", $CANCEL_BUT)

GuiSetState()

While 1
    $msg = GuiGetMsg()
    Select
        Case $msg = $OK_BUT
            If $Allow_Move = 0 Then
                MsgBox(0, "Title", "This button still works!")
            EndIf
        Case $msg = $CANCEL_BUT
            If $Allow_Move = 0 Then
                MsgBox(0, "Title", "This button still works!")
            EndIf
        Case $msg = $Move_But
            If $Allow_Move = 0 Then
                GUICtrlSetData(6, "Lock Controls")
                $Allow_Move = 1
            ElseIf $Allow_Move = 1 Then
                GUICtrlSetData(6, "Unlock Controls")
                $Allow_Move = 0
            EndIf
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
   
    ;If moving is enabled
   
    If $Allow_Move = 1 Then
       
        ;Check for a Hover
       
        $Over = _ControlHover(0, $Main_GUI)
        If $Over = 1 Then
            If @extended = $MoveMe Then
                GUICtrlSetBkColor(3, 0xFF0000)
            Else
                GUICtrlSetBkColor(3, 0xECE9D8)
            EndIf
            If @extended = $OK_BUT Then
                GUICtrlSetColor(4, 0xFF0000)
            Else
                GUICtrlSetColor(4, 0xECE9D8)
            EndIf
        EndIf
       
        ;Check for a Click
       
        $Click = _ControlHover(1, $Main_GUI)
        If $Click = 1 Then
            Select
                Case @extended = $MoveMe
                    MoveControl(3)
                Case @extended = $OK_BUT
                    MoveControl(4)
                Case @extended = $CANCEL_BUT
                    MoveControl(5)
            EndSelect
        EndIf
        $Check_Click = GUIGetCursorInfo()
        Select
            Case $Check_Click[4] = 3 And $Check_Click[3] = 1
                Text_Change(3)
            Case $Check_Click[4] = 4 And $Check_Click[3] = 1
                Text_Change(4)
            Case $Check_Click[4] = 5 And $Check_Click[3] = 1
                Text_Change(5)
        EndSelect
    EndIf
WEnd

;Text_Change ==> To rename a control in "Unlocked" mode when it is right-clicked on.

Func Text_Change($IDtoRename)
    $New_Name = InputBox("Label Change", "Input new text for this label:")
    If $New_Name = "" Then
        MsgBox(0, "ERROR!", "The entered text was invalid.  No changes have been made.")
    Else
        GUICtrlSetData($IDtoRename, $New_Name)
    EndIf
EndFunc

;MoveControl ==> When a control is clicked on in "Unlocked" mode.

Func MoveControl($IDtoMove)
    Do
        $Check_Click = GUIGetCursorInfo()
        $mousepos = MouseGetPos()
        GUICtrlSetPos($IDtoMove, $mousepos[0] - 40, $mousepos[1] - 10)
        Sleep(20)
    Until $Check_Click[2] = 0
EndFunc

8)

NEWHeader1.png

Link to comment
Share on other sites

Heh, very good Valuater! =]]

#include <Constants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

GUICreate('Test', 300, 100)

$Input1 = GUICtrlCreateInput('', 20, 20, 260, 25)
$Input2 = GUICtrlCreateInput('', 20, 55, 260, 25)
$hInput1 = GUICtrlGetHandle($Input1)
$hInput2 = GUICtrlGetHandle($Input2)

$hFunc = DllCallbackRegister('InputHandler', 'lparam', 'hwnd;uint;wparam;lparam')
$hOldFunc1 = _WinAPI_GetWindowLong($hInput1, $GWL_WNDPROC)
$hOldFunc2 = _WinAPI_GetWindowLong($hInput2, $GWL_WNDPROC)
_WinAPI_SetWindowLong($hInput1, $GWL_WNDPROC, DllCallbackGetPtr($hFunc))
_WinAPI_SetWindowLong($hInput2, $GWL_WNDPROC, DllCallbackGetPtr($hFunc))

GUISetState()

Do
    Sleep(20)
Until GUIGetMsg() = -3

GUIDelete()
DllCallbackFree($hFunc)


Func InputHandler($hWnd, $iMsg, $wParam, $lParam)
    Local $hOldFunc
    If $hWnd = $hInput1 Then
        $hOldFunc = $hOldFunc1
    Else
        $hOldFunc = $hOldFunc2
    EndIf
    
    If $iMsg = $WM_SETFOCUS Then
        GUICtrlSetBkColor(_WinAPI_GetDlgCtrlID($hWnd), 0xFF00FF)
        GUICtrlSetBkColor(_WinAPI_GetDlgCtrlID($wParam), 0xFFFFFF)
    EndIf

    Return _WinAPI_CallWindowProc($hOldFunc, $hWnd, $iMsg, $wParam, $lParam)
EndFunc

By subclassing it's control procedure.

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...