找回密码
 加入
搜索
查看: 2740|回复: 0

[AU3基础] [已解决]请大家帮我完善一下我的代码

[复制链接]
发表于 2009-10-25 21:34:52 | 显示全部楼层 |阅读模式
本帖最后由 smooth 于 2010-11-9 20:58 编辑
#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, 437, -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, 397)
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, 132)
;
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)
;
GUICtrlCreateLabel("今天是孕期第:", 40, 198, 100, 17)
$Input7 = GUICtrlCreateInput("", 144, 190, 33, 25, BitOR($ES_RIGHT, $ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetFont(-1, 13, 800)
GUICtrlCreateLabel("月,零", 184, 198, 40, 17)
$Input8 = GUICtrlCreateInput("", 224, 190, 33, 25, BitOR($ES_RIGHT, $ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetFont(-1, 13, 800)
GUICtrlCreateLabel("天(合计", 264, 198, 52, 17)
$Input9 = GUICtrlCreateInput("", 320, 190, 41, 25, BitOR($ES_RIGHT, $ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetFont(-1, 13, 800)
GUICtrlCreateLabel("天)", 368, 198, 28, 17)

GUICtrlCreateGroup("宝宝出生倒计时", 24, 236, 377, 153)
;
GUICtrlCreateLabel("离宝宝出生还有:", 40, 266, 100, 17)
$Input10 = GUICtrlCreateInput("", 140, 258, 41, 25, BitOR($ES_RIGHT, $ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetFont(-1, 13, 800)
GUICtrlCreateLabel("月,零", 184, 266, 40, 17)
$Input11 = GUICtrlCreateInput("", 224, 258, 33, 25, BitOR($ES_RIGHT, $ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetFont(-1, 13, 800)
GUICtrlCreateLabel("天(合计", 264, 266, 52, 17)
$Input12 = GUICtrlCreateInput("", 316, 258, 49, 25, BitOR($ES_RIGHT, $ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetFont(-1, 13, 800)
GUICtrlCreateLabel("天)", 368, 266, 28, 17)
;
GUICtrlCreateLabel("离宝宝出生还有:", 40, 302, 100, 17)
$Input13 = GUICtrlCreateInput("", 140, 296, 41, 25, BitOR($ES_RIGHT, $ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetFont(-1, 13, 800)
GUICtrlCreateLabel("周,零", 184, 302, 40, 17)
$Input14 = GUICtrlCreateInput("", 224, 296, 33, 25, BitOR($ES_RIGHT, $ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetFont(-1, 13, 800)
GUICtrlCreateLabel("天(合计", 264, 302, 52, 17)
$Input15 = GUICtrlCreateInput("", 316, 296, 49, 25, BitOR($ES_RIGHT, $ES_AUTOHSCROLL, $ES_READONLY))
GUICtrlSetFont(-1, 13, 800)
GUICtrlCreateLabel("天)", 368, 302, 28, 17)
;
GUICtrlCreateLabel("祝:母子平安,阖家幸福!", 39, 340, 200, 24)
GUICtrlSetFont(-1, 11, 800)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("", -99, -99, 1, 1)
;
GUICtrlCreateLabel("鼎盛技术,开创未来!", 250, 336, 140, 14)
GUICtrlSetFont(-1, 10, 800)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUICtrlCreateGroup("", -99, -99, 1, 1)
;
$lj = GUICtrlCreateLabel("访问我的主页", 250, 361,72, 14)
GUICtrlSetCursor(-1, 0)
GUICtrlSetFont(-1, 10, 800)

Dim $vPartEdge[2], $vPartText[2]
$vPartEdge[0] = 200
$vPartEdge[1] = 400
$vPartText[0] = '  今天日期是:' & @YEAR & '年 ' & @MON & '月 ' & @MDAY & '日'
$vPartText[1] = '  Coded by ********,QQ:********'
_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, 800, 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("www.autoitx.com")
        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)
                GUICtrlSetData($Input9, $iDayTotal)
        Else
                GUICtrlSetData($Input4, '')
                GUICtrlSetData($Input5, '')
                GUICtrlSetData($Input6, '')
                GUICtrlSetData($Input7, '')
                GUICtrlSetData($Input8, '')
                GUICtrlSetData($Input9, '')
        EndIf
EndFunc   ;==>_Show_DayForPregnant

Func _Show_DayToBirth($iDayToBirth, $iMode = 1)
        If $iMode == 1 Then
                Local $iMonthNum = Floor($iDayToBirth / 28), _
                                $iDayNum = Mod($iDayToBirth, 28), _
                                $iDayTotal = $iDayToBirth
                If $iDayTotal > 9999 Then
                        $iMonthNum = '???'
                        $iDayNum = '??'
                        $iDayTotal = '????'
                EndIf
                GUICtrlSetData($Input10, $iMonthNum)
                GUICtrlSetData($Input11, $iDayNum)
                GUICtrlSetData($Input12, $iDayTotal)
                ;
                Local $iWeekNum = Floor($iDayToBirth / 7), _
                                $iDayNum = Mod($iDayToBirth, 7), _
                                $iDayTotal = $iDayToBirth
                If $iWeekNum > 999 Then
                        $iWeekNum = '???'
                        $iDayNum = '??'
                        $iDayTotal = '????'
                EndIf
                GUICtrlSetData($Input13, $iWeekNum)
                GUICtrlSetData($Input14, $iDayNum)
                GUICtrlSetData($Input15, $iDayTotal)
        Else
                GUICtrlSetData($Input10, '')
                GUICtrlSetData($Input11, '')
                GUICtrlSetData($Input12, '')
                GUICtrlSetData($Input13, '')
                GUICtrlSetData($Input14, '')
                GUICtrlSetData($Input15, '')
        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
问题一:我添加了一行“今天是预期第(   )月,零(   )天,合计(   )天”,前面2个空不会计算,能否帮忙完成;
问题二:能否修改一下代码,增加一个“查看本周胎宝宝的状况”按钮,当点击这个按钮时,弹出一个窗口,这个窗口和原来的窗口挨着,窗口显示的内容为:判断Input4的周数,如果是第1周,就显示内容a1,如果是第2周,就显示内容a2……,一直到a40。a代表一段文字,大约800多字,所以弹出的窗口差不多要和主窗口一样大。
感谢帮我解答的朋友,谢谢。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-5-17 13:22 , Processed in 0.078214 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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