begin process at 2010 03 19 05:25:26
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Applications Windows

 > FENÊTRE WIDOWS (NASM)

FENÊTRE WIDOWS (NASM)


 Description

Encor un coup de pousse pour les programmer sous nasm. Je sais qu'il y a déjà un exemple mais celui si un peu différents : pur assembleur
En plus il y a une petite gestion des erreures!
TRAX

Source

  • [EXTERN MessageBoxA]
  • [import MessageBoxA user32.dll]
  • [EXTERN ExitProcess]
  • [import ExitProcess kernel32.dll]
  • [EXTERN CreateWindowExA]
  • [import CreateWindowExA user32.dll]
  • [extern GetModuleHandleA]
  • [import GetModuleHandleA kernel32.dll]
  • [extern GetCommandLineA]
  • [import GetCommandLineA kernel32.dll]
  • [EXTERN RegisterClassExA]
  • [import RegisterClassExA user32.dll]
  • [EXTERN ShowWindow]
  • [import ShowWindow user32.dll]
  • [EXTERN LoadIconA]
  • [import LoadIconA user32.dll]
  • [EXTERN LoadCursorA]
  • [import LoadCursorA user32.dll]
  • [EXTERN DefWindowProcA]
  • [import DefWindowProcA user32.dll]
  • [EXTERN PostQuitMessage]
  • [import PostQuitMessage user32.dll]
  • [EXTERN TranslateMessage]
  • [import TranslateMessage user32.dll]
  • [EXTERN DispatchMessageA]
  • [import DispatchMessageA user32.dll]
  • [EXTERN GetMessageA]
  • [import GetMessageA user32.dll]
  • [EXTERN CreateFontIndirectA]
  • [import CreateFontIndirectA gdi32.dll]
  • [EXTERN DeleteObject]
  • [import DeleteObject gdi32.dll]
  • [EXTERN PostMessageA]
  • [import PostMessageA user32.dll]
  • ;_______________________________________________
  • [SECTION CODE USE32 CLASS=CODE]
  • ..start:
  • push dword 00h ; null
  • call [GetModuleHandleA]
  • mov dword [instance], eax
  • Call [GetCommandLineA]
  • mov dword [commandline], eax
  • push dword 0Ah ; SW_SHOW
  • push dword eax
  • push dword 00h ; null
  • push dword [instance]
  • call WinMain
  • push dword eax
  • call [ExitProcess]
  • ;************************************************
  • ;* winMain *
  • ;************************************************
  • ;%define hInstance ebp+8
  • ;%define hPrevInstance ebp+12
  • ;%define lpCmdLine ebp+16
  • ;%define nCmdShow ebp+20
  • WinMain:
  • enter 0,0
  • mov dword [winclass+0], 30h ; 48(d)
  • mov dword [winclass+4], 03h ; CS_HREDRAW | CS_VREDRAW
  • mov dword [winclass+8], WinProc
  • mov dword [winclass+12], 0
  • mov dword [winclass+16], 0
  • mov eax, dword [instance]
  • mov dword [winclass+20], eax
  • push word 0
  • push word 101
  • mov eax, dword [instance]
  • push dword eax
  • call [LoadIconA]
  • mov dword [winclass+24], eax
  • mov dword [winclass+44], eax
  • push dword 07F00h ; IDC_ARROW
  • push dword 00h ; NULL
  • call [LoadCursorA]
  • mov dword [winclass+28], eax
  • mov dword [winclass+32], 10h ; background COLOR_BTNFACE+1
  • mov dword [winclass+36], 00h ; (MenuName)
  • mov dword [winclass+40], nomclass
  • push dword winclass
  • call [RegisterClassExA]
  • cmp eax,0
  • jne RegisterOk
  • push dword 00h
  • push dword message1
  • push dword message2
  • push dword 00h
  • call [MessageBoxA]
  • push word 00h
  • call [ExitProcess]
  • RegisterOk:
  • mov dword [atom], eax
  • push dword 00h ; null
  • mov eax, dword [instance]
  • push dword eax
  • push dword 00h ; null
  • push dword 00h ; null
  • push dword 500 ; Wigth
  • push dword 500 ; Height
  • push dword 20 ; Left
  • push dword 20 ; Top
  • push dword 00CF0000h ; WS_TILEDWINDOW
  • push dword nom
  • push dword nomclass
  • push dword 00h ; WS_EX_LEFT
  • call [CreateWindowExA]
  • cmp eax , 0
  • jne CreateWindowOk
  • push dword 00h
  • push dword message1
  • push dword message3
  • push dword 00h
  • call [MessageBoxA]
  • push word 00h
  • call [ExitProcess]
  • CreateWindowOk:
  • mov dword [handle], eax
  • push dword 5h ; SW_SHOW
  • push dword [handle]
  • call [ShowWindow]
  • BoucleMessages:
  • push dword 0
  • push dword 0
  • push dword [handle]
  • push dword msg1
  • call [GetMessageA]
  • cmp eax, 12h ; WM_QUIT
  • je FinBoucle
  • cmp eax, -1
  • jne GetMEssageOk
  • push dword 00h
  • push dword message1
  • push dword message4
  • push dword 00h
  • call [MessageBoxA]
  • push word 00h
  • call [ExitProcess]
  • GetMEssageOk:
  • push dword msg1
  • call [TranslateMessage]
  • push dword msg1
  • call [DispatchMessageA]
  • jmp BoucleMessages
  • FinBoucle:
  • mov eax, dword [msg1+8] ; ????????????????????????? wParam
  • Fin:
  • leave
  • ret 16
  • ;*********************************************
  • ;* WindowProc *
  • ;*********************************************
  • %define hwnd ebp+8
  • %define uMsg ebp+12
  • %define wParam ebp+16
  • %define lParam ebp+20
  • WinProc:
  • enter 0,0
  • mov eax,[uMsg]
  • cmp eax,01b
  • je near Create
  • cmp eax,10b
  • je near Destroy
  • Defaut:
  • push dword [lParam]
  • push dword [wParam]
  • push dword [uMsg]]
  • push dword [hwnd]
  • call [DefWindowProcA]
  • Fin2:
  • leave
  • ret 16
  • Create: ;**************************************
  • push dword FontStandard
  • call [CreateFontIndirectA]
  • mov dword [hFontStandard], eax
  • jmp Fin2
  • Destroy: ;*************************************
  • push dword [hFontStandard]
  • call [DeleteObject]
  • jmp Fin2
  • ;_______________________________________________
  • ; Procedures et fonctions secondaires
  • ;_______________________________________________
  • ;Procedure qui assigne une font standard à un contrôle
  • ; Param : Handle du contrôle dans eax
  • SetFontStandard:
  • push dword 01b
  • push dword [hFontStandard]
  • push dword 30h
  • push dword eax
  • call [PostMessageA]
  • ret
  • ;_______________________________________________
  • [SECTION DATA USE32 CLASS=DATA]
  • ; Données
  • ;_______________________________________________
  • instance resd 1
  • commandline resd 1
  • winclass resd 12
  • atom resd 1
  • handle resd 1
  • msg1 resd 9
  • nomclass db "WindowClass01",0
  • nom db "premiere fenetre window",0
  • message1 db "Erreur !",0
  • message2 db "Première erreur !",0
  • message3 db "Deuxsième erreur !",0
  • message4 db "Bye !",0
  • FontStandard dd 10
  • resd 6
  • db "MS sans Serif",0
  • hFontStandard resd 1
  • ;_______________________________________________
