用Win32汇编写的"奥运会开幕倒计时牌",请大家指正
今天我用Win32汇编写了一个小小的程序,目的:1、我是小菜鸟,大程序还不会写;
2、坚持每天写一个小程序,培养自己的动手动脚能力;
3、2008北京奥运会快要开幕了,不能整天都埋头写代码,也要关心国家大事,所以写了个东西,这是最主要的目的;
4、既然是小菜鸟,自己做出来的东西,就要拿出来让大家批评指正。
牛哥牛弟们呀,在计算两次时间间隔的方法上,我实在没有好办法啊,知道的给讲讲吧。还有,对于“年”我没法算,好像太复杂了,对于“月份”我是按31天/月计的(呵呵~~幸亏7月、8月都是31天哈),可见这是一个偷工减料的程序。
===============================================================================
OlympicTime.ASM文件
=========================================================
;这个小程序的功能是:把北京奥运会的开幕时间换算成秒数,
;然后获取本地时间,也换算成秒数,将前者减去后者,(如果相
;减后,数值小于或等于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
======================================================================================================
//OLYMPICTIME.RC文件
//===============================================
#include <resource.h>
#define ICO_MAIN 1
#define ID_DIALOG 1
#define IDB_MAIN 1
#define IDC_DAY 100
#define IDC_HOUR 101
#define IDC_MINUTE 102
#define IDC_SECOND 103
#define IDC_BMP 104
ICO_MAIN ICON "1.ico"
IDB_MAIN BITMAP "1.bmp"
//==============================================
ID_DIALOG DIALOG DISCARDABLE 50, 50, 180, 88
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "2008北京奥运开幕倒计时"
FONT 14, "宋体"
BEGIN
PUSHBUTTON "退 出",IDCANCEL,116,66,50,14
CONTROL " ",IDC_BMP,"Static",SS_BITMAP | WS_CHILD | WS_VISIBLE,7,7,40,
60
LTEXT "距第29届奥运会开幕还有:",IDC_STATIC,51,7,129,18,
SS_CENTERIMAGE
CTEXT " ",IDC_DAY,52,39,16,10,SS_SUNKEN
LTEXT "天",IDC_STATIC,71,39,8,10
CTEXT " ",IDC_HOUR,85,39,16,10,SS_SUNKEN
LTEXT "时",IDC_STATIC,106,39,8,10
CTEXT " ",IDC_MINUTE,115,39,16,10,SS_SUNKEN
LTEXT "分",IDC_STATIC,134,39,8,10
CTEXT " ",IDC_SECOND,143,39,16,10,SS_SUNKEN
LTEXT "秒",IDC_STATIC,164,39,8,10
END
//=============================================================================================
OlympicTime.rar
(20.92 KB)