Une autre façon plus ou moins originale d'affichage de l'heure réelle et de la date en utilisant des images Bitmap.
Source / Exemple :
.586
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
DlgProc PROTO :HWND,:UINT,:WPARAM,:LPARAM
BmpButton PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
FaitChiffre PROTO :DWORD
.data
forme db "HH:mm:ss",0
buffer db 20 dup (0)
imgButton db "BUTTON",0
txtStatic db "STATIC",0
format db "dddd dd MMMM yyyy",0
buff db 27 dup (0)
.data?
hInstance dd ?
hTimer dd ?
hBtn0 dd ?
hBtn1 dd ?
hBtn2 dd ?
hBtn3 dd ?
hBtn4 dd ?
hBtn5 dd ?
hBtn6 dd ?
hBtn7 dd ?
hBmp0 dd ?
hBmp1 dd ?
hBmp2 dd ?
hBmp3 dd ?
hBmp4 dd ?
hBmp5 dd ?
hBmp6 dd ?
hBmp7 dd ?
hBmp8 dd ?
hBmp9 dd ?
hBmp10 dd ?
.code
start:
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance,100,NULL,addr DlgProc,NULL
invoke ExitProcess,NULL
DlgProc proc hWnd :HWND,uMsg :UINT,wParam :WPARAM,lParam :LPARAM
.if uMsg == WM_INITDIALOG
;*********************************************************
; Recherche de la date et du jour (en clair et en entier)
;*********************************************************
invoke GetDateFormat,0,0,0,addr format,addr buff,27
;*****************************************
; création du static affichant cette date
;*****************************************
invoke CreateWindowEx,WS_EX_CLIENTEDGE,addr txtStatic,addr buff,
SS_CENTER or WS_VISIBLE or WS_CHILD,
5,5,400,20,hWnd,300,hInstance,0
;**********************************************************
; on lance le timer qui se déclenchera toutes les secondes
;**********************************************************
invoke SetTimer,hWnd,200,1000,NULL
mov hTimer,eax
;***************************************************************************
; Charger toutes les images.Impossible de charger une image portant le N° 0
; donc elles seront numérotées de 10 à 20 (chiffres de 0 à 9 + :)
;***************************************************************************
invoke LoadImage,hInstance,10,IMAGE_BITMAP,0,0,
LR_LOADTRANSPARENT or LR_LOADMAP3DCOLORS
mov hBmp0,eax
invoke LoadImage,hInstance,11,IMAGE_BITMAP,0,0,
LR_LOADTRANSPARENT or LR_LOADMAP3DCOLORS
mov hBmp1,eax
invoke LoadImage,hInstance,12,IMAGE_BITMAP,0,0,
LR_LOADTRANSPARENT or LR_LOADMAP3DCOLORS
mov hBmp2,eax
invoke LoadImage,hInstance,13,IMAGE_BITMAP,0,0,
LR_LOADTRANSPARENT or LR_LOADMAP3DCOLORS
mov hBmp3,eax
invoke LoadImage,hInstance,14,IMAGE_BITMAP,0,0,
LR_LOADTRANSPARENT or LR_LOADMAP3DCOLORS
mov hBmp4,eax
invoke LoadImage,hInstance,15,IMAGE_BITMAP,0,0,
LR_LOADTRANSPARENT or LR_LOADMAP3DCOLORS
mov hBmp5,eax
invoke LoadImage,hInstance,16,IMAGE_BITMAP,0,0,
LR_LOADTRANSPARENT or LR_LOADMAP3DCOLORS
mov hBmp6,eax
invoke LoadImage,hInstance,17,IMAGE_BITMAP,0,0,
LR_LOADTRANSPARENT or LR_LOADMAP3DCOLORS
mov hBmp7,eax
invoke LoadImage,hInstance,18,IMAGE_BITMAP,0,0,
LR_LOADTRANSPARENT or LR_LOADMAP3DCOLORS
mov hBmp8,eax
invoke LoadImage,hInstance,19,IMAGE_BITMAP,0,0,
LR_LOADTRANSPARENT or LR_LOADMAP3DCOLORS
mov hBmp9,eax
invoke LoadImage,hInstance,20,IMAGE_BITMAP,0,0,
LR_LOADTRANSPARENT or LR_LOADMAP3DCOLORS
mov hBmp10,eax;
;*****************************************************************
; Si vous préférez LoadBitmap à LoadImage, neutralisez les lignes
; précédentes avec des points virgule et supprimez ceux qui sont
; devant les suivantes, le résultat final est identique.
;*****************************************************************
; invoke LoadBitmap,hInstance,10
; mov hBmp0,eax
; invoke LoadBitmap,hInstance,11
; mov hBmp1,eax
; invoke LoadBitmap,hInstance,12
; mov hBmp2,eax
; invoke LoadBitmap,hInstance,13
; mov hBmp3,eax
; invoke LoadBitmap,hInstance,14
; mov hBmp4,eax
; invoke LoadBitmap,hInstance,15
; mov hBmp5,eax
; invoke LoadBitmap,hInstance,16
; mov hBmp6,eax
; invoke LoadBitmap,hInstance,17
; mov hBmp7,eax
; invoke LoadBitmap,hInstance,18
; mov hBmp8,eax
; invoke LoadBitmap,hInstance,19
; mov hBmp9,eax
; invoke LoadBitmap,hInstance,20
; mov hBmp10,eax
;***********************************
; créer les 7 emplacements (boutons)
;***********************************
invoke BmpButton,hWnd,5,30,50,100,400
mov hBtn0,eax
invoke BmpButton,hWnd,55,30,50,100,401
mov hBtn1,eax
invoke BmpButton,hWnd,105,30,50,100,402
mov hBtn2,eax
invoke BmpButton,hWnd,155,30,50,100,403
mov hBtn3,eax
invoke BmpButton,hWnd,205,30,50,100,404
mov hBtn4,eax
invoke BmpButton,hWnd,255,30,50,100,405
mov hBtn5,eax
invoke BmpButton,hWnd,305,30,50,100,406
mov hBtn6,eax
invoke BmpButton,hWnd,355,30,50,100,407
mov hBtn7,eax
;***********************************************
; Charger les 2 points sur les boutons 2 et 5
;***********************************************
invoke SendMessage,hBtn2,BM_SETIMAGE,0,hBmp10
invoke SendMessage,hBtn5,BM_SETIMAGE,0,hBmp10
.elseif uMsg == WM_COMMAND
;********************************************
; bouton Quitter,on stoppe le timer et on sort
;********************************************
.if wParam == 1001
invoke KillTimer,hWnd,hTimer
invoke EndDialog,hWnd,NULL
.endif
.elseif uMsg == WM_CLOSE
;********************************************
; même traitement si on a cliqué sur la croix
; en haut , à droite.
;********************************************
invoke KillTimer,hWnd,hTimer
invoke EndDialog,hWnd,NULL
.elseif uMsg == WM_TIMER
;********************************************************************
; toutes les secondes récupération de l'heure locale en chiffres
; décimaux dans le buffer,sélection du chiffre a afficher sur
; chaque bouton en fonction des chiffres réels se trouvant dans
; chaque case du tableau buffer et affichage.
;********************************************************************
invoke GetTimeFormat,LOCALE_USER_DEFAULT,TIME_FORCE24HOURFORMAT,NULL,
addr forme,addr buffer,20
invoke FaitChiffre,buffer[7]
invoke SendMessage,hBtn7,BM_SETIMAGE,0, [eax]
invoke FaitChiffre,buffer[6]
invoke SendMessage,hBtn6,BM_SETIMAGE,0, [eax]
invoke FaitChiffre,buffer[4]
invoke SendMessage,hBtn4,BM_SETIMAGE,0, [eax]
invoke FaitChiffre,buffer[3]
invoke SendMessage,hBtn3,BM_SETIMAGE,0, [eax]
invoke FaitChiffre,buffer[1]
invoke SendMessage,hBtn1,BM_SETIMAGE,0, [eax]
invoke FaitChiffre,buffer[0]
invoke SendMessage,hBtn0,BM_SETIMAGE,0, [eax]
.endif
xor eax,eax
ret
DlgProc endp
;**********************************************************
BmpButton proc hParent :DWORD,a :DWORD,b :DWORD,wd :DWORD,ht :DWORD,id :DWORD
invoke CreateWindowEx,0,addr imgButton,0,WS_CHILD or WS_VISIBLE or\
BS_BITMAP,a,b,wd,ht,hParent,id,hInstance,NULL
ret
BmpButton endp
;*****************************************
FaitChiffre proc Case :dword
mov cl,4
mov eax,Case ; chiffre se trouvant dans buffer[x]
sub al,30h ; transformation en décimal
mul cl
add eax,offset hBmp0 ; en partant de la base on est sur la bonne adresse
ret
FaitChiffre endp
;******************************************
end start
;******************************************
500 ICON MOVEABLE PURE LOADONCALL DISCARDABLE "\masm32\en_cours\icones\ie.ico"
#include "\masm32\include\resource.h"
10 BITMAP MOVEABLE PURE LOADONCALL DISCARDABLE "Images\Image0.bmp"
11 BITMAP MOVEABLE PURE LOADONCALL DISCARDABLE "Images\Image1.bmp"
12 BITMAP MOVEABLE PURE LOADONCALL DISCARDABLE "Images\Image2.bmp"
13 BITMAP MOVEABLE PURE LOADONCALL DISCARDABLE "Images\Image3.bmp"
14 BITMAP MOVEABLE PURE LOADONCALL DISCARDABLE "Images\Image4.bmp"
15 BITMAP MOVEABLE PURE LOADONCALL DISCARDABLE "Images\Image5.bmp"
16 BITMAP MOVEABLE PURE LOADONCALL DISCARDABLE "Images\Image6.bmp"
17 BITMAP MOVEABLE PURE LOADONCALL DISCARDABLE "Images\Image7.bmp"
18 BITMAP MOVEABLE PURE LOADONCALL DISCARDABLE "Images\Image8.bmp"
19 BITMAP MOVEABLE PURE LOADONCALL DISCARDABLE "Images\Image9.bmp"
20 BITMAP MOVEABLE PURE LOADONCALL DISCARDABLE "Images\Image10.bmp"
100 DIALOGEX 0, 0, 205,82,0
STYLE DS_MODALFRAME | DS_3DLOOK | DS_CENTER | WS_CAPTION | WS_SYSMENU | WS_POPUP
CAPTION " Voici la date et l'heure"
FONT 12, "Monotype Corsiva",800,1 /*TRUE(Italique)*/
BEGIN
DEFPUSHBUTTON "Quitter.", 1001, 80,60,50,20 ,SS_SUNKEN
END
Conclusion :
La fonction LoadBitmap aurait pi être utilisée en lieu et place de LoadImage puisque ces deux fonctions renvoient le handle du Bitmap indiqué.
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.