|
用Win32汇编写的"奥运会开幕倒计时牌"
[mw_shl_code=asm,true];这个小程序的功能是:把北京奥运会的开幕时间换算成秒数,
;然后获取本地时间,也换算成秒数,将前者减去后者,(如果相
;减后,数值小于或等于0,则提醒,点OK退出)把得到
;的时间再换算成天数时数分数秒数,并显示出来.
;呵呵~~方法很笨,但超简单的啦.希望牛哥牛弟批评指正
;=================================================
;作者:ONEPROBLEM 2008年7月24日
;=================================================
.386
.model flat,stdcall
option casemap:none
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
ID_DIALOG equ 1
ICO_MAIN equ 1
IDB_MAIN equ 1
IDC_DAY equ 100
IDC_HOUR equ 101
IDC_MINUTE equ 102
IDC_SECOND equ 103
IDC_BMP equ 104
.data?
hInstance dd ?
hWinMain dd ?
hBmp dd ?
idTimer dd ?
OlymTimeCount dd ?
NowTimeCount dd ?
.const
szCaption db '友情提醒',0
szText db '2008北京奥运会开幕了! Welcome to BeiJing!',0
;================================================================
.code
_Getlocaltime proc _hWnd
local @stTime:SYSTEMTIME
pushad
invoke GetLocalTime,addr @stTime
movzx eax,@stTime.wMonth
mov ebx,2678400 ;把月份换算成秒数
mul ebx
mov NowTimeCount,eax
movzx eax,@stTime.wDay
mov ebx,86400 ;把天数换算成秒数
mul ebx
add NowTimeCount,eax
movzx eax,@stTime.wHour
mov ebx,3600 ;把时数换算成秒数
mul ebx
add NowTimeCount,eax
movzx eax,@stTime.wMinute ;把分数换算成秒数
mov ebx,60
mul ebx
add NowTimeCount,eax
movzx eax,@stTime.wSecond
add NowTimeCount,eax
mov eax,22190888 ;开幕时间在8月8日20时8分8秒,这是换算成的秒数
sub eax,NowTimeCount
.if eax <=0
invoke MessageBox,hWinMain,offset szText,offset szCaption,MB_OK
invoke SendMessage,hWinMain,WM_CLOSE,0,0
.endif
mov OlymTimeCount,eax ;以下将这个数换算成倒计时"天时分秒"
mov edx,0 ;在此eax不用重新赋值
mov ebx,86400
div ebx
mov OlymTimeCount,edx ;重新保存余数
invoke SetDlgItemInt,hWinMain,IDC_DAY,eax,FALSE
mov eax,OlymTimeCount
mov edx,0
mov ebx,3600
div ebx
mov OlymTimeCount,edx
invoke SetDlgItemInt,hWinMain,IDC_HOUR,eax,FALSE
mov eax,OlymTimeCount
mov edx,0
mov ebx,60
div ebx
mov OlymTimeCount,edx
invoke SetDlgItemInt,hWinMain,IDC_MINUTE,eax,FALSE
mov eax,OlymTimeCount
invoke SetDlgItemInt,hWinMain,IDC_SECOND,eax,FALSE
popad
ret
_Getlocaltime endp
;======================================================================
_ProcDlgMain proc uses ebx edi esi,hWnd,uMsg,wParam,IParam
mov eax,uMsg
.if eax == WM_INITDIALOG
push hWnd
pop hWinMain
invoke LoadIcon,hInstance,ICO_MAIN
invoke SendMessage,hWnd,WM_SETICON,ICON_BIG,eax
invoke LoadBitmap,hInstance,IDB_MAIN
mov hBmp,eax
invoke SendDlgItemMessage,hWnd,IDC_BMP,STM_SETIMAGE,IMAGE_BITMAP,hBmp
invoke SetTimer,NULL,NULL,1000,addr _Getlocaltime
mov idTimer,eax
.elseif eax == WM_COMMAND
mov eax,wParam
.if ax == IDCANCEL
invoke KillTimer,NULL,idTimer
invoke EndDialog,hWnd,NULL
.endif
.elseif eax == WM_CLOSE
invoke KillTimer,NULL,idTimer
invoke EndDialog,hWnd,NULL
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
_ProcDlgMain endp
;========================================================================
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance,ID_DIALOG,NULL,offset _ProcDlgMain,NULL
invoke ExitProcess,NULL
end start[/mw_shl_code] |
|