Jump to content

Change input back ground color on focus


Wingens
 Share

Recommended Posts

Hi I am trying to create a GUI at wich turns the input field yellow when the cursor/focus is on it. So the users instandly sees where they are typing.

Right now I am stuck with this code, it get's the focus but it does not change the input background color.

Hope you guys can help me.

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <DateTimeConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <file.au3>
#include <array.au3>
#include <GuiListView.au3>
#include <Misc.au3>
#include <ColorConstants.au3>
#include <GUIComboBox.au3>

Global $VERSION = "2.0.0 | Build: 20819"

$INLOGGUI = GUICreate($VERSION & " - Inloggen", 332, 342, -1, -1, $WS_POPUPWINDOW)
    $BG = GUICtrlCreatePic(@ScriptDir & '\Images\LoginBG.BMP', 0, 0, 332, 342)
        $TITEL = GUICtrlCreateLabel("Inloggen", 0, 40, 332, 30, $ES_CENTER)
            GUICtrlSetFont(-1, 18, 800, 0, "Calibri")

        $LABELUSERNAME = GUICtrlCreateLabel("Gebruiker", 50, 150, 50, 17)
            $Combo1 = GUICtrlCreateCombo("Kies een medewerker...", 50, 167, 233, 25, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
        $LABELPASSW = GUICtrlCreateLabel("Wachtwoord:", 50, 210, 77, 17, 0)
            $PasswordEdit = GUICtrlCreateInput("", 50, 227, 233, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_PASSWORD))

        $VERSIONLABEL = GUICtrlCreateLabel("Versie: " & $VERSION, 8, 323)

        $hLabel = GUICtrlCreateLabel("", 0, 0, 332, 50, -1, $GUI_WS_EX_PARENTDRAG)

            GUICtrlSetState($BG, $GUI_DISABLE)
            GUICtrlSetBkColor($TITEL, $GUI_BKCOLOR_TRANSPARENT)
            GUICtrlSetBkColor($LABELUSERNAME, $GUI_BKCOLOR_TRANSPARENT)
            GUICtrlSetBkColor($LABELPASSW, $GUI_BKCOLOR_TRANSPARENT)
            GUICtrlSetBkColor($Combo1, $GUI_BKCOLOR_TRANSPARENT)
            GUICtrlSetBkColor($PasswordEdit, $GUI_BKCOLOR_TRANSPARENT)
            GUICtrlSetBkColor($VERSIONLABEL, $GUI_BKCOLOR_TRANSPARENT)
            GUICtrlSetBkColor($hLabel, $GUI_BKCOLOR_TRANSPARENT)

Local $hDLL = DllOpen("user32.dll")

GUISetState(@SW_SHOW)

While 1
    $Test = ControlGetFocus($VERSION & " - Inloggen")
IF $Test = "Edit1" Then
    GUICtrlSetBkColor($Combo1, $COLOR_YELLOW)
Else
    GUICtrlSetBkColor($Combo1, $COLOR_WHITE)
EndIf

$nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

 

Link to comment
Share on other sites

here something that would work way better :

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <DateTimeConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <file.au3>
#include <array.au3>
#include <GuiListView.au3>
#include <Misc.au3>
#include <ColorConstants.au3>
#include <GUIComboBox.au3>

Global $VERSION = "2.0.0 | Build: 20819"

Global $INLOGGUI = GUICreate($VERSION & " - Inloggen", 332, 342, -1, -1, $WS_POPUPWINDOW)
$TITEL = GUICtrlCreateLabel("Inloggen", 0, 40, 332, 30, $ES_CENTER)
GUICtrlSetFont(-1, 18, 800, 0, "Calibri")

$LABELUSERNAME = GUICtrlCreateLabel("Gebruiker", 50, 150, 50, 17)
$Combo1 = GUICtrlCreateCombo("Kies een medewerker...", 50, 167, 233, 25)
$LABELPASSW = GUICtrlCreateLabel("Wachtwoord:", 50, 210, 77, 17, 0)
$PasswordEdit = GUICtrlCreateInput("", 50, 227, 233, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_PASSWORD))

$VERSIONLABEL = GUICtrlCreateLabel("Versie: " & $VERSION, 8, 323)

Global $iIDPrev = 0

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

GUISetState(@SW_SHOW)

