PDA

Показать полную графическую версию : [решено] GUICtrlCreateInput - маленький вопрос


Centrinar
02-07-2010, 13:15
GUICtrlCreateInput("Модель:", 190, 250, 260, 25) какможно сделать что бы при нажатии на строку ввода, слово "Модель:" пропадало

Creat0R
02-07-2010, 13:32
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>

GUICreate("Input Focus Demo", 500, 300)

$Input = GUICtrlCreateInput("Модель:", 190, 250, 260, 25)
$Exit = GUICtrlCreateButton("Exit", 20, 100, 60, 20)
GUICtrlSetState(-1, $GUI_FOCUS)

GUISetState()
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

While 1
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE, $Exit
ExitLoop
EndSwitch
WEnd

Func WM_COMMAND($hWnd, $nMsg, $wParam, $lParam)
Local $nNotifyCode = BitShift($wParam, 16)
Local $nID = BitAND($wParam, 0xFFFF)

Switch $nID
Case $Input
Switch $nNotifyCode
Case $EN_SETFOCUS
If GUICtrlRead($Input) = "Модель:" Then
GUICtrlSetData($Input, "")
EndIf
EndSwitch
EndSwitch

Return $GUI_RUNDEFMSG
EndFunc

А вообще если я правильно понял, то тебе будет интересно это (http://www.autoitscript.com/forum/index.php?showtopic=106799).
#include <GUIConstantsEx.au3>
#include <EditConstants.au3>
#include <WindowsConstants.au3>

GUICreate("_GUICtrlEdit_SetDefault")

Global $EDIT_DEF_ITEMS[1][2] = [[0, 0]]

$nEdit1 = GUICtrlCreateInput("", 5, 5, 100, 20)
_GUICtrlEdit_SetDefault($nEdit1, "This is the test", 0xFFC1C1, 0x0000FF)

$nEdit2 = GUICtrlCreateInput("", 5, 30, 100, 20)
_GUICtrlEdit_SetDefault($nEdit2, "Take 2.", 0x989898)

GUICtrlCreateInput("Just a standard input", 5, 55, 200, 20)
GUICtrlSetState(-1, $GUI_FOCUS)

GUISetState()

While GUIGetMsg() <> -3
WEnd

Func _GUICtrlEdit_SetDefault($hEdit, $sDefText, $nDefColor = 0x989898, $nTextColor = 0x000000)
If $hEdit = 0 Then
Return SetError(1, 0, 0)
EndIf

If $EDIT_DEF_ITEMS[0][0] = 0 Then
GUIRegisterMsg($WM_COMMAND, "__EDIT_DEF_WM_COMMAND")
EndIf

If GUICtrlRead($hEdit) = "" Then
GUICtrlSetColor($hEdit, $nDefColor)
GUICtrlSetData($hEdit, $sDefText)
EndIf

$EDIT_DEF_ITEMS[0][0] += 1
ReDim $EDIT_DEF_ITEMS[$EDIT_DEF_ITEMS[0][0] + 1][4]

$EDIT_DEF_ITEMS[$EDIT_DEF_ITEMS[0][0]][0] = $hEdit
$EDIT_DEF_ITEMS[$EDIT_DEF_ITEMS[0][0]][1] = $sDefText
$EDIT_DEF_ITEMS[$EDIT_DEF_ITEMS[0][0]][2] = $nDefColor
$EDIT_DEF_ITEMS[$EDIT_DEF_ITEMS[0][0]][3] = $nTextColor

Return 1
EndFunc ;==>_GUICtrlEdit_SetDefault

Func __EDIT_DEF_WM_COMMAND($hWnd, $msgID, $wParam, $lParam)
Local $n = __EDIT_DEF_GETINDEX(BitAND($wParam, 0xFFFF))

If $n = -1 Then
Return $GUI_RUNDEFMSG
EndIf

Local $nMsg = BitShift($wParam, 16)

If $nMsg = $EN_SETFOCUS Then ; Gained focus (EN_SETFOCUS)
If (GUICtrlRead($EDIT_DEF_ITEMS[$n][0]) == $EDIT_DEF_ITEMS[$n][1]) Then
GUICtrlSetColor($EDIT_DEF_ITEMS[$n][0], $EDIT_DEF_ITEMS[$n][3])
GUICtrlSetData($EDIT_DEF_ITEMS[$n][0], "")
EndIf
ElseIf $nMsg = $EN_KILLFOCUS Then ; Lost Focus (EN_KILLFOCUS)
If GUICtrlRead($EDIT_DEF_ITEMS[$n][0]) = "" Then
GUICtrlSetColor($EDIT_DEF_ITEMS[$n][0], $EDIT_DEF_ITEMS[$n][2])
GUICtrlSetData($EDIT_DEF_ITEMS[$n][0], $EDIT_DEF_ITEMS[$n][1])
EndIf
EndIf
EndFunc ;==>__EDIT_DEF_WM_COMMAND

Func __EDIT_DEF_GETINDEX($hEdit)
For $i = 1 To UBound($EDIT_DEF_ITEMS) - 1
If $EDIT_DEF_ITEMS[$i][0] = $hEdit Then
Return $i
EndIf
Next

Return -1
EndFunc ;==>__EDIT_DEF_GETINDEX

madmasles
02-07-2010, 14:45
У меня так работает:#include (http://www.autoitscript.com/autoit3/docs/keywords.htm##include) <GUIConstantsEx.au3>

$iCheck = 1
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate (http://www.autoitscript.com/autoit3/docs/functions/GUICreate.htm)("Form1", 200, 100, -1, -1)
$Input1 = GUICtrlCreateInput (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateInput.htm)("Input1", 10, 15, 180, 20)
$Input2 = GUICtrlCreateInput (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlCreateInput.htm)("Input2", 10, 45, 180, 20)
GUICtrlSetState (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetState.htm)(-1, $GUI_FOCUS)
GUISetState (http://www.autoitscript.com/autoit3/docs/functions/GUISetState.htm)(@SW_SHOW (http://www.autoitscript.com/autoit3/docs/macros.htm#@sw_show))
#endregion ### END Koda GUI section ###
While (http://www.autoitscript.com/autoit3/docs/keywords.htm#While) 1
$nMsg = GUIGetMsg (http://www.autoitscript.com/autoit3/docs/functions/GUIGetMsg.htm)()
Switch (http://www.autoitscript.com/autoit3/docs/keywords.htm#Switch) $nMsg
Case (http://www.autoitscript.com/autoit3/docs/keywords.htm#Case) $GUI_EVENT_CLOSE
Exit (http://www.autoitscript.com/autoit3/docs/keywords.htm#Exit)
EndSwitch (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndSwitch)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) $iCheck Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
If (http://www.autoitscript.com/autoit3/docs/keywords.htm#If) ControlGetFocus (http://www.autoitscript.com/autoit3/docs/functions/ControlGetFocus.htm)($Form1) = 'Edit1' Then (http://www.autoitscript.com/autoit3/docs/keywords.htm#Then)
GUICtrlSetData (http://www.autoitscript.com/autoit3/docs/functions/GUICtrlSetData.htm)($Input1, "")
$iCheck = 0
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
EndIf (http://www.autoitscript.com/autoit3/docs/keywords.htm#EndIf)
WEnd (http://www.autoitscript.com/autoit3/docs/keywords.htm#WEnd)

Creat0R
02-07-2010, 16:48
У меня так работает »
У меня тоже, но это не самое оптимальное решение ;)

madmasles
02-07-2010, 17:15
У меня тоже, но это не самое оптимальное решение »
А в каком случае этот вариант может не сработать?

Creat0R
02-07-2010, 19:11
в каком случае этот вариант может не сработать? »
А я не говорил что это может не сработать :).




© OSzone.net 2001-2012