找回密码
 加入
搜索
查看: 2092|回复: 4

如何对输入框中的日期使用BackSpace键修改?

[复制链接]
发表于 2009-9-27 19:40:55 | 显示全部楼层 |阅读模式

如图,输入时间的时候,比如我想输入2009,但是由于下手的时候,第一个数字输成了3,但是却不能使用BackSpace键或者Delete键进行删除。
脚本如下:
#Region ;**** 参数创建于 ACNWrapper_GUI ****
#AutoIt3Wrapper_icon=include\Baby.ico
#AutoIt3Wrapper_outfile=..\..\BabyBirth.exe
#AutoIt3Wrapper_Res_Comment=程序设计:鼎盛中国。你可以自由使用、分发本程序,但严禁用于商业用途。
#AutoIt3Wrapper_Res_Description=宝宝出生日期计算器
#AutoIt3Wrapper_Res_Fileversion=5.8.8.5
#AutoIt3Wrapper_Res_LegalCopyright=鼎盛中国保留所有权利
#EndRegion ;**** 参数创建于 ACNWrapper_GUI ****

#cs ____________________________________
        
        Au3 版本: 3.3.0.0
        脚本设计:鼎盛中国 
        脚本功能: 宝宝出生倒计时计算器
        
#ce _______________脚本开始_________________

#include <DateTimeConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

#include <GuiStatusBar.au3>
#include <Date.au3>

Opt("TrayMenuMode", 1)
Opt('TrayAutoPause', 0)
Opt("MustDeclareVars")

Global $Title = "宝宝出生倒计时计算器"
If WinExists($Title) Then Exit
AutoItWinSetTitle($Title)

Global $Form = GUICreate($Title, 425, 401, -1, -1)

Global $SkinFile = @TempDir & '\Skin.skf', _
                $SkinDll = @TempDir & '\SkinCrafter.dll'
FileInstall('include\Skin.skf', $SkinFile, 1)
FileInstall('include\SkinCrafter.dll', $SkinDll, 1)
Global $hSkinDll = _LoadSkin($SkinFile, $SkinDll, $Form)

Global $IniFile = StringLeft(@ScriptFullPath, StringInStr(@ScriptFullPath, '.', 0, -1)) & 'ini'

GUICtrlCreateGroup("献给未来出生的宝宝的小礼物", 8, 8, 409, 361)
GUICtrlCreateGroup("", 24, 24, 225, 64)
GUICtrlCreateLabel("请输入怀孕日期:", 40, 52, 100, 17)
$Date = GUICtrlCreateDate(IniRead($IniFile, 'Baby', 'PregnantDate', @YEAR & '-' & @MON & '-' & @MDAY), 144, 48, 90, 21, 0)
GUICtrlCreateGroup("", -99, -99, 1, 1)

Global $Image = @TempDir & '\Baby.jpg'
FileInstall('include\Baby.jpg', $Image, 1)
GUICtrlCreatePic($Image, 260, 29, 140, 60, 0)
FileDelete($Image)

