Textbox,bouton,timer masm32

Contenu du snippet

Bonjour a tous, ce code permet de voir,comment on peut gerer un evenement,
lorsque l'on appuie sur un bouton.
En clair, parce que la... Vous saississez du texte, vous pressez le bouton...
Et MAGIC, ca fais du bruit, et vous avez un message.
Conclusion:
Ce code a des fonctions simples a comprendre,comment par
exemple,l'utilisation d' un timer.
Ce code n'est pas destiné aux experts, mais au simple débutant, qui desire
apprendre.
Je ne detaillerais rien, car il y a beaucoup de renseignement sur le Web,qui
vous permet de trouver votre reponse..Pareil pour les troubles du comportement.
:-)
http://trans.voila.fr/ <--- un site de traduction,comme par hazard!!
Bon Coding!

Source / Exemple :


.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
include \MASM32\INCLUDE\gdi32.inc
includelib \MASM32\LIB\gdi32.lib
      
EditSl PROTO  :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
  PushButton PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD

      szText MACRO Name, Text:VARARG
        LOCAL lbl
          jmp lbl
            Name db Text,0
          lbl:
        ENDM

  

      m2m MACRO M1, M2
        push M2
        pop  M1
      ENDM

      return MACRO arg
        mov eax, arg
        ret
      ENDM

WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
TopXY PROTO   :DWORD,:DWORD

    .data
 adrTxt db 0
Moment db 0
szDisplayName db "Vv@20oX",0
        CommandLine   dd 0
        hWnd          dd 0
        hInstance     dd 0
     btnClass  db "BUTTON",0
hFont         dd 0
 hEdit1        dd 0

.DATA?
Buffer db 256 dup(?)

    .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     :DWORD,
             hPrevInst :DWORD,
             CmdLine   :DWORD,
             CmdShow   :DWORD

    
        LOCAL wc   :WNDCLASSEX
        LOCAL msg  :MSG

        LOCAL Wwd  :DWORD
        LOCAL Wht  :DWORD
        LOCAL Wtx  :DWORD
        LOCAL Wty  :DWORD

        szText szClassName,"Vv@20o3Class32"

       

        mov wc.cbSize,         sizeof WNDCLASSEX
        mov wc.style,          CS_HREDRAW or CS_VREDRAW                                or CS_BYTEALIGNWINDOW
        mov wc.lpfnWndProc,    offset WndProc      ; address of WndProc
        mov wc.cbClsExtra,     NULL
        mov wc.cbWndExtra,     NULL
        m2m wc.hInstance,      hInst               ; instance handle
        mov wc.hbrBackground,  COLOR_BTNFACE+1     ; system color
        mov wc.lpszMenuName,   NULL
        mov wc.lpszClassName,  offset szClassName  ; window class name
          invoke LoadIcon,hInst,500    ; icon ID   ; resource icon
        mov wc.hIcon,          eax
          invoke LoadCursor,NULL,IDC_ARROW         ; system cursor
        mov wc.hCursor,        eax
        mov wc.hIconSm,        0

        invoke RegisterClassEx, ADDR wc     ; register the window class

        mov Wwd, 200
        mov Wht, 150

        invoke GetSystemMetrics,SM_CXSCREEN ; get screen width in pixels
        invoke TopXY,Wwd,eax
        mov Wtx, eax

        invoke GetSystemMetrics,SM_CYSCREEN ; get screen height in pixels
        invoke TopXY,Wht,eax
        mov Wty, eax

       
        invoke CreateWindowEx,WS_EX_OVERLAPPEDWINDOW,
                              ADDR szClassName,
                              ADDR szDisplayName,
                              WS_OVERLAPPEDWINDOW,
                              Wtx,Wty,Wwd,Wht,
                              NULL,NULL,
                              hInst,NULL

        mov   hWnd,eax  ; copy return value into handle DWORD

     

        invoke ShowWindow,hWnd,SW_SHOWNORMAL      ; display the window
        invoke UpdateWindow,hWnd                  ; update the display

    StartLoop:
      invoke GetMessage,ADDR msg,NULL,0,0         ; get each message
      cmp eax, 0                                  ; exit if GetMessage()
      je ExitLoop                                 ; returns zero
      invoke TranslateMessage, ADDR msg           ; translate it
      invoke DispatchMessage,  ADDR msg           ; send it to message proc
      jmp StartLoop
    ExitLoop:

      return msg.wParam

WinMain endp

WndProc proc hWin   :DWORD,
             uMsg   :DWORD,
             wParam :DWORD,
             lParam :DWORD

    .if uMsg == WM_COMMAND

    
        .if wParam == 600

           invoke SendMessage,hEdit1,WM_GETTEXT,sizeof Buffer,ADDR Buffer
           invoke MessageBox,hWin,ADDR Buffer,ADDR szDisplayName,0
           Invoke SetTimer,hWin,0,1500, 0

        .endif
   
    .elseif uMsg == WM_CREATE

szText font1,"Lucida Console"
invoke CreateFont,13,5,0,0,500,0,0,0,                           DEFAULT_CHARSET,0,0,0,                          DEFAULT_PITCH,ADDR font1
        mov hFont, eax

invoke EditSl,ADDR adrTxt,10,10,170,20,hWin,700
mov hEdit1, eax
invoke PushButton,ADDR btnClass,hWin,50,40,80,25,600
 

    .elseif uMsg == WM_CLOSE
    
        szText TheText,"Please Confirm Exit"
        invoke MessageBox,hWin,ADDR TheText,ADDR szDisplayName,MB_YESNO
          .if eax == IDNO
            return 0
          .endif

    .elseif uMsg == WM_DESTROY
   
        invoke PostQuitMessage,NULL
        return 0 
    .endif

.if uMsg == WM_TIMER
   
    							
.if Moment == 0									
invoke Beep,200,20
mov Moment,2
.else
Mov Moment,0
invoke Beep,500,30

.endif
						
    

.endif

    invoke DefWindowProc,hWin,uMsg,wParam,lParam

    ret

WndProc endp

TopXY proc wDim:DWORD, sDim:DWORD

  
    shr sDim, 1      ; divide screen dimension by 2
    shr wDim, 1      ; divide window dimension by 2
    mov eax, wDim    ; copy window dimension into eax
    sub sDim, eax    ; sub half win dimension from half screen dimension

    return sDim

TopXY endp

EditSl proc szMsg:DWORD,a:DWORD,b:DWORD,
               wd:DWORD,ht:DWORD,hParent:DWORD,ID:DWORD

    LOCAL hndle:DWORD

    szText slEdit,"EDIT"

    invoke CreateWindowEx,WS_EX_CLIENTEDGE,ADDR slEdit,szMsg,
                WS_VISIBLE or WS_CHILDWINDOW or                 ES_AUTOHSCROLL or ES_NOHIDESEL,
              a,b,wd,ht,hParent,ID,hInstance,NULL

    mov hndle, eax

    invoke SendMessage,hndle,WM_SETFONT,hFont,1

    mov eax, hndle

    ret

EditSl endp

PushButton proc lpText:DWORD,hParent:DWORD,a:DWORD,b:DWORD,wd:DWORD,ht:DWORD,ID:DWORD
    invoke CreateWindowEx,0,
            ADDR btnClass,lpText,
            WS_CHILD or WS_VISIBLE,
            a,b,wd,ht,hParent,ID,
            hInstance,NULL

    ret

PushButton endp
end start

Conclusion :


C'est beau, c'est neuf et ca brille.
Ce programme n'est vraiment pas compliqué.
Bon coding,que la patience soient avec vous!

A voir également

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.