The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: majid1605 on December 20, 2011, 07:11:14 PM

Title: Display system time
Post by: majid1605 on December 20, 2011, 07:11:14 PM
How do I display  the system time in the message box

.486
.model flat,stdcall
option casemap:none
 
     
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
 
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\msvcrt.inc ;crt__ultoa
include     \masm32\macros\macros.asm


includelib  \masm32\lib\user32.lib
includelib  \masm32\lib\kernel32.lib
includelib \masm32\lib\msvcrt.lib  ;crt__ultoa


     
.data
ClassName db "SimpleWinClass",0
AppName  db "Local Time",0


MyString      DB 20 dup(' '),0

LTimeis     db "LocalTime is: "
HTime       DB   2 dup (' ')
SymTime     db ':'
STime       DB   2 dup (' ')
            db 0     


.data?

hInstance HINSTANCE ?
CommandLine LPSTR ?


width_w       dd ?
height_w   dd ?

stimestruct STRUCT     
       wYear            WORD ?   
       wMonth           WORD ?
       wDayOfWeek       WORD ?
       wDay             WORD ?
       wHour            WORD ?
       wMinute          WORD ?
       wSecond          WORD ?
       wMilliseconds    WORD ?
    stimestruct EndS
       
    stime stimestruct {}

; example of simplified Windows programming using complex macro features



.code

  start:

LTimep proc
    lea ebx,stime
    push ebx
    call GetLocalTime
     
    xor eax,eax
    mov al,byte ptr [ebx].stimestruct.wHour
    invoke crt__ultoa,eax,ADDR MyString,10

    mov ax,word ptr MyString
    mov word ptr HTime,ax
    cmp HTime+1,0
    jne next
    mov al,HTime
    xchg HTime+1,al
    mov HTime,' '
next: 
     
    xor eax,eax
    mov  al,byte ptr [ebx].stimestruct.wMinute
    invoke crt__ultoa,eax,ADDR MyString,10
     
     
    mov ax,word ptr MyString
    mov word ptr STime,ax
    cmp STime+1,0
    jne next2
    mov STime,al
next2:


    ret
LTimep endp   

invoke MessageBox,HWND_DESKTOP,ADDR LTimep,invoke GetCommandLine,MB_OK
invoke ExitProcess,0

.end start



like the following code But in the message box

.486
.model flat,stdcall
option casemap:none
 
     
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
 
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\msvcrt.inc ;crt__ultoa
include     \masm32\macros\macros.asm


includelib  \masm32\lib\user32.lib
includelib  \masm32\lib\kernel32.lib
includelib \masm32\lib\msvcrt.lib  ;crt__ultoa


     
     
.data
ClassName db "SimpleWinClass",0
AppName  db "Local Time",0


MyString      DB 20 dup(' '),0

LTimeis     db "LocalTime is: "
HTime       DB   2 dup (' ')
SymTime     db ':'
STime       DB   2 dup (' ')
            db 0     


.data?

hInstance HINSTANCE ?
CommandLine LPSTR ?


width_w       dd ?
height_w   dd ?

stimestruct STRUCT     
       wYear            WORD ?   
       wMonth           WORD ?
       wDayOfWeek       WORD ?
       wDay             WORD ?
       wHour            WORD ?
       wMinute          WORD ?
       wSecond          WORD ?
       wMilliseconds    WORD ?
    stimestruct EndS
       
    stime stimestruct {}
 
 
     

.code
start:
    invoke GetModuleHandle, NULL
    mov    hInstance,eax
    invoke GetCommandLine
    mov CommandLine,eax
    invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
    invoke ExitProcess,eax
WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,  CmdShow:DWORD
    LOCAL wc:WNDCLASSEX
    LOCAL msg:MSG
    LOCAL hwnd:HWND
    mov   wc.cbSize,SIZEOF WNDCLASSEX
    mov   wc.style, CS_HREDRAW or CS_VREDRAW
    mov   wc.lpfnWndProc, OFFSET WndProc
    mov   wc.cbClsExtra,NULL
    mov   wc.cbWndExtra,NULL
    push  hInst
    pop   wc.hInstance
    mov   wc.hbrBackground,COLOR_WINDOW+1
    mov   wc.lpszMenuName,NULL
    mov   wc.lpszClassName,OFFSET ClassName
    invoke LoadIcon,NULL,IDI_APPLICATION
    mov   wc.hIcon,eax
    mov   wc.hIconSm,0
    invoke LoadCursor,NULL,IDC_ARROW
    mov   wc.hCursor,eax