GUICtrlCreateGroup("预测结果", 24, 96, 377, 96)
;
GUICtrlCreateLabel("宝宝出生日期是:", 40, 126, 100, 17)
$Input1 = GUICtrlCreateInput("", 144, 118, 49, 25, BitOR($ES_RIGHT, $ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetFont(-1, 13, 800)
GUICtrlCreateLabel("年", 200, 126, 16, 17)
$Input2 = GUICtrlCreateInput("", 224, 118, 33, 25, BitOR($ES_RIGHT, $ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetFont(-1, 13, 800)
GUICtrlCreateLabel("月", 264, 126, 16, 17)
$Input3 = GUICtrlCreateInput("", 280, 118, 33, 25, BitOR($ES_RIGHT, $ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetFont(-1, 13, 800)
GUICtrlCreateLabel("日", 320, 126, 16, 17)
;
GUICtrlCreateLabel("今天是孕期第:", 40, 162, 100, 17)
$Input4 = GUICtrlCreateInput("", 144, 154, 33, 25, BitOR($ES_RIGHT, $ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetFont(-1, 13, 800)
GUICtrlCreateLabel("周,零", 184, 162, 40, 17)
$Input5 = GUICtrlCreateInput("", 224, 154, 33, 25, BitOR($ES_RIGHT, $ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetFont(-1, 13, 800)
GUICtrlCreateLabel("天(合计", 264, 162, 52, 17)
$Input6 = GUICtrlCreateInput("", 320, 154, 41, 25, BitOR($ES_RIGHT, $ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetFont(-1, 13, 800)
GUICtrlCreateLabel("天)", 368, 162, 28, 17)

GUICtrlCreateGroup("宝宝出生倒计时", 24, 200, 377, 153)
;
GUICtrlCreateLabel("离宝宝出生还有:", 40, 230, 100, 17)
$Input7 = GUICtrlCreateInput("", 140, 222, 41, 25, BitOR($ES_RIGHT, $ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetFont(-1, 13, 800)
GUICtrlCreateLabel("月,零", 184, 230, 40, 17)
$Input8 = GUICtrlCreateInput("", 224, 222, 33, 25, BitOR($ES_RIGHT, $ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetFont(-1, 13, 800)
GUICtrlCreateLabel("天(合计", 264, 230, 52, 17)
$Input9 = GUICtrlCreateInput("", 316, 222, 49, 25, BitOR($ES_RIGHT, $ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetFont(-1, 13, 800)
GUICtrlCreateLabel("天)", 368, 230, 28, 17)
;
GUICtrlCreateLabel("离宝宝出生还有:", 40, 266, 100, 17)
$Input10 = GUICtrlCreateInput("", 140, 260, 41, 25, BitOR($ES_RIGHT, $ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetFont(-1, 13, 800)
GUICtrlCreateLabel("周,零", 184, 266, 40, 17)
$Input11 = GUICtrlCreateInput("", 224, 260, 33, 25, BitOR($ES_RIGHT, $ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetFont(-1, 13, 800)
GUICtrlCreateLabel("天(合计", 264, 266, 52, 17)
$Input12 = GUICtrlCreateInput("", 316, 260, 49, 25, BitOR($ES_RIGHT, $ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetFont(-1, 13, 800)
GUICtrlCreateLabel("天)", 368, 266, 28, 17)
;
GUICtrlCreateLabel("祝:母子平安,阖家幸福!", 39, 310, 200, 24)
GUICtrlSetFont(-1, 11, 800)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("", -99, -99, 1, 1)
;
GUICtrlCreateLabel("鼎盛技术,开创未来!", 260, 300, 130, 14)
GUICtrlSetFont(-1, 10, 400)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("", -99, -99, 1, 1)
;
$lj = GUICtrlCreateLabel("访问鼎盛中国的网站", 260, 325,108, 14)
GUICtrlSetCursor(-1, 0)

Dim $vPartEdge[2], $vPartText[2]
$vPartEdge[0] = 200
$vPartEdge[1] = 400
$vPartText[0] = '  今天日期是:' & @YEAR & '年 ' & @MON & '月 ' & @MDAY & '日'
$vPartText[1] = '  Coded by 鼎盛中国,QQ:93737788'
_GUICtrlStatusBar_Create($Form, $vPartEdge, $vPartText)

_Set(GUICtrlRead($Date))
GUISetState(@SW_SHOW)

Dim $bj = 0
While 1
        $zt = GUIGetCursorInfo($Form)
        If $zt[4] = $lj And $bj = 0 Then
                GUICtrlSetFont($lj, 9, 400, 4)
                GUICtrlSetColor($lj, 0x0000FF)
                $bj = 1
        ElseIf $zt[4] <> $lj And $bj = 1 Then
                GUICtrlSetFont($lj, 9, 400, 0)
                GUICtrlSetColor($lj, 0x000000)
                $bj = 0
        EndIf
        
            $nMsg = GUIGetMsg()
            Switch $nMsg
                    Case $GUI_EVENT_CLOSE
                            _UnLoadSkin($hSkinDll)
                            FileDelete($SkinFile)
                            FileDelete($SkinDll)
                        Exit
                    Case $Date
                            _Set(GUICtrlRead($Date))
                            _Write($IniFile, 'Baby', 'PregnantDate', GUICtrlRead($Date))
                        Case - 3
                                Exit
                    Case $lj
                ShellExecute("http://hi.baidu.com/cnace")
        EndSwitch
WEnd


Func _Set($dPregnantDate)
        Local $sPregnantDate, $sToday, $sDateOfBirth, $iDayToBirth, $iDayForPregnant

        ;处理怀孕日期,获取 年 月 日(因受精当天算入孕期第一天,为方便计算,“日”往前推一天)
        Local $t = StringSplit($dPregnantDate, '-')
        Local $iYear = $t[1], _
                        $iMonth = $t[2], _
                        $iDay = $t[3]

        ;获取怀孕日期的 Juliandate
        $sPregnantDate = _DateToDayValue($iYear, $iMonth, $iDay) - 1
        ;获取当前系统日期的 Juliandate
        $sToday = _DateToDayValue(@YEAR, @MON, @MDAY)

        ;分别计算出 1.出生日期的 Juliandate; 2.离出生的天数; 3.怀孕天数
        $sDateOfBirth = $sPregnantDate + 281
        $iDayToBirth = $sDateOfBirth - $sToday
        $iDayForPregnant = $sToday - $sPregnantDate

        If $sPregnantDate > 0 Then
                Select
                        Case $iDayForPregnant <= 0 ;当 怀孕天数 <=0 时,还没有怀孕,不显示 “孕期”,只显示 “出生日期”、“出生倒计时”
                                _Show_DateOfBirth($sDateOfBirth)
                                _Show_DayForPregnant('', 0)
                                _Show_DayToBirth($iDayToBirth)
                        Case $iDayForPregnant <= 280 ;当 0< 怀孕天数 <=280 时,正常显示 “出生日期”、“孕期”、“出生倒计时”
                                _Show_DateOfBirth($sDateOfBirth)
                                _Show_DayForPregnant($iDayForPregnant)
                                _Show_DayToBirth($iDayToBirth)
                        Case $iDayForPregnant > 280 ;当 怀孕天数 >280 时,不显示 “孕期”、“出生倒计时”,只显示 “出生日期”
                                _Show_DateOfBirth($sDateOfBirth)
                                _Show_DayForPregnant('', 0)
                                _Show_DayToBirth('', 0)
                EndSelect
        Else
                _Show_DateOfBirth('', 0)
                _Show_DayForPregnant('', 0)
                _Show_DayToBirth('', 0)
        EndIf
EndFunc   ;==>_Set

Func _Show_DateOfBirth($sDateOfBirth, $iMode = 1)
        If $iMode == 1 Then
                Local $iYear, $iMonth, $iDay
                _DayValueToDate($sDateOfBirth, $iYear, $iMonth, $iDay)
                GUICtrlSetData($Input1, $iYear)
                GUICtrlSetData($Input2, $iMonth)
                GUICtrlSetData($Input3, $iDay)
        Else
                GUICtrlSetData($Input1, '')
                GUICtrlSetData($Input2, '')
                GUICtrlSetData($Input3, '')
        EndIf
EndFunc   ;==>_Show_DateOfBirth

Func _Show_DayForPregnant($iDayForPregnant, $iMode = 1)
        If $iMode == 1 Then
                Local $iWeekNum = Floor($iDayForPregnant / 7), _
                                $iDayNum = Mod($iDayForPregnant, 7), _
                                $iDayTotal = $iDayForPregnant
                GUICtrlSetData($Input4, $iWeekNum)
                GUICtrlSetData($Input5, $iDayNum)
                GUICtrlSetData($Input6, $iDayTotal)
        Else
                GUICtrlSetData($Input4, '')
                GUICtrlSetData($Input5, '')
                GUICtrlSetData($Input6, '')
        EndIf
EndFunc   ;==>_Show_DayForPregnant

Func _Show_DayToBirth($iDayToBirth, $iMode = 1)
        If $iMode == 1 Then
                Local $iMonthNum = Floor($iDayToBirth / 30), _
                                $iDayNum = Mod($iDayToBirth, 30), _
                                $iDayTotal = $iDayToBirth
                If $iDayTotal > 9999 Then
                        $iMonthNum = '???'
                        $iDayNum = '??'
                        $iDayTotal = '????'
                EndIf
                GUICtrlSetData($Input7, $iMonthNum)
                GUICtrlSetData($Input8, $iDayNum)
                GUICtrlSetData($Input9, $iDayTotal)
                ;
                Local $iWeekNum = Floor($iDayToBirth / 7), _
                                $iDayNum = Mod($iDayToBirth, 7), _
                                $iDayTotal = $iDayToBirth
                If $iWeekNum > 999 Then
                        $iWeekNum = '???'
                        $iDayNum = '??'
                        $iDayTotal = '????'
                EndIf
                GUICtrlSetData($Input10, $iWeekNum)
                GUICtrlSetData($Input11, $iDayNum)
                GUICtrlSetData($Input12, $iDayTotal)
        Else
                GUICtrlSetData($Input7, '')
                GUICtrlSetData($Input8, '')
                GUICtrlSetData($Input9, '')
                GUICtrlSetData($Input10, '')
                GUICtrlSetData($Input11, '')
                GUICtrlSetData($Input12, '')
        EndIf
EndFunc   ;==>_Show_DayToBirth

Func _Write($sFile, $sSection, $sKey, $dPregnantDate)
        ;处理怀孕日期,获取 年 月 日, 给 月 日 的一位数字补0 (如 09月 09日)
        Local $t = StringSplit($dPregnantDate, '-')
        Local $iYear = $t[1], _
                        $iMonth = $t[2], _
                        $iDay = $t[3]
        $dPregnantDate = $iYear & '-' & StringRight('0' & $iMonth, 2) & '-' & StringRight('0' & $iDay, 2)

        ;写入配置文件
        IniWrite($sFile, $sSection, $sKey, $dPregnantDate)

EndFunc   ;==>_Write

Func _LoadSkin($sSkinFile, $sSkinDll, $cForm)
        Local $hSkinDll = DllOpen($sSkinDll)
        DllCall($hSkinDll, "int:cdecl", "InitLicenKeys", "wstr", "1", "wstr", "", "wstr", "1@1.com", "wstr", "1")
        DllCall($hSkinDll, "int:cdecl", "InitDecoration", "int", 1)
        DllCall($hSkinDll, "int:cdecl", "LoadSkinFromFile", "wstr", $sSkinFile)
        DllCall($hSkinDll, "int:cdecl", "DecorateAs", "int", $cForm, "int", 25)
        DllCall($hSkinDll, "int:cdecl", "ApplySkin")
        Return $hSkinDll
EndFunc   ;==>_LoadSkin

Func _UnLoadSkin($hSkinDll)
        GUISetState(@SW_HIDE)
        DllCall($hSkinDll, "int:cdecl", "DeInitDecoration")
        DllCall($hSkinDll, "int:cdecl", "RemoveSkin")
        DllClose($hSkinDll)
EndFunc   ;==>_UnLoadSkin

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2009-9-28 00:36:14 | 显示全部楼层
把readonly属性去了,你见过只读的控件可以输入或删除内容的
 楼主| 发表于 2009-9-28 00:53:03 | 显示全部楼层
本帖最后由 smooth 于 2009-9-28 00:54 编辑

输入是可以。可见不是只读属性了。但是必须把其中一项输入完毕,才能再次输入。或者将光标移动到别的项,比如从年份移动到月,然后再移动回来,才可以再次输入。怎么弄,还请多多指点。
发表于 2009-9-28 01:16:10 | 显示全部楼层
本帖最后由 netegg 于 2009-9-28 01:17 编辑

没错呀,你的那个$nMsg是换了句柄才出来的,没换句柄,哪出来guigetmsg

另外,“必须把其中一项输入完毕,才能再次输入“这句话是什么意思
 楼主| 发表于 2009-9-28 13:06:01 | 显示全部楼层
没错呀,你的那个$nMsg是换了句柄才出来的,没换句柄,哪出来guigetmsg

另外,“必须把其中一项输入完毕,才能再次输入“这句话是什么意思
netegg 发表于 2009-9-28 01:16


比如要输入2009,第一个数字不小心输入了3,那么你必须在3之后再输入3位数字,才能再次输入2009。或者,你发现第1个数字输错了,也可以按向右的方向键,让光标跳到月份那里,然后再按向左的方向键,光标重新回到年份那里,你才可以再次输入正确的。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-22 19:30 , Processed in 0.081601 second(s), 22 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表