- Offizieller Beitrag
Ihr kennt ja sicher die Lösung um grauen Infotext in einem Input anzeigen zu lassen.
Der Nachteil war, dass dieses Input nicht den Fokus haben darf, damit dieser Text gezeigt wird.
Ich habe hier mal eine Lösung erstellt, die das umgeht.
Zwar hat das Input den Fokus nicht wirklich, aber optisch entsteht der Eindruck, als ob das Input den Fokus hat (das Caret blinkt am Inputanfang vor dem grauen Infotext). Der User muß auch nicht erst in das Input klicken, sondern kann sofort schreiben. Mit dem ersten geschriebenen Zeichen findet dann der Fokuswechsel zum tatsächlichen Input statt.
Falls der Inhalt des Input gelöscht wird, erscheint sofort wieder der graue Infotext.
Hier das Bsp. (die Befehlszeile in Run ist auf meinen Browser zugeschnitten, für die Darstellung der Funktionsweise aber nicht wichtig):
Edit: Der von Fresapore beschriebene Effekt sollte jetzt nicht mehr auftreten.
Spoiler anzeigen
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$hGui = GUICreate('Web Application', 300, 30);, @DesktopWidth-310, @DesktopHeight-60)
$cDummy = GUICtrlCreateInput('', 8, 6, 1 , 20)
$cIn = GUICtrlCreateInput('', 5, 5, 250, 20)
GUICtrlSendMsg($cIn, 0x1501, 0, "Bitte Web-Adresse oder Suchtext eingeben")
$btSearch = GUICtrlCreateButton('?', 255, 5, 20, 20)
$btLink = GUICtrlCreateButton('>', 275, 5, 20, 20)
GUISetState()
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
While 1
Switch GUIGetMsg()
Case -3
Exit
Case $btSearch
$s2Search = GUICtrlRead($cIn)
If $s2Search <> '' Then ShellExecute("http://www.google.de/search?q=" & $s2Search)
Case $btLink
$sLink = GUICtrlRead($cIn)
If $sLink <> '' Then Run('"C:\Program Files\K-Meleon1.6.0_Beta2_en-US\k-meleon.exe" ' & '"' & $sLink & '"')
EndSwitch
WEnd
Func WM_COMMAND($hWnd, $iMsg, $iwParam)
If BitShift($iwParam, 16) = 0x300 Then
If BitAND($iwParam, 0xFFFF) = $cDummy Then
GUICtrlSetData($cIn, GUICtrlRead($cDummy))
GUICtrlSetData($cDummy, '')
ControlFocus($hWnd, '', $cIn)
ElseIf GUICtrlRead($cIn) = '' Then
ControlFocus($hWnd, '', $cDummy)
EndIf
EndIf
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_COMMAND