News:

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

Display system time

Started by majid1605, December 20, 2011, 07:11:14 PM

Previous topic - Next topic

GregL

#15
majid1605,

Attached is a GUI example for you.

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



majid1605

Thank you :U
But i want use the MessageBox .
Is it possible to؟




donkey

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
"Ahhh, what an awful dream. Ones and zeroes everywhere...[shudder] and I thought I saw a two." -- Bender
"It was just a dream, Bender. There's no such thing as two". -- Fry
-- Futurama

Donkey's Stable

GregL

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.


dedndave

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

majid1605

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

GregL

majid1605,

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


dedndave

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

GregL

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.

dedndave

didn't know you were a ham - or i knew and had forgotten (a common occurance, lately)
K7NL, here

GregL

Dave,

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


dedndave

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."

GregL

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.

dedndave