TITLE COORD and the systemTime (.asm)
; This program
; This program
; Last update:2011.4.3
INCLUDE Irvine32.inc
.data
systime SYSTEMTIME <>
xypos COORD <10,5>
consolehandle DWORD ?
colonStr byte ":",0
.code
main PROC
;//获取win32控制台的标准输出手柄
invoke GetStdHandle,STD_OUTPUT_HANDLE
mov consolehandle,eax
;//设置光标并且获取系统时间,定义完句柄把句柄放进这里面
invoke SetConsoleCursorPosition,consolehandle,xypos
invoke GetLocalTime,addr sysTime
;//显示系统时间
movzx eax,sysTime.wHour
call writedec
mov edx,offset colonStr
call writestring
movzx eax,systime.wminute
call writedec
call writestring
movzx eax,systime.wsecond
call writedec
call crlf
exit
main ENDP
END main
因为上面调用了windows的默认句柄,所以这里是smallwin.inc文件里面的定义,这里的HANDLE下面有给出.
GetStdHandle PROTO, ; get standard handle
nStdHandle:HANDLE ; type of console handle
我们选择的是标准输出句柄,同样也有输入句柄和错误句柄.
; Win32 Console handles
STD_INPUT_HANDLE EQU -10
STD_OUTPUT_HANDLE EQU -11 ; predefined Win API constant
STD_ERROR_HANDLE EQU -12
为了能够输出,这里要定义句柄和坐标.
SetConsoleCursorPosition PROTO,
hConsoleOutput:HANDLE, ; output handle
dwCursorPosition:COORD ; screen X,Y coordinates
这里是smallWin.inc里面已经定义好的
COORD STRUCT ;坐标
X WORD ?
Y WORD ?
COORD ENDS
SYSTEMTIME STRUCT ;系统时间
wYear WORD ?
wMonth WORD ?
wDayOfWeek WORD ?
wDay WORD ?
wHour WORD ?
wMinute WORD ?
wSecond WORD ?
wMilliseconds WORD ?
SYSTEMTIME ENDS