mov     width_w,200
mov   height_w,300
    invoke RegisterClassEx, addr wc
    INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
           WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
           CW_USEDEFAULT,width_w,height_w,NULL,NULL,\
           hInst,NULL
    mov   hwnd,eax
    INVOKE ShowWindow, hwnd,SW_SHOWNORMAL
    INVOKE UpdateWindow, hwnd
    .WHILE TRUE
                INVOKE GetMessage, ADDR msg,NULL,0,0
                .BREAK .IF (!eax)
                INVOKE TranslateMessage, ADDR msg
                INVOKE DispatchMessage, ADDR msg
    .ENDW
    mov     eax,msg.wParam
    ret
WinMain endp
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
    LOCAL hdc:HDC
    LOCAL ps:PAINTSTRUCT
    LOCAL rect:RECT
    .IF uMsg==WM_DESTROY
        invoke PostQuitMessage,NULL
    .ELSEIF uMsg==WM_PAINT
        invoke BeginPaint,hWnd, ADDR ps
        mov    hdc,eax
        invoke GetClientRect,hWnd, ADDR rect
        call    LTimep
        invoke DrawText, hdc,ADDR LTimeis,-1, ADDR rect, DT_SINGLELINE or DT_CENTER or DT_VCENTER
        invoke EndPaint,hWnd, ADDR ps
    .ELSE     
        invoke DefWindowProc,hWnd,uMsg,wParam,lParam
        ret
    .ENDIF       
    xor    eax,eax
    ret
WndProc endp

LTimep proc
    lea ebx,stime
    push ebx
    call GetLocalTime
     
    xor eax,eax
    mov al,byte ptr [ebx].stimestruct.wHour
    invoke crt__ultoa,eax,ADDR MyString,10

    mov ax,word ptr MyString
    mov word ptr HTime,ax
    cmp HTime+1,0
    jne next
    mov al,HTime
    xchg HTime+1,al
    mov HTime,' '
next: 
     
    xor eax,eax
    mov  al,byte ptr [ebx].stimestruct.wMinute
    invoke crt__ultoa,eax,ADDR MyString,10
     
     
    mov ax,word ptr MyString
    mov word ptr STime,ax
    cmp STime+1,0
    jne next2
    mov STime,al
next2:


    ret
LTimep endp   
end start

