Textbox Focus ermitteln nicht möglich (Textbox transparent)

  • Hi,
    ic hab mal wieder ein Problem.
    Und zwar wollte ich ein kleines Menü machen mit transparenten Textfeldern und Buttons. klappt ja auch so weit, jetzt wollte ich aber prüfen ob eine der textboxen den Focus hat und dann den Text löschen der drinsteht.
    aber ich bekomm einfach nicht den Focus abgefragt.

    hab es versucht mit

    [autoit]

    If _IsFocused ($frmFinder, $txtUser) And $Clear = 0 Then
    GUICtrlSetData ($txtUser, "")
    $Clear = 1
    ElseIf $Clear = 1 And Not _IsFocused ($frmFinder, $txtUser) Then
    GUICtrlSetData($txtUser,"search User...")
    $Clear = 0
    EndIf

    [/autoit][autoit][/autoit][autoit]

    Func _IsFocused($hWnd, $nCID)
    Return ControlGetHandle($hWnd, '', $nCID) = ControlGetHandle($hWnd, '', ControlGetFocus($hWnd))
    EndFunc ;==>_IsFocused

    [/autoit]

    und nur mit

    [autoit]

    ControlGetFocus($hWnd))

    [/autoit]


    aber leider bekomm ich nix hin.

    vielleicht hat einer eine Idee?

    Zur Info so stell ich die transparens ein:

    [autoit]

    $txtLeo = GUICtrlCreateInput("search dictLeo...", 5, 154, 191, 21)
    _GuiCtrlMakeTrans(-1,175)

    [/autoit][autoit][/autoit][autoit]

    Func _GuiCtrlMakeTrans($iCtrlID,$iTrans=255)

    Local $pHwnd, $nHwnd, $aPos, $a

    $hWnd = GUICtrlGetHandle($iCtrlID);Get the control handle
    If $hWnd = 0 then Return SetError(1,1,0)
    $pHwnd = DllCall("User32.dll", "hwnd", "GetParent", "hwnd", $hWnd);Get the parent Gui Handle
    If $pHwnd[0] = 0 then Return SetError(1,2,0)
    $aPos = ControlGetPos($pHwnd[0],"",$hWnd);Get the current pos of the control
    If @error then Return SetError(1,3,0)
    $nHwnd = GUICreate("", $aPos[2], $aPos[3], $aPos[0], $aPos[1], 0x80000000, 0x00080000 + 0x00000040, $pHwnd[0]);greate a gui in the position of the control
    If $nHwnd = 0 then Return SetError(1,4,0)
    $a = DllCall("User32.dll", "hwnd", "SetParent", "hwnd", $hWnd, "hwnd", $nHwnd);change the parent of the control to the new gui
    If $a[0] = 0 then Return SetError(1,5,0)
    If NOT ControlMove($nHwnd,'',$hWnd,0,0) then Return SetError(1,6,-1);Move the control to 0,0 of the newly created child gui
    GUISetState(@SW_Show,$nHwnd);show the new child gui
    WinSetTrans($nHwnd,"",$iTrans);set the transparency
    If @error then Return SetError(1,7,0)
    GUISwitch($pHwnd[0]);switch back to the parent Gui

    Return $nHwnd;Return the handle for the new Child gui

    EndFunc

    [/autoit]

    mfg

    nefas

  • Spoiler anzeigen
    [autoit]

    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <GUIConstants.au3>
    #include <WindowsConstants.au3>
    #Include <WinAPI.au3>
    #include <IE.au3>
    #include <StaticConstants.au3>
    #include <Misc.au3>
    #include <Array.au3>
    #include <adfunctions.au3>
    #include <GUIListBox.au3>
    #Include <Constants.au3>

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    #Region ### START Koda GUI section ### Form=\\wetp030a\uid67481$o$\scripte\source\-=project=-\finder\gui\frmfinder_v2.kxf
    $frmFinder = GUICreate("Finder", 233, 183, -1, -1, BitOR($WS_POPUP,$WS_BORDER,$WS_CLIPSIBLINGS))
    WinSetTrans($frmFinder,"",1)
    $txtLeo = GUICtrlCreateInput("search dictLeo...", 5, 154, 191, 21)
    $txtLeo_Trans = _GuiCtrlMakeTrans(-1,175)
    $cmdLeo = GUICtrlCreateButton("(Not allowed)", 201, 149, 26, 26, BitOR($BS_FLAT,$BS_BITMAP))
    $cmdLeo_Trans = _GuiCtrlMakeTrans(-1,175)
    GUICtrlSetImage(-1, "", 0)
    $txtIntranet = GUICtrlCreateInput("search IntraNet...", 5, 130, 191, 21)
    $txtIntranet_Trans = _GuiCtrlMakeTrans(-1,175)
    $cmdIntranet = GUICtrlCreateButton("(Not allowed)", 201, 125, 26, 26, BitOR($BS_FLAT,$BS_BITMAP))
    $cmdIntranet_Trans = _GuiCtrlMakeTrans(-1,175)
    GUICtrlSetImage(-1, "", 0)
    $txtUser = GUICtrlCreateInput("search User...", 6, 105, 191, 21)
    $txtUser_Trans = _GuiCtrlMakeTrans(-1,175)
    $cmdUser = GUICtrlCreateButton("(Not allowed)", 201, 100, 26, 26, BitOR($BS_FLAT,$BS_BITMAP))
    $cmdUser_Trans = _GuiCtrlMakeTrans(-1,175)
    GUICtrlSetImage(-1, "", 0)
    $txtLocal = GUICtrlCreateInput("search Local...", 5, 80, 191, 21)
    _GuiCtrlMakeTrans(-1,175)
    $cmdLocal = GUICtrlCreateButton("(Not allowed)", 201, 75, 26, 26, BitOR($BS_FLAT,$BS_BITMAP))
    _GuiCtrlMakeTrans(-1,175)
    GUICtrlSetImage(-1, "", 0)
    $txtWiki = GUICtrlCreateInput("search Wiki...", 6, 55, 191, 21)
    _GuiCtrlMakeTrans(-1,175)
    $cmdWiki = GUICtrlCreateButton("(Not allowed)", 201, 50, 26, 26, BitOR($BS_FLAT,$BS_BITMAP))
    _GuiCtrlMakeTrans(-1,175)
    GUICtrlSetImage(-1, "", 0)
    $txtGoogle = GUICtrlCreateInput("search Google...", 5, 30, 191, 21)
    _GuiCtrlMakeTrans(-1,175)
    $cmdGoogle = GUICtrlCreateButton("(Not allowed)", 201, 25, 26, 26, BitOR($BS_FLAT,$BS_BITMAP))
    _GuiCtrlMakeTrans(-1,175)
    GUICtrlSetImage(-1, "", 0)
    GUICtrlSetResizing(-1, $GUI_DOCKAUTO)
    $Label1 = GUICtrlCreateLabel("", 0, 0, 222, 165,"",$GUI_WS_EX_PARENTDRAG)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    TraySetClick("9")
    ;$displayitem = TrayCreateItem("Anzeige")
    $exititem = TrayCreateItem("Beenden")
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    #Region ### Transparency ######################################################################################################

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; Function Name: _WinAPI_SetLayeredWindowAttributes
    ; Description:: Sets Layered Window Attributes:) See MSDN for more informaion
    ; Parameter(s):
    ; $hwnd - Handle of GUI to work on
    ; $i_transcolor - Transparent color
    ; $Transparency - Set Transparancy of GUI
    ; $isColorRef - If True, $i_transcolor is a COLORREF( 0x00bbggrr ), else an RGB-Color
    ; Requirement(s): Layered Windows
    ; Return Value(s): Success: 1
    ; Error: 0
    ; @error: 1 to 3 - Error from DllCall
    ; @error: 4 - Function did not succeed - use
    ; _WinAPI_GetLastErrorMessage or _WinAPI_GetLastError to get more information
    ; Author(s): Prog@ndy
    ;
    ; Link : @@MsdnLink@@ SetLayeredWindowAttributes
    ; Example : Yes
    ;===============================================================================
    ;
    Func _WinAPI_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $dwFlages = 0x03, $isColorRef = False)
    If $dwFlages = Default Or $dwFlages = "" Or $dwFlages < 0 Then $dwFlages = 0x03
    If Not $isColorRef Then
    $i_transcolor = Hex(String($i_transcolor), 6)
    $i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2))
    EndIf
    Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $dwFlages)
    Select
    Case @error
    Return SetError(@error, 0, 0)
    Case $Ret[0] = 0
    Return SetError(4, _WinAPI_GetLastError(), 0)
    Case Else
    Return 1
    EndSelect
    EndFunc ;==>_WinAPI_SetLayeredWindowAttributes

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _GuiCtrlMakeTrans($iCtrlID,$iTrans=255)

    Local $pHwnd, $nHwnd, $aPos, $a

    $hWnd = GUICtrlGetHandle($iCtrlID);Get the control handle
    If $hWnd = 0 then Return SetError(1,1,0)
    $pHwnd = DllCall("User32.dll", "hwnd", "GetParent", "hwnd", $hWnd);Get the parent Gui Handle
    If $pHwnd[0] = 0 then Return SetError(1,2,0)
    $aPos = ControlGetPos($pHwnd[0],"",$hWnd);Get the current pos of the control
    If @error then Return SetError(1,3,0)
    $nHwnd = GUICreate("", $aPos[2], $aPos[3], $aPos[0], $aPos[1], 0x80000000, 0x00080000 + 0x00000040, $pHwnd[0]);greate a gui in the position of the control
    If $nHwnd = 0 then Return SetError(1,4,0)
    $a = DllCall("User32.dll", "hwnd", "SetParent", "hwnd", $hWnd, "hwnd", $nHwnd);change the parent of the control to the new gui
    If $a[0] = 0 then Return SetError(1,5,0)
    If NOT ControlMove($nHwnd,'',$hWnd,0,0) then Return SetError(1,6,-1);Move the control to 0,0 of the newly created child gui
    GUISetState(@SW_Show,$nHwnd);show the new child gui
    WinSetTrans($nHwnd,"",$iTrans);set the transparency
    If @error then Return SetError(1,7,0)
    GUISwitch($pHwnd[0]);switch back to the parent Gui

    Return $nHwnd;Return the handle for the new Child gui

    EndFunc
    #EndRegion ### Transparency ###################################################################################################

    [/autoit]

    Ich hab allerdings die Pfade von den Grafiken für die Buttons rausgenommen, sollte aber ja der GUI keine einbusen bringen.

    ich hab auch die ganznén Funktionenrausgenommen da es teilweise interen pfade enthällt.

    Aber das hat ja auch keinen einfluss auf die GUI.

    Hoffe es hilft.

    mfg

    • Offizieller Beitrag

    Mit GUIRegisterMsg bekommst Du auch heraus, welches Input-Control gerade den Focus besitzt:

    Spoiler anzeigen
    [autoit]


    #include <ButtonConstants.au3>
    #include <EditConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <GUIConstants.au3>
    #include <WindowsConstants.au3>
    #Include <WinAPI.au3>
    #include <IE.au3>
    #include <StaticConstants.au3>
    #include <Misc.au3>
    #include <Array.au3>
    ;~ #include <adfunctions.au3>
    #include <GUIListBox.au3>
    #Include <Constants.au3>

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    #Region ### START Koda GUI section ### Form=\\wetp030a\uid67481$o$\scripte\source\-=project=-\finder\gui\frmfinder_v2.kxf
    $frmFinder = GUICreate("Finder", 233, 183, -1, -1, BitOR($WS_POPUP,$WS_BORDER,$WS_CLIPSIBLINGS))
    WinSetTrans($frmFinder,"",1)
    $txtLeo = GUICtrlCreateInput("search dictLeo...", 5, 154, 191, 21)
    $txtLeo_Trans = _GuiCtrlMakeTrans(-1,175)
    $cmdLeo = GUICtrlCreateButton("(Not allowed)", 201, 149, 26, 26, BitOR($BS_FLAT,$BS_BITMAP))
    $cmdLeo_Trans = _GuiCtrlMakeTrans(-1,175)
    GUICtrlSetImage(-1, "", 0)
    $txtIntranet = GUICtrlCreateInput("search IntraNet...", 5, 130, 191, 21)
    $txtIntranet_Trans = _GuiCtrlMakeTrans(-1,175)
    $cmdIntranet = GUICtrlCreateButton("(Not allowed)", 201, 125, 26, 26, BitOR($BS_FLAT,$BS_BITMAP))
    $cmdIntranet_Trans = _GuiCtrlMakeTrans(-1,175)
    GUICtrlSetImage(-1, "", 0)
    $txtUser = GUICtrlCreateInput("search User...", 6, 105, 191, 21)
    $txtUser_Trans = _GuiCtrlMakeTrans(-1,175)
    $cmdUser = GUICtrlCreateButton("(Not allowed)", 201, 100, 26, 26, BitOR($BS_FLAT,$BS_BITMAP))
    $cmdUser_Trans = _GuiCtrlMakeTrans(-1,175)
    GUICtrlSetImage(-1, "", 0)
    $txtLocal = GUICtrlCreateInput("search Local...", 5, 80, 191, 21)
    _GuiCtrlMakeTrans(-1,175)
    $cmdLocal = GUICtrlCreateButton("(Not allowed)", 201, 75, 26, 26, BitOR($BS_FLAT,$BS_BITMAP))
    _GuiCtrlMakeTrans(-1,175)
    GUICtrlSetImage(-1, "", 0)
    $txtWiki = GUICtrlCreateInput("search Wiki...", 6, 55, 191, 21)
    _GuiCtrlMakeTrans(-1,175)
    $cmdWiki = GUICtrlCreateButton("(Not allowed)", 201, 50, 26, 26, BitOR($BS_FLAT,$BS_BITMAP))
    _GuiCtrlMakeTrans(-1,175)
    GUICtrlSetImage(-1, "", 0)
    $txtGoogle = GUICtrlCreateInput("search Google...", 5, 30, 191, 21)
    _GuiCtrlMakeTrans(-1,175)
    $cmdGoogle = GUICtrlCreateButton("(Not allowed)", 201, 25, 26, 26, BitOR($BS_FLAT,$BS_BITMAP))
    _GuiCtrlMakeTrans(-1,175)
    GUICtrlSetImage(-1, "", 0)
    GUICtrlSetResizing(-1, $GUI_DOCKAUTO)
    $Label1 = GUICtrlCreateLabel("", 0, 0, 222, 165,"",$GUI_WS_EX_PARENTDRAG)
    GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
    GUICtrlCreateGroup("", -99, -99, 1, 1)
    TraySetClick("9")
    ;$displayitem = TrayCreateItem("Anzeige")
    $exititem = TrayCreateItem("Beenden")
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    [/autoit] [autoit][/autoit] [autoit]

    GUIRegisterMsg($WM_COMMAND, 'MY_WM_COMMAND')

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    WEnd

    [/autoit] [autoit][/autoit] [autoit]

    Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    Local $nID = BitAND($wParam, 0x0000FFFF)
    Switch $nID
    Case $txtLeo
    ToolTip('Leo')
    Case $txtIntranet
    ToolTip('Intranet')
    Case $txtUser
    ToolTip('User')
    Case $txtLocal
    ToolTip('Local')
    Case $txtWiki
    ToolTip('Wiki')
    Case $txtGoogle
    ToolTip('Google')
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>MY_WM_COMMAND

    [/autoit] [autoit][/autoit] [autoit]

    #Region ### Transparency ######################################################################################################

    [/autoit] [autoit][/autoit] [autoit]

    ;===============================================================================
    ;
    ; Function Name: _WinAPI_SetLayeredWindowAttributes
    ; Description:: Sets Layered Window Attributes:) See MSDN for more informaion
    ; Parameter(s):
    ; $hwnd - Handle of GUI to work on
    ; $i_transcolor - Transparent color
    ; $Transparency - Set Transparancy of GUI
    ; $isColorRef - If True, $i_transcolor is a COLORREF( 0x00bbggrr ), else an RGB-Color
    ; Requirement(s): Layered Windows
    ; Return Value(s): Success: 1
    ; Error: 0
    ; @error: 1 to 3 - Error from DllCall
    ; @error: 4 - Function did not succeed - use
    ; _WinAPI_GetLastErrorMessage or _WinAPI_GetLastError to get more information
    ; Author(s): Prog@ndy
    ;
    ; Link : @@MsdnLink@@ SetLayeredWindowAttributes
    ; Example : Yes
    ;===============================================================================
    ;
    Func _WinAPI_SetLayeredWindowAttributes($hwnd, $i_transcolor, $Transparency = 255, $dwFlages = 0x03, $isColorRef = False)
    If $dwFlages = Default Or $dwFlages = "" Or $dwFlages < 0 Then $dwFlages = 0x03
    If Not $isColorRef Then
    $i_transcolor = Hex(String($i_transcolor), 6)
    $i_transcolor = Execute('0x00' & StringMid($i_transcolor, 5, 2) & StringMid($i_transcolor, 3, 2) & StringMid($i_transcolor, 1, 2))
    EndIf
    Local $Ret = DllCall("user32.dll", "int", "SetLayeredWindowAttributes", "hwnd", $hwnd, "long", $i_transcolor, "byte", $Transparency, "long", $dwFlages)
    Select
    Case @error
    Return SetError(@error, 0, 0)
    Case $Ret[0] = 0
    Return SetError(4, _WinAPI_GetLastError(), 0)
    Case Else
    Return 1
    EndSelect
    EndFunc ;==>_WinAPI_SetLayeredWindowAttributes

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _GuiCtrlMakeTrans($iCtrlID,$iTrans=255)

    Local $pHwnd, $nHwnd, $aPos, $a

    $hWnd = GUICtrlGetHandle($iCtrlID);Get the control handle
    If $hWnd = 0 then Return SetError(1,1,0)
    $pHwnd = DllCall("User32.dll", "hwnd", "GetParent", "hwnd", $hWnd);Get the parent Gui Handle
    If $pHwnd[0] = 0 then Return SetError(1,2,0)
    $aPos = ControlGetPos($pHwnd[0],"",$hWnd);Get the current pos of the control
    If @error then Return SetError(1,3,0)
    $nHwnd = GUICreate("", $aPos[2], $aPos[3], $aPos[0], $aPos[1], 0x80000000, 0x00080000 + 0x00000040, $pHwnd[0]);greate a gui in the position of the control
    If $nHwnd = 0 then Return SetError(1,4,0)
    $a = DllCall("User32.dll", "hwnd", "SetParent", "hwnd", $hWnd, "hwnd", $nHwnd);change the parent of the control to the new gui
    If $a[0] = 0 then Return SetError(1,5,0)
    If NOT ControlMove($nHwnd,'',$hWnd,0,0) then Return SetError(1,6,-1);Move the control to 0,0 of the newly created child gui
    GUISetState(@SW_Show,$nHwnd);show the new child gui
    WinSetTrans($nHwnd,"",$iTrans);set the transparency
    If @error then Return SetError(1,7,0)
    GUISwitch($pHwnd[0]);switch back to the parent Gui

    Return $nHwnd;Return the handle for the new Child gui

    EndFunc

    [/autoit]
  • Danke Oscar, so klappt es :P

    Spoiler anzeigen
    [autoit]

    Func MY_WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    Local $nID = BitAND($wParam, 0x0000FFFF)
    Switch $nID
    Case $txtLeo
    if GuiCtrlRead($txtLeo) <> "" Then
    GuiCtrlSetData($txtLeo,"")
    Else
    GuiCtrlSetData($txtLeo,"search dictLeo...")
    EndIf
    Case $txtIntranet
    if GuiCtrlRead($txtIntranet) <> "" Then
    GuiCtrlSetData($txtIntranet,"")
    Else
    GuiCtrlSetData($txtIntranet,"search Intranet...")
    EndIf
    Case $txtUser
    if GuiCtrlRead($txtUser) <> "" Then
    GuiCtrlSetData($txtUser,"")
    Else
    GuiCtrlSetData($txtUser,"search User...")
    EndIf
    Case $txtLocal
    if GuiCtrlRead($txtLocal) <> "" Then
    GuiCtrlSetData($txtLocal,"")
    Else
    GuiCtrlSetData($txtLocal,"search Local...")
    EndIf
    Case $txtWiki
    if GuiCtrlRead($txtWiki) <> "" Then
    GuiCtrlSetData($txtWiki,"")
    Else
    GuiCtrlSetData($txtWiki,"search Wiki...")
    EndIf
    Case $txtGoogle
    if GuiCtrlRead($txtGoogle) <> "" Then
    GuiCtrlSetData($txtGoogle,"")
    Else
    GuiCtrlSetData($txtGoogle,"search Google...")
    EndIf
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>MY_WM_COMMAND

    [/autoit]

    Was aber komisch ist, das er mir immer so feld von Google leer macht wenn ich den Focus in einme anderen Feld hab ist der Focus im Feld von Google ist der Text da...