News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

GetLocalTime

Started by santa, February 03, 2006, 10:19:20 AM

Previous topic - Next topic

santa


I don't know how to use this function? Could somebody help me.

Santa

ramguru

Hi!

...some code here
.data
mon1  db " January",0
mon2  db " February",0
mon3  db " March",0
mon4  db " April",0
mon5  db " May",0
mon6  db " June",0
mon7  db " July",0
mon8  db " August",0
mon9  db " September",0
mon10 db " October",0
mon11 db " November",0
mon12 db " December",0
MONS  dd OFFSET mon1,OFFSET mon2,OFFSET mon3,OFFSET mon4,OFFSET mon5,OFFSET mon6,OFFSET mon7,OFFSET mon8,OFFSET mon9,OFFSET mon10,OFFSET mon11,OFFSET mon12
day0  db " Sunday",0
day1  db " Monday",0
day2  db " Tuesday",0
day3  db " Wednesday",0
day4  db " Thursday",0
day5  db " Friday",0
day6  db " Saturday",0
DAYS  dd OFFSET day0,OFFSET day1,OFFSET day2,OFFSET day3,OFFSET day4,OFFSET day5,OFFSET day6

.code

start:

invoke GetModuleHandle,NULL
mov    hInstance,eax
    invoke InitCommonControls
invoke DialogBoxParam,hInstance,IDD_DIALOG1,NULL,addr DlgProc,NULL
invoke ExitProcess,0

DlgProc proc hWin:HWND,uMsg:UINT,wParam:WPARAM,lParam:LPARAM
LOCAL stime:SYSTEMTIME
LOCAL buf[16]:BYTE
LOCAL buffer[64]:BYTE

mov eax,uMsg
.if eax==WM_INITDIALOG
.elseif eax==WM_COMMAND
mov    eax, wParam
.if eax == 1002 ;if button with ID = 1002 pressed
invoke GetLocalTime, ADDR stime
xor    ecx, ecx
mov    cx, stime.wYear
invoke dwtoa, ecx, ADDR buf
invoke szCopy, ADDR buf, ADDR buffer

mov    ecx, OFFSET MONS
xor    eax, eax
mov    ax, stime.wMonth
dec    eax
shl    eax, 2
add    ecx, eax
invoke szCatStr, ADDR buffer, DWORD ptr [ecx]

mov    ecx, OFFSET DAYS
xor    eax, eax
mov    ax, stime.wDayOfWeek
shl    eax, 2
add    ecx, eax
invoke szCatStr, ADDR buffer, DWORD ptr [ecx]

invoke SendDlgItemMessage, hWin, 1001, WM_SETTEXT, 0, ADDR buffer ;set text of edit control with ID 1001

;THE OUTPUT WILL BE: "2006 February Friday"
.endif
...some code here

Tedd

.data
thetime     db "The current time is:",0

.data?
systime     SYSTEMTIME <?>      ;somewhere to store the time details
buff        db 64 dup (?)

.code
    invoke GetLocalTime, ADDR systime       ;get the time, saved into systime

    xor eax,eax
    mov ax,[systime].wHour      ;eax = the current hour
    xor ecx,ecx
    mov cx,[systime].wMinute    ;ecx = the current minute
    ;do whatever you want with the numbers..


    ;if you want to display the current time, you can do..
    ;(there are extra paramters if you want to format the time in some way - lookup the function)
    invoke GetTimeFormat, LOCALE_USER_DEFAULT,NULL,ADDR systime,NULL,ADDR buff,SIZEOF buff

    invoke MessageBox, NULL,ADDR buff,ADDR thetime,MB_ICONINFORMATION or MB_OK
No snowflake in an avalanche feels responsible.

santa

Hellow

Thanks

Respect
Santa