Title: Re: Display system time
Post by: MichaelW on December 21, 2011, 06:52:41 AM
To get the system time you need to call the  GetSystemTime (http://msdn.microsoft.com/en-us/library/windows/desktop/ms724390(v=vs.85).aspx) function. And to display your string in a message box you need to call the  MessageBox (http://msdn.microsoft.com/en-us/library/windows/desktop/ms645505(v=vs.85).aspx) function, passing the address of the string in the lpText parameter.
Title: Re: Display system time
Post by: bomz on December 21, 2011, 07:27:02 AM
.386

.model flat, stdcall
option casemap :none

include \MASM32\INCLUDE\windows.inc
include \MASM32\INCLUDE\user32.inc
include \MASM32\INCLUDE\kernel32.inc
includelib \MASM32\LIB\user32.lib
includelib \MASM32\LIB\kernel32.lib

.data
mestitle db "TIME",0
TimeHeader db '00-00-00-00-00-000',0

.data?
mytime SYSTEMTIME <>

.code
start:
invoke GetLocalTime, addr mytime
lea edi, TimeHeader+3
lea esi, mytime+6
mov ebx, 10
xor eax, eax

mov ax, word ptr[mytime+2]
div bl
add ax, 3030h
mov word ptr[TimeHeader], ax

mov ecx, 4
@@:
mov ax, [esi]
add esi, 2
div bl
add ax, 3030h
mov [edi], ax
add edi, 3
sub ecx, 1
jnz @B

mov ax, [esi]
div bl
add ah, 30h
mov [edi], ah
add edi, 1
xor ah, ah
div bl
add ax, 3030h
mov [edi], ax

invoke MessageBox,0,ADDR TimeHeader,ADDR mestitle,MB_ICONASTERISK
invoke ExitProcess,0
end start
Title: Re: Display system time
Post by: donkey on December 21, 2011, 07:32:53 AM
You can use GetTimeFormat if you want to avoid the extra step of converting to a string. Using NULL in place of the lpTime parameter will use the current time...

szTimeFormat DB "hh:mm tt",0 ; you can change this to whatever format you need
szTimeOut DB 64 DUP (?)

invoke GetTimeFormat,LOCALE_SYSTEM_DEFAULT,NULL,NULL,OFFSET szTimeFormat ,OFFSET szTimeOut,64


No need to get or translate the system time and it outputs in string format.

Edgar
Title: Re: Display system time
Post by: bomz on December 21, 2011, 07:36:15 AM
Quote.386

.model flat, stdcall
option casemap :none

include \MASM32\INCLUDE\windows.inc
include \MASM32\INCLUDE\DateTime.inc
include \MASM32\INCLUDE\user32.inc
include \MASM32\INCLUDE\kernel32.inc
includelib \MASM32\LIB\DateTime.lib
includelib \MASM32\LIB\user32.lib
includelib \MASM32\LIB\kernel32.lib

.data
mestitle db "TIME",0

.data?
buffer db 512 dup(?)
mytime SYSTEMTIME <>

.code
start:

invoke GetLocalTime, addr mytime
INVOKE DateTimeToDateString, addr mytime, addr buffer
INVOKE DateTimeToDateStringLong, addr mytime, addr buffer
invoke MessageBox,0,ADDR buffer,ADDR mestitle,MB_ICONASTERISK
invoke ExitProcess,0
end start
With year something strange. DateTime struc need ?
Title: Re: Display system time
Post by: donkey on December 21, 2011, 07:47:52 AM
BTW for the date you use GetDateFormat:

szDateFormat DB "dd MMM yyyy",0
szDateOut DB 64 DUP (?)

invoke GetDateFormat,LOCALE_SYSTEM_DEFAULT,NULL,NULL,OFFSET szDateFormat,OFFSET szDateOut,64


Current date direct to formatted string.

Putting them together:

szTimeFormat DB "hh:mm tt",0
szDateFormat DB "dd MMM yyyy, ",0
szDateOut DB 64 DUP (?)

invoke GetDateFormat,LOCALE_SYSTEM_DEFAULT,NULL,NULL,OFFSET szDateFormat,OFFSET szDateOut,64
invoke lstrlen,offset szDateOut
add eax,offset szDateOut
invoke GetTimeFormat,LOCALE_SYSTEM_DEFAULT,NULL,NULL,OFFSET szTimeFormat ,eax,64


The output is:

21 Dec 2011, 01:06 AM
Title: Re: Display system time
Post by: MichaelW on December 21, 2011, 08:27:08 AM
Edgar,

Passing NULL in the GetTimeFormat lpTime parameter will cause the function to use the current local time, not the system (UTC) time.


;==============================================================================
; BUILD AS CONSOLE APP.
;==============================================================================
include \masm32\include\masm32rt.inc
;==============================================================================

;-----------------------------------------------------
; This currently missing from the MASM32 windows.inc:
;-----------------------------------------------------

LOCALE_SYSTEM_DEFAULT equ 0800h

;==============================================================================
    .data
        systemtime SYSTEMTIME <>
        buffer     db 40 dup(0)
    .code
;==============================================================================
start:
;==============================================================================
    invoke GetLocalTime, ADDR systemtime

    invoke GetTimeFormat, LOCALE_SYSTEM_DEFAULT,
                          TIME_FORCE24HOURFORMAT,
                          ADDR systemtime,
                          chr$("hh:mm:ss"),
                          ADDR buffer,
                          40

    invoke MessageBox, 0, ADDR buffer, chr$("Local Time"), 0

    invoke GetTimeFormat, LOCALE_SYSTEM_DEFAULT,
                          TIME_FORCE24HOURFORMAT,
                          0,
                          chr$("hh:mm:ss"),
                          ADDR buffer,
                          40
    invoke MessageBox, 0, ADDR buffer, chr$("Local Time"), 0


    invoke GetSystemTime, ADDR systemtime

    invoke GetTimeFormat, LOCALE_SYSTEM_DEFAULT,
                          TIME_FORCE24HOURFORMAT,
                          ADDR systemtime,
                          chr$("hh:mm:ss"),
                          ADDR buffer,
                          40
                         
    invoke MessageBox, 0, ADDR buffer, chr$("System Time (UTC)"), 0
    exit
;==============================================================================
end start


Then again, maybe I'm using the wrong interpretation of "system time".
Title: Re: Display system time
Post by: majid1605 on December 21, 2011, 09:57:19 AM
Thank you friends
But i want use the following code

LTimep proc
    lea ebx,stime
    push ebx
    call GetLocalTime
     
    xor eax,eax
    mov al,byte ptr [ebx].stimestruct.wHour
    invoke crt__ultoa,eax,ADDR MyString,10

    mov ax,word ptr MyString
    mov word ptr HTime,ax
    cmp HTime+1,0
    jne next
    mov al,HTime
    xchg HTime+1,al
    mov HTime,' '
next:
     
    xor eax,eax
    mov  al,byte ptr [ebx].stimestruct.wMinute
    invoke crt__ultoa,eax,ADDR MyString,10
     
     
    mov ax,word ptr MyString
    mov word ptr STime,ax
    cmp STime+1,0
    jne next2
    mov STime,al
next2:


    ret
LTimep endp   
Title: Re: Display system time
Post by: dedndave on December 21, 2011, 02:49:10 PM
is that the complete code ?
show us the data declarations, please

you seem to have 2 different names for stime/stimestruct
also, if you are going to use EBX, it is standard practice to preserve it across the call
Title: Re: Display system time
Post by: GregL on December 21, 2011, 07:35:19 PM
Bomz,

If you want to use the DateTime library, you must use DateTime variables for the date and time. There is a help file in masm32\help and the source code is provided.
Title: Re: Display system time
Post by: bomz on December 21, 2011, 07:39:06 PM
Quote.386

.model flat, stdcall
option casemap :none

include \MASM32\INCLUDE\windows.inc
include \MASM32\INCLUDE\DateTime.inc
include \MASM32\INCLUDE\user32.inc
include \MASM32\INCLUDE\kernel32.inc
includelib \MASM32\LIB\DateTime.lib
includelib \MASM32\LIB\user32.lib
includelib \MASM32\LIB\kernel32.lib

.data
mestitle db "TIME",0

.data?
buffer db 512 dup(?)
mytime SYSTEMTIME <>

.code
start:

INVOKE GetLocalDateTime, addr mytime
INVOKE DateTimeToDateString, addr mytime, addr buffer
;INVOKE DateTimeToDateStringLong, addr mytime, addr buffer
invoke MessageBox,0,ADDR buffer,ADDR mestitle,MB_ICONASTERISK
invoke ExitProcess,0
end start
(http://smiles.kolobok.us/light_skin/thank_you2.gif)
Title: Re: Display system time
Post by: GregL on December 22, 2011, 12:03:12 AM
Bomz,

mytime should be a DateTime variable. It just happens a SYSTEMTIME is larger than a DateTime, so the program works.
Title: Re: Display system time
Post by: bomz on December 22, 2011, 07:05:13 AM
Quote.386
.model flat, stdcall
option casemap:none
include \MASM32\INCLUDE\windows.inc
include \MASM32\INCLUDE\kernel32.inc
includelib \MASM32\LIB\kernel32.lib
include \MASM32\INCLUDE\user32.inc
includelib \MASM32\LIB\user32.lib

.data
MsgCaption      db "TIME",0
form      db '%02hu-%02hu-%02hu-%02hu-%02hu-%03hu',0
mytime      SYSTEMTIME <>

.data?
Buffer      db 1024 dup (?)

.code
start:
   invoke GetSystemTime, addr mytime
   xor eax, eax
   mov ax, mytime.wMilliseconds
   movzx ebx, mytime.wSecond
   movzx ecx, mytime.wMinute
   movzx edx, mytime.wHour
   movzx edi, mytime.wDay
   movzx esi, mytime.wMonth
   invoke wsprintf,addr Buffer,addr form, esi, edi, edx, ecx, ebx, eax
   invoke MessageBox, NULL, addr Buffer, addr MsgCaption, MB_ICONASTERISK

   invoke ExitProcess,NULL
end start
Title: Re: Display system time
Post by: majid1605 on January 19, 2012, 08:08:02 PM
please tell me how use Macro for color and font size?

include \masm32\include\masm32rt.inc
LOCALE_SYSTEM_DEFAULT equ 0800h
RGB macro red,green,blue
        xor eax,eax
        mov ah,blue
        shl eax,8
        mov ah,green
        mov al,red
endm
    .data
        systemtime SYSTEMTIME <>
        buffer     db 40 dup(0)
    .code
start:
    invoke GetLocalTime, ADDR systemtime
    invoke GetTimeFormat, LOCALE_SYSTEM_DEFAULT,
                          TIME_FORCE24HOURFORMAT,
                          ADDR systemtime,
                          chr$("hh:mm:ss"),
                          ADDR buffer,
                          40
    invoke MessageBox, 0, ADDR buffer, chr$("System Time (UTC)"), 0
    exit
end start
Title: Re: Display system time
Post by: dedndave on January 19, 2012, 08:21:55 PM
with a message box, you cannot select font size or text colors
you will have to make a custom dialog box to do that

it is not necessary to put the RGB macro in your pogram
it is included with this line
include \masm32\include\masm32rt.inc
because that include file adds the macros.asm file
also, the RGB function can be better performed by simply adding values together - without generating any code
Title: Re: Display system time
Post by: GregL on January 20, 2012, 03:25:21 AM
majid1605,

Attached is a GUI example for you.

[Update] Reduced the size of the icon and thus the executable.


Title: Re: Display system time
Post by: majid1605 on January 20, 2012, 08:15:16 AM
Thank you :U
But i want use the MessageBox .
Is it possible to؟



Title: Re: Display system time
Post by: donkey on January 20, 2012, 09:52:47 AM
You can customize a messagebox to whatever degree you like by hooking it.

#DEFINE WINVER NTDDI_WINXP
#DEFINE CCUSEORDINALS

#include "WINDOWS.H"
#include "Commctrl.h"

DATA SECTION
hHook HANDLE ?

CODE SECTION
// set up the hook and call the MessageBox function
invoke GetCurrentThreadId
// WH_CALLWNDPROC will direct WndProc messages to the hook
invoke SetWindowsHookEx, WH_CALLWNDPROC, offset MsgBoxHookProc,0,eax
mov [hHook],eax
invoke MessageBox,NULL,"Hello",0,0

// The hook procedures

// The main hook procedure only processes 1 message, WM_INITDIALOG
// On receiving that message from the message box it subclasses the message
// box and allows you to process any messages you like.
MsgBoxHookProc FRAME nCode, wParam, lParam
uses edi

cmp D[nCode],HC_ACTION
jne >>.NEXTHOOK
mov edi,[lParam]
cmp D[edi+CWPSTRUCT.message],WM_INITDIALOG
jne >>
invoke SetWindowSubclass,[edi+CWPSTRUCT.hwnd],offset MsgBoxSubClass,1,0
:
.NEXTHOOK
invoke CallNextHookEx,[hHook],[nCode], [wParam], [lParam]
ret
endf

// Now the message box is redirecting all of its messages to a standard subclass
// Treat is as a normal dialog, you can paint it change the background etc...
// Be sure to unhook it when you recieve a WM_NCDESTROY notification
MsgBoxSubClass FRAME hwnd,uMsg, wParam, lParam, uIdSubclass, dwRefData

cmp D[uMsg],WM_NCDESTROY
jne >>.DEFPROC
invoke UnhookWindowsHookEx,[hHook]
.DEFPROC
invoke DefSubclassProc, [hwnd], [uMsg], [wParam], [lParam]
ret
endf


Hope this helps. I've attached a little sample, its kind of dumb but I wrote it on the fly to demonstrate how messagebox hooks work.

Edgar
Title: Re: Display system time
Post by: GregL on January 20, 2012, 07:15:01 PM
majid1605,

If you look at the code you will know how to set up time and date strings to use in a MessageBox.  From what everyone has shown you, you should be able to come up with exactly what you want.

Title: Re: Display system time
Post by: dedndave on January 20, 2012, 11:35:22 PM
i forgot all about hooking the MessageBox - lol
dammmm, i am getting old   :P

i have used the WH_CBT hook with MessageBox to alter the button text

here is a related article written in C for use with .NET
but, i am sure it can be ported
http://stackoverflow.com/questions/232066/messagebox-show-font-change

and another - no .NET
http://www.codeguru.com/cpp/w-p/win32/messagebox/article.php/c14605

i do see some potential problems with altering the font or size, however
the MessageBox dialog size is calculated based on the standard font
it isn't hard to create a scenario where the text is cropped off due to size
Title: Re: Display system time
Post by: majid1605 on January 22, 2012, 12:07:52 PM
Thank you
I think it is better  use the Windows window.I just do not know How do  change the colors and fonts.

.486
.model flat,stdcall
option casemap:none
 
     
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
 
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\msvcrt.inc ;crt__ultoa

includelib  \masm32\lib\user32.lib
includelib  \masm32\lib\kernel32.lib
includelib \masm32\lib\msvcrt.lib  ;crt__ultoa

RGB MACRO red,green,blue
    xor  eax,eax
    mov  ah,blue
    shl  eax,8
    mov  ah,green
    mov  al,red
ENDM
.data
ClassName db "SimpleWinClass",0
AppName  db "Local Time",0


MyString      DB 20 dup(' '),0

LTimeis     db "LocalTime is: "
HTime       DB   2 dup (' ')
SymTime     db ':'
STime       DB   2 dup (' ')
            db 0     


.data?

hInstance HINSTANCE ?
CommandLine LPSTR ?


width_w       dd ?
height_w   dd ?

stimestruct STRUCT     
       wYear            WORD ?   
       wMonth           WORD ?
       wDayOfWeek       WORD ?
       wDay             WORD ?
       wHour            WORD ?
       wMinute          WORD ?
       wSecond          WORD ?
       wMilliseconds    WORD ?
    stimestruct EndS   
    stime stimestruct {}
.code
start:
    invoke GetModuleHandle, NULL
    mov    hInstance,eax
    invoke GetCommandLine
    mov CommandLine,eax
    invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
    invoke ExitProcess,eax
WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,  CmdShow:DWORD
    LOCAL wc:WNDCLASSEX
    LOCAL msg:MSG
    LOCAL hwnd:HWND
    mov   wc.cbSize,SIZEOF WNDCLASSEX
    mov   wc.style, CS_HREDRAW or CS_VREDRAW
    mov   wc.lpfnWndProc, OFFSET WndProc
    mov   wc.cbClsExtra,NULL
    mov   wc.cbWndExtra,NULL
    push  hInst
    pop   wc.hInstance
    mov   wc.hbrBackground,COLOR_WINDOW+1
    mov   wc.lpszMenuName,NULL
    mov   wc.lpszClassName,OFFSET ClassName
    invoke LoadIcon,NULL,IDI_APPLICATION
    mov   wc.hIcon,eax
    mov   wc.hIconSm,0
    invoke LoadCursor,NULL,IDC_ARROW
    mov   wc.hCursor,eax
mov     width_w,300
mov   height_w,300
    invoke RegisterClassEx, addr wc
    INVOKE CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
           WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
           CW_USEDEFAULT,width_w,height_w,NULL,NULL,\
           hInst,NULL
    mov   hwnd,eax
    INVOKE ShowWindow, hwnd,SW_SHOWNORMAL
    INVOKE UpdateWindow, hwnd
    .WHILE TRUE
                INVOKE GetMessage, ADDR msg,NULL,0,0
                .BREAK .IF (!eax)
                INVOKE TranslateMessage, ADDR msg
                INVOKE DispatchMessage, ADDR msg
    .ENDW
    mov     eax,msg.wParam
    ret
WinMain endp
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
    LOCAL hdc:HDC
    LOCAL ps:PAINTSTRUCT
LOCAL hfont:HFONT
    LOCAL rect:RECT

    .IF uMsg==WM_DESTROY
        invoke PostQuitMessage,NULL
    .ELSEIF uMsg==WM_PAINT
        invoke BeginPaint,hWnd, ADDR ps
        mov    hdc,eax
        invoke GetClientRect,hWnd, ADDR rect
        call    LTimep
        invoke DrawText, hdc,ADDR LTimeis,-1, ADDR rect, DT_SINGLELINE or DT_CENTER or DT_VCENTER

  invoke EndPaint,hWnd, ADDR ps
    .ELSE     
        invoke DefWindowProc,hWnd,uMsg,wParam,lParam
        ret
    .ENDIF       
    xor    eax,eax
    ret
WndProc endp
LTimep proc
    lea ebx,stime
    push ebx
    call GetLocalTime
     
    xor eax,eax
    mov al,byte ptr [ebx].stimestruct.wHour
    invoke crt__ultoa,eax,ADDR MyString,10

    mov ax,word ptr MyString
    mov word ptr HTime,ax
    cmp HTime+1,0
    jne next
    mov al,HTime
    xchg HTime+1,al
    mov HTime,' '
next: 
    xor eax,eax
    mov  al,byte ptr [ebx].stimestruct.wMinute
    invoke crt__ultoa,eax,ADDR MyString,10
    mov ax,word ptr MyString
    mov word ptr STime,ax
    cmp STime+1,0
    jne next2
    mov STime,al
next2:
    ret
LTimep endp   
end start
Title: Re: Display system time
Post by: GregL on January 23, 2012, 01:07:05 AM
majid1605,

Did you look at my code? It does both, and in a window.

Title: Re: Display system time
Post by: dedndave on January 23, 2012, 02:35:31 AM
i like it, Greg   :U

except, the icon is a bit big
icon ~ 160 Kb
rest of it ~ 4 Kb   :P

at any rate, it is a nice example for several concepts
Title: Re: Display system time
Post by: GregL on January 23, 2012, 07:18:32 PM
Dave,

Thanks. The icon contains several sizes and color resolutions, that's why it is so large.  It probably doesn't need so many. In these days of terabyte drives, I'm not too concerned about 100 Kb :wink.  I have a similar program that displays UTC time that's not much use to the average person, but it's really handy for amateur radio.
Title: Re: Display system time
Post by: dedndave on January 23, 2012, 07:28:12 PM
didn't know you were a ham - or i knew and had forgotten (a common occurance, lately)
K7NL, here
Title: Re: Display system time
Post by: GregL on January 23, 2012, 07:34:17 PM
Dave,

Cool.  My call is N7YAP, I'm a General. I keep meaning to get the Extra but haven't yet.

Title: Re: Display system time
Post by: dedndave on January 23, 2012, 08:03:15 PM
wow - that looks like a great QTH   :U
in case you forget...
you expire in April   :P

i got may advanced when i was a teenager
and, could have easily passed the extra - but lost interest for a little while - then went into the army
finally got around to upgrading in about 1980 or so, some 15 years later - lol
it was harder back in the old days - now, it's not so bad
back then, we had to go to an FCC examination point (field office) to take the test
when i took my advanced, i signed up to take the extra - passed the code part
my examiner was W8DX - Dick Cotton - the OM, himself
i was nervous - but i used a hand-key and tapped out 20   :P
i remember that day pretty well
when he came into the room, he said, "The guy that usually does this is sick today, so you're stuck with me."
Title: Re: Display system time
Post by: GregL on January 24, 2012, 08:58:52 PM
Quote from: dedndavewow - that looks like a great QTH
It rains a lot here, eastern Washington is dryer and sunnier, I grew up over there and prefer that climate to this.  On the other hand, when it's sunny here it's beautiful.

Quote from: dedndaveyou expire in April
I just renewed online yesterday, I hit the 90 days on Sunday. :P

I did pass the code test (13 WPM) when I got my General.  Yes, it is a lot easier now without the code tests.  I imagine it was pretty tough back when you took the Extra test.

I attached the UTC clock program.
Title: Re: Display system time
Post by: dedndave on January 24, 2012, 11:38:44 PM
thanks   :U