While 1
  $nMsg = GUIGetMsg()
  Switch $nMsg
    Case $GUI_EVENT_CLOSE
      Exit

  EndSwitch
WEnd

Func WM_COMMAND($hWnd, $iMsg, $wParam, $lParam)
  Local $hWndFrom, $iIDFrom, $iCode

  $hWndFrom = $lParam
  $iIDFrom = _WinAPI_LoWord($wParam)
  $iCode = _WinAPI_HiWord($wParam)

  If $iIDFrom <> $iIDPrev Then
    ; ConsoleWrite ($hWndFrom & "/" & $iIDFrom & "/" & $iCode & @CRLF)
    GUICtrlSetBkColor($iIDPrev, $COLOR_WHITE)
    GUICtrlSetBkColor($iIDFrom, $COLOR_YELLOW)
    _WinAPI_RedrawWindow($INLOGGUI)
    $iIDPrev = $iIDFrom
  EndIf

  Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_COMMAND

 

Link to comment
Share on other sites

You can do something like this here:

#include <ButtonConstants.au3>
#include <ComboConstants.au3>
#include <DateTimeConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <WinAPISysWin.au3>
#include <file.au3>
#include <array.au3>
#include <GuiListView.au3>
#include <Misc.au3>
#include <ColorConstants.au3>
#include <GUIComboBox.au3>

Global $VERSION = "2.0.0 | Build: 20819"

$INLOGGUI = GUICreate($VERSION & " - Inloggen", 332, 342, -1, -1, $WS_POPUPWINDOW)
$BG = GUICtrlCreatePic(@ScriptDir & '\Images\LoginBG.BMP', 0, 0, 332, 342)
$TITEL = GUICtrlCreateLabel("Inloggen", 0, 40, 332, 30, $ES_CENTER)
GUICtrlSetFont(-1, 18, 800, 0, "Calibri")

$LABELUSERNAME = GUICtrlCreateLabel("Gebruiker", 50, 150, 50, 17)
$Combo1 = GUICtrlCreateCombo("Kies een medewerker...", 50, 167, 233, 25, BitOR($CBS_DROPDOWNLIST, $WS_VSCROLL))
$LABELPASSW = GUICtrlCreateLabel("Wachtwoord:", 50, 210, 77, 17, 0)
$PasswordEdit = GUICtrlCreateInput("", 50, 227, 233, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_CENTER, $ES_PASSWORD))
$hPasswordEdit = GUICtrlGetHandle($PasswordEdit)
$VERSIONLABEL = GUICtrlCreateLabel("Versie: " & $VERSION, 8, 323)

$hLabel = GUICtrlCreateLabel("", 0, 0, 332, 50, -1, $GUI_WS_EX_PARENTDRAG)

GUICtrlSetState($BG, $GUI_DISABLE)
GUICtrlSetBkColor($TITEL, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetBkColor($LABELUSERNAME, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetBkColor($LABELPASSW, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetBkColor($Combo1, $GUI_BKCOLOR_TRANSPARENT)
;~ GUICtrlSetBkColor($PasswordEdit, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetBkColor($VERSIONLABEL, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetBkColor($hLabel, $GUI_BKCOLOR_TRANSPARENT)

GUISetState(@SW_SHOW)

Global $iColor = 0xFFFFFF

GUIRegisterMsg($WM_CTLCOLOREDIT, "WM_CTLCOLOREDIT")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

While 1
$nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

Func WM_CTLCOLOREDIT($hWnd, $iMsg, $wParam, $lParam)
    If $lParam = $hPasswordEdit Then
        _WinAPI_SetTextColor($wParam, 0x000000)
        _WinAPI_SetBkMode($wParam, $TRANSPARENT)
        Return _WinAPI_CreateSolidBrush($iColor)
    EndIf
    Return "GUI_RUNDEFMSG"
EndFunc

Func WM_COMMAND($hWnd, $iMsg, $lParam, $wParam)
    Switch $hWnd
        Case $INLOGGUI
            Switch _WinAPI_LoWord($lParam)
                Case $PasswordEdit
                    Switch _WinAPI_HiWord($lParam)
                        Case $EN_SETFOCUS
                            $iColor = 0x00FFFF
                        Case $EN_KILLFOCUS
                            $iColor = 0xFFFFFF
                    EndSwitch
            EndSwitch
    EndSwitch
    Return "GUI_RUNDEFMSG"
EndFunc

 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

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