[EXTERN MessageBoxA]	
[import MessageBoxA user32.dll]

[EXTERN ExitProcess]
[import ExitProcess kernel32.dll]
[EXTERN CreateWindowExA]
[import CreateWindowExA user32.dll]
[extern GetModuleHandleA]
[import GetModuleHandleA kernel32.dll]
[extern GetCommandLineA]
[import GetCommandLineA kernel32.dll]
[EXTERN RegisterClassExA]
[import RegisterClassExA user32.dll]
[EXTERN ShowWindow]
[import ShowWindow user32.dll]
[EXTERN LoadIconA]
[import LoadIconA user32.dll]
[EXTERN LoadCursorA]
[import LoadCursorA user32.dll]
[EXTERN DefWindowProcA]
[import DefWindowProcA user32.dll]
[EXTERN PostQuitMessage]
[import PostQuitMessage user32.dll]
[EXTERN TranslateMessage]
[import TranslateMessage user32.dll]
[EXTERN DispatchMessageA]
[import DispatchMessageA user32.dll]
[EXTERN GetMessageA]
[import GetMessageA user32.dll]
[EXTERN CreateFontIndirectA]
[import CreateFontIndirectA gdi32.dll]
[EXTERN DeleteObject]
[import DeleteObject gdi32.dll]
[EXTERN PostMessageA]
[import PostMessageA user32.dll]
;_______________________________________________
  
[SECTION CODE USE32 CLASS=CODE]
  
..start:

push dword 00h				; null
call [GetModuleHandleA]
mov dword [instance], eax

Call [GetCommandLineA]
mov dword [commandline], eax

push dword 0Ah				; SW_SHOW
push dword eax
push dword 00h				; null
push dword [instance]
call WinMain

push dword eax
call [ExitProcess]


;************************************************
;*	             winMain			*
;************************************************
;%define hInstance 	ebp+8
;%define hPrevInstance	ebp+12
;%define lpCmdLine	ebp+16
;%define nCmdShow	ebp+20

	WinMain:
  enter 0,0
mov dword [winclass+0], 30h					; 48(d)
mov dword [winclass+4], 03h					; CS_HREDRAW | CS_VREDRAW	
mov dword [winclass+8], WinProc
mov dword [winclass+12], 0
mov dword [winclass+16], 0
mov eax, dword [instance]
mov dword [winclass+20], eax

push word 0
push word 101
mov eax, dword [instance]
push dword eax
call [LoadIconA]
mov dword [winclass+24], eax
mov dword [winclass+44], eax

push dword 07F00h									; IDC_ARROW
push dword 00h									; NULL
call [LoadCursorA]
mov dword [winclass+28], eax

mov dword [winclass+32], 10h						; background COLOR_BTNFACE+1
mov dword [winclass+36], 00h						; (MenuName)
mov dword [winclass+40], nomclass

push dword winclass
call [RegisterClassExA]

cmp eax,0
jne RegisterOk

push dword 00h
push dword message1
push dword message2
push dword 00h
call [MessageBoxA]

push word 00h
call [ExitProcess]



 RegisterOk:

mov dword [atom], eax

push dword 00h							; null
mov eax, dword [instance]
push dword eax
push dword 00h							; null
push dword 00h							; null
push dword 500 							; Wigth
push dword 500 							; Height
push dword 20 							; Left
push dword 20 							; Top
push dword 00CF0000h						; WS_TILEDWINDOW
push dword nom
push dword nomclass
push dword 00h							; WS_EX_LEFT
call [CreateWindowExA]

cmp eax , 0
jne CreateWindowOk


push dword 00h
push dword message1
push dword message3
push dword 00h
call [MessageBoxA]

push word 00h
call [ExitProcess]


 CreateWindowOk:

mov dword [handle], eax

push dword 5h								; SW_SHOW
push dword [handle]
call [ShowWindow] 

 BoucleMessages:

push dword 0
push dword 0
push dword [handle]
push dword msg1
call [GetMessageA]

cmp eax, 12h 								; WM_QUIT
je FinBoucle 

cmp eax, -1
jne GetMEssageOk


push dword 00h
push dword message1
push dword message4
push dword 00h
call [MessageBoxA]

push word 00h
call [ExitProcess]

  GetMEssageOk:

push dword msg1
call [TranslateMessage]
push dword msg1
call [DispatchMessageA]

jmp BoucleMessages

 FinBoucle:
mov eax, dword [msg1+8]			; ????????????????????????? wParam

 Fin:
  leave
	ret 16

;*********************************************
;*	        WindowProc		     *
;*********************************************
%define hwnd 	ebp+8
%define uMsg 	ebp+12
%define wParam	ebp+16
%define lParam	ebp+20

	WinProc:
  enter 0,0
mov eax,[uMsg]

cmp eax,01b
je near Create  
cmp eax,10b
je near Destroy

 Defaut:
push dword  [lParam]
push dword   [wParam] 
push dword   [uMsg]]
push dword   [hwnd]
call [DefWindowProcA]

 Fin2:
    leave
	ret 16

 Create: ;**************************************
push dword FontStandard
call [CreateFontIndirectA]
mov dword [hFontStandard], eax

 jmp Fin2

 Destroy: ;*************************************
push dword [hFontStandard]
call [DeleteObject] 
 jmp Fin2
;_______________________________________________

  
  ; Procedures et fonctions secondaires
;_______________________________________________

 ;Procedure qui assigne une font standard à un contrôle
 ; Param : Handle du contrôle dans eax

 SetFontStandard:
push dword 01b
push dword [hFontStandard]
push dword 30h
push dword eax
call [PostMessageA]
 ret  
;_______________________________________________
  
  
[SECTION DATA USE32 CLASS=DATA]
  
  ; Données
;_______________________________________________
instance 		resd 1
commandline		resd 1
winclass			resd 12
atom				resd 1
handle			resd 1
msg1				resd 9
nomclass			db "WindowClass01",0
nom				db "premiere fenetre window",0
message1			db "Erreur !",0
message2			db "Première erreur !",0
message3			db "Deuxsième erreur !",0
message4			db "Bye !",0


FontStandard    dd      10
                resd    6
                db      "MS sans Serif",0
                
hFontStandard   resd    1
;_______________________________________________




 Sources du même auteur

ECRIRE DU TEXTE DANS UNE FENÊTRE (NASM)
POSTION SOURI (NASM)
UTILISER API BEGINPAINT DÉBUTANT (NASM)

 Sources de la même categorie

Source avec Zip Source avec une capture BASE DE REGISTRE ET TRANSFERE DE BMP DANS SYSTEM32 par vincent2795
Source avec Zip RÉSOUDRE LES PROBLÈMES DE VERSIONS DU SYSTÈME OU DE DLL par ToutEnMasm
Source avec Zip DEXPLORE INTERFACE HELP2 MICROSOFT DOCUMENT EXPLORER par ToutEnMasm
Source avec Zip DEXPLORE INTERFACE HELP2 MICROSOFT DOCUMENT EXPLORER par ToutEnMasm
Source avec Zip Source avec une capture ANALYSEUR DE TRAFIC (WINPCAP) par ORdream

Commentaires et avis

Commentaire de gokudo le 30/07/2009 07:00:25

Je trouve ce genre d'exemples simples d'une grande utilité pour les débutants comme moi.
merci pour ce code source.

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mars 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728
293031    

Consulter la suite du CalendriCode

Photothèque

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,390 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales