ça marche pas, aide ...

iscalibar Messages postés 15 Date d'inscription vendredi 22 juin 2007 Statut Membre Dernière intervention 27 mars 2009 - 26 déc. 2007 à 23:04
ToutEnMasm Messages postés 587 Date d'inscription jeudi 28 novembre 2002 Statut Membre Dernière intervention 13 décembre 2022 - 27 déc. 2007 à 20:24
Bonjour, j'ai un petit probleme, j'ai ecris un program pour le compilateur masm32 qui ne fai que afficher une fenetre, mai malheureusement ça marche pa, voila le code:
----------------------------------------------------
.386p
.model flat, stdcall


WS_VISIBLE                              equ     000CF0000H
WS_CAPTION                              equ     0C00000h
WM_DESTROY                              equ     0002h
SW_SHOWNORMAL                           equ     1
IDC_ARROW                               equ     32515
IDI_APPLICATION                         equ     32512
WM_CREATE equ 1
CS_VREDRAW                              equ     00001h
CS_HREDRAW                              equ     00002h


extern           [mailto:GetModuleHandleA@4 GetModuleHandleA@4]: near
extern           [mailto:LoadIconA@8 LoadIconA@8]: near
extern           [mailto:LoadCursorA@8 LoadCursorA@8]  : near
extern           [mailto:RegisterClassA@4 RegisterClassA@4]  : near
extern           [mailto:CreateWindowExA@48 CreateWindowExA@48] : near
extern           [mailto:PostQuitMessage@4 PostQuitMessage@4] : near
extern           [mailto:GetMessageA@16 GetMessageA@16]  : near
extern           [mailto:TranslateMessage@4:near TranslateMessage@4:near]
extern           [mailto:DispatchMessageA@4 DispatchMessageA@4]: near
extern           [mailto:DefWindowProcA@16 DefWindowProcA@16]  : near
extern           [mailto:ExitProcess@4 ExitProcess@4]  : near
extern           [mailto:ShowWindow@8 ShowWindow@8]      : near
extern           [mailto:UpdateWindow@4 UpdateWindow@4]    : near
extern [mailto:MessageBoxA@16:near MessageBoxA@16:near]


includelib c:\masm32\lib\kernel32.lib
includelib c:\masm32\lib\user32.lib


;structure de la class de la feneter
WinClass struct
cbSize dword ?
style dword ?
winproc dword ?
ClsExtra dword ?
WndExtra dword ?
instance dword ?
icon dword ?
cursor dword ?
background dword ?
menuName dword ?
className dword ?
IconSm dword ?
WinClass ends
;structure d'un msg system
MSG struct
hwnd dword ?
message dword ?
wParam dword ?
lParam dword ?
time dword ?
pnt dd ?
MSG ends


.DATA
mssg MSG <?>
wc WinClass <?>
;handels
hMain dd 0
hInst dd 0


progName db 'Ich Bin HStein',0
szMainClass db 'ASMWINDOW',0
marchtitle db 'Box',0
marchbody db 'Ich marche bien',0
.CODE
start:
push 0
call [mailto:GetModuleHandleA@4 GetModuleHandleA@4]
mov [hInst],eax


mov [wc.style],CS_HREDRAW + CS_VREDRAW
mov [wc.winproc],offset WndProc
mov [wc.ClsExtra],0
mov [wc.WndExtra],0


mov eax,[hInst]
mov [wc.instance],eax


push IDI_APPLICATION
push 0
call [mailto:LoadIconA@8 LoadIconA@8]
mov [wc.icon],eax


push IDC_ARROW
push 0
call [mailto:LoadCursorA@8 LoadCursorA@8]
mov [wc.cursor],eax


mov [wc.background],17
mov dword ptr [wc.menuName],0
mov dword ptr [wc.className],offset szMainClass
push offset wc
call [mailto:RegisterClassA@4 RegisterClassA@4]


push 0
push [hInst]
push 0
push 0
push 400
push 400
push 100
push 100
push WS_VISIBLE
push offset progName
push offset szMainClass
push 0
call [mailto:CreateWindowExA@48 CreateWindowExA@48]
mov [hMain],eax


push SW_SHOWNORMAL
push [hMain]
call [mailto:ShowWindow@8 ShowWindow@8]
push [hMain]
call [mailto:UpdateWindow@4 UpdateWindow@4]


msg_loop:
push 0
push 0
push 0
push offset mssg
call [mailto:GetMessageA@16 GetMessageA@16]
cmp eax,0
je end_loop
push offset mssg
call [mailto:TranslateMessage@4 TranslateMessage@4]
push offset mssg
call [mailto:DispatchMessageA@4 DispatchMessageA@4]
jmp msg_loop
end_loop:
push 0
call [mailto:ExitProcess@4 ExitProcess@4]


WndProc proc
push ebp
mov ebp,esp
push ebx
push esi
push edi


cmp dword ptr [ebp+0ch],WM_DESTROY
je wmdestroy
cmp dword ptr [ebp+0ch],WM_CREATE
je wmcreate
push dword ptr [ebp+014h]
push dword ptr [ebp+010h]
push dword ptr [ebp+0ch]
push dword ptr [ebp+08h]
call [mailto:DefWindowProcA@16 DefWindowProcA@16]
jmp finish
wmcreate:
mov eax,0
jmp finish
wmdestroy:
push 0
call [mailto:PostQuitMessage@4 PostQuitMessage@4]
xor eax,eax
finish:
pop edi
pop esi
pop ebx
pop ebp
ret 16
WndProc endp
end start
----------------------------------
la fenetre ne s'affiche pa ,aide moi a trouver le probleme et la solution svp

6 réponses

ToutEnMasm Messages postés 587 Date d'inscription jeudi 28 novembre 2002 Statut Membre Dernière intervention 13 décembre 2022 3
27 déc. 2007 à 10:54
Le mieux est de prendre un exemple,nombreux dans masm32,pour s'en inspirer.
Dans exemple1,on trouve des exemples de fenêtres.
0
iscalibar Messages postés 15 Date d'inscription vendredi 22 juin 2007 Statut Membre Dernière intervention 27 mars 2009
27 déc. 2007 à 11:42
Ben, mon code est extrait d'un example, ben voila le code source de l'example (ben je sais qu'il y a une erreur mai je ne la voi pa, je veu seuelement savoir ou est l'erreur), voila le code source de l'example:
-------------------------------------------------------


.386P
; Flat memory model
.MODEL FLAT, stdcall
; Constants
; The message arrives when the window is closed
WM_DESTROY equ 2
; The message arrives when the window is created
WM_CREATE equ 1
; The message arrives if the left mouse button is clicked

; somewhere in the window area
WM_LBUTTONDOWN equ 201h
; The message arrives if the right mouse button is clicked
; somewhere in the window area
WM_RBUTTONDOWN equ 204h
; Window properties
CS_VREDRAW equ 1h
CS_HREDRAW equ 2h
CS_GLOBALCLASS equ 4000h
WS_OVERLAPPEDWINDOW equ 000CF0000H
Style equ CS_HREDRAW+CS_VREDRAW+CS_GLOBALCLASS
; Standard icon identifier
IDI_APPLICATION equ 32512
; Cursor identifier
IDC_CROSS equ 32515
; Normal mode of displaying the window
SW_SHOWNORMAL equ 1
; Prototypes of external procedures
EXTERN MessageBoxA@16:NEAR
EXTERN CreateWindowExA@48:NEAR
EXTERN DefWindowProcA@16:NEAR
EXTERN DispatchMessageA@4:NEAR
EXTERN ExitProcess@4:NEAR
EXTERN GetMessageA@16:NEAR
EXTERN GetModuleHandleA@4:NEAR
EXTERN LoadCursorA@8:NEAR
EXTERN LoadIconA@8:NEAR
EXTERN PostQuitMessage@4:NEAR
EXTERN RegisterClassA@4:NEAR
EXTERN ShowWindow@8:NEAR
EXTERN TranslateMessage@4:NEAR
EXTERN UpdateWindow@4:NEAR
; Directives for linking libraries
includelib .c:\masm32\lib\user32.lib
includelib c:\masm32\lib\kernel32.lib
;------------------------------------------
; Structures
; Message structure
MSGSTRUCT STRUC
MSHWND DD ? ; Identifier of the window
; that received the message
MSMESSAGE DD ? ; Message identifier
MSWPARAM DD ? ; Auxiliary information about the message

MSLPARAM DD ? ; Auxiliary information about the message
MSTIME DD ? ; Time of sending the message
MSPT DD ? ; Cursor position at the time of sending
; the message

MSGSTRUCT ENDS
;------------
WNDCLASS STRUC
CLSSTYLE DD ? ; Window style
CLWNDPROC DD ? ; Pointer to the window procedure
CLSCEXTRA DD ? ; Information on auxiliary bytes for
; this structure
CLWNDEXTRA DD ? ; Information on auxiliary bytes for the window
CLSHINSTANCE DD ? ; Application descriptor
CLSHICON DD ? ; Window icon descriptor
CLSHCURSOR DD ? ; Window cursor descriptor
CLBKGROUND DD ? ; Window brush descriptor
CLMENUNAME DD ? ; Menu identifier
CLNAME DD ? ; Specifies the window class name
WNDCLASS ENDS
; Data segment
_DATA SEGMENT
NEWHWND DD 0
MSG MSGSTRUCT <?>
WC WNDCLASS <?>
HINST DD 0 ; Here, the application descriptor is stored
TITLENAME DB 'Simple example of a 32-bit application', 0
CLASSNAME DB 'CLASS32', 0
CAP DB 'Message', 0
MES1 DB 'You have clicked the left mouse button', 0
MES2 DB 'Exit. Bye!', 0
_DATA ENDS
; Code segment
_TEXT SEGMENT
START:
; Get application descriptor
PUSH 0
CALL GetModuleHandleA@4 ;
MOV [HINST], EAX
REG_CLASS:
; Fill window structure
; Style
MOV [WC.CLSSTYLE], style
; Message-handling procedure

MOV [WC.CLWNDPROC], OFFSET WNDPROC
MOV [WC.CLSCEXTRA], 0
MOV [WC.CLWNDEXTRA], 0
MOV EAX, [HINST]
MOV [WC.CLSHINSTANCE], EAX
;----------Window icon
PUSH IDI_APPLICATION
PUSH 0
CALL LoadIconA@8
MOV [WC.CLSHICON], EAX
;----------Window cursor
PUSH IDC_CROSS
PUSH 0
CALL LoadCursorA@8
MOV [WC.CLSHCURSOR], EAX
;-----------
MOV [WC.CLBKGROUND], 17 ; Window color
MOV DWORD PTR [WC.CLMENUNAME], 0
MOV DWORD PTR [WC.CLNAME], OFFSET CLASSNAME
PUSH OFFSET WC
CALL RegisterClassA@4
; Create a window of the registered class
PUSH 0
PUSH [HINST]
PUSH 0
PUSH 0
PUSH 400 ; DY - Window height
PUSH 400 ; DX - Window width
PUSH 100 ; Y - Coordinate of the window's top left corner
PUSH 100 ; X - Coordinate of the window's top left corner
PUSH WS_OVERLAPPEDWINDOW
PUSH OFFSET TITLENAME ; Window name
PUSH OFFSET CLASSNAME ; Class name
PUSH 0
CALL CreateWindowExA@48
; Check for errors
CMP EAX, 0
JZ _ERR
MOV [NEWHWND], EAX ; Window descriptor
;---------------------
PUSH SW_SHOWNORMAL
PUSH [NEWHWND]
CALL ShowWindow@8 ; Display the newly created window

;-------------------------
PUSH [NEWHWND]
CALL UpdateWindow@4 ; Redraw the visible part of the window
; WM_PAINT message
; Message-handling loop
MSG_LOOP:
PUSH 0
PUSH 0
PUSH 0
PUSH OFFSET MSG
CALL GetMessageA@16
CMP EAX, 0
JE END_LOOP
PUSH OFFSET MSG
CALL TranslateMessage@4
PUSH OFFSET MSG
CALL DispatchMessageA@4
JMP MSG_LOOP
END_LOOP:
; Exit the program (close the process)
PUSH [MSG.MSWPARAM]
CALL ExitProcess@4
_ERR:
JMP END_LOOP
;------------------------------------------
; Window procedure
; Position of parameters in the stack
; [EBP+014H] LPARAM
; [EBP+10H] WAPARAM
; [EBP+0CH] MES
; [EBP+8] HWND
WNDPROC PROC
PUSH EBP
MOV EBP, ESP
PUSH EBX
PUSH ESI
PUSH EDI
CMP DWORD PTR [EBP+0CH], WM_DESTROY
JE WMDESTROY
CMP DWORD PTR [EBP+0CH], WM_CREATE
JE WMCREATE
CMP DWORD PTR [EBP+0CH], WM_LBUTTONDOWN ; Left button
JE LBUTTON

CMP DWORD PTR [EBP+0CH], WM_RBUTTONDOWN ; Right button
JE RBUTTON
JMP DEFWNDPROC
; Clicking the right mouse button closes the window
RBUTTON:
JMP WMDESTROY
; Clicking the left mouse button
LBUTTON:
; Displaying the message
PUSH 0 ; MB_OK
PUSH OFFSET CAP
PUSH OFFSET MES1
PUSH DWORD PTR [EBP+08H]
CALL MessageBoxA@16
MOV EAX, 0
JMP FINISH
WMCREATE:
MOV EAX, 0
JMP FINISH
DEFWNDPROC:
PUSH DWORD PTR [EBP+14H]
PUSH DWORD PTR [EBP+10H]
PUSH DWORD PTR [EBP+0CH]
PUSH DWORD PTR [EBP+08H]
CALL DefWindowProcA@16
JMP FINISH
WMDESTROY:
PUSH 0 ; MB_OK
PUSH OFFSET CAP
PUSH OFFSET MES2
PUSH DWORD PTR [EBP+08H] ; Window descriptor
CALL MessageBoxA@16
PUSH 0
CALL PostQuitMessage@4 ; WM_QUIT message
MOV EAX, 0
FINISH:
POP EDI
POP ESI
POP EBX
POP EBP
RET 16
WNDPROC ENDP
_TEXT ENDS
END START
------------------------------------


j'aimerai bien que quelqu'un m'aide a trouver l'erreur car on peu pa apprendre si on connais pa nos erreur.
0
iscalibar Messages postés 15 Date d'inscription vendredi 22 juin 2007 Statut Membre Dernière intervention 27 mars 2009
27 déc. 2007 à 11:42
Ben, mon code est extrait d'un example, ben voila le code source de l'example (ben je sais qu'il y a une erreur mai je ne la voi pa, je veu seuelement savoir ou est l'erreur), voila le code source de l'example:
-------------------------------------------------------


.386P
; Flat memory model
.MODEL FLAT, stdcall
; Constants
; The message arrives when the window is closed
WM_DESTROY equ 2
; The message arrives when the window is created
WM_CREATE equ 1
; The message arrives if the left mouse button is clicked

; somewhere in the window area
WM_LBUTTONDOWN equ 201h
; The message arrives if the right mouse button is clicked
; somewhere in the window area
WM_RBUTTONDOWN equ 204h
; Window properties
CS_VREDRAW equ 1h
CS_HREDRAW equ 2h
CS_GLOBALCLASS equ 4000h
WS_OVERLAPPEDWINDOW equ 000CF0000H
Style equ CS_HREDRAW+CS_VREDRAW+CS_GLOBALCLASS
; Standard icon identifier
IDI_APPLICATION equ 32512
; Cursor identifier
IDC_CROSS equ 32515
; Normal mode of displaying the window
SW_SHOWNORMAL equ 1
; Prototypes of external procedures
EXTERN MessageBoxA@16:NEAR
EXTERN CreateWindowExA@48:NEAR
EXTERN DefWindowProcA@16:NEAR
EXTERN DispatchMessageA@4:NEAR
EXTERN ExitProcess@4:NEAR
EXTERN GetMessageA@16:NEAR
EXTERN GetModuleHandleA@4:NEAR
EXTERN LoadCursorA@8:NEAR
EXTERN LoadIconA@8:NEAR
EXTERN PostQuitMessage@4:NEAR
EXTERN RegisterClassA@4:NEAR
EXTERN ShowWindow@8:NEAR
EXTERN TranslateMessage@4:NEAR
EXTERN UpdateWindow@4:NEAR
; Directives for linking libraries
includelib .c:\masm32\lib\user32.lib
includelib c:\masm32\lib\kernel32.lib
;------------------------------------------
; Structures
; Message structure
MSGSTRUCT STRUC
MSHWND DD ? ; Identifier of the window
; that received the message
MSMESSAGE DD ? ; Message identifier
MSWPARAM DD ? ; Auxiliary information about the message

MSLPARAM DD ? ; Auxiliary information about the message
MSTIME DD ? ; Time of sending the message
MSPT DD ? ; Cursor position at the time of sending
; the message

MSGSTRUCT ENDS
;------------
WNDCLASS STRUC
CLSSTYLE DD ? ; Window style
CLWNDPROC DD ? ; Pointer to the window procedure
CLSCEXTRA DD ? ; Information on auxiliary bytes for
; this structure
CLWNDEXTRA DD ? ; Information on auxiliary bytes for the window
CLSHINSTANCE DD ? ; Application descriptor
CLSHICON DD ? ; Window icon descriptor
CLSHCURSOR DD ? ; Window cursor descriptor
CLBKGROUND DD ? ; Window brush descriptor
CLMENUNAME DD ? ; Menu identifier
CLNAME DD ? ; Specifies the window class name
WNDCLASS ENDS
; Data segment
_DATA SEGMENT
NEWHWND DD 0
MSG MSGSTRUCT <?>
WC WNDCLASS <?>
HINST DD 0 ; Here, the application descriptor is stored
TITLENAME DB 'Simple example of a 32-bit application', 0
CLASSNAME DB 'CLASS32', 0
CAP DB 'Message', 0
MES1 DB 'You have clicked the left mouse button', 0
MES2 DB 'Exit. Bye!', 0
_DATA ENDS
; Code segment
_TEXT SEGMENT
START:
; Get application descriptor
PUSH 0
CALL GetModuleHandleA@4 ;
MOV [HINST], EAX
REG_CLASS:
; Fill window structure
; Style
MOV [WC.CLSSTYLE], style
; Message-handling procedure

MOV [WC.CLWNDPROC], OFFSET WNDPROC
MOV [WC.CLSCEXTRA], 0
MOV [WC.CLWNDEXTRA], 0
MOV EAX, [HINST]
MOV [WC.CLSHINSTANCE], EAX
;----------Window icon
PUSH IDI_APPLICATION
PUSH 0
CALL LoadIconA@8
MOV [WC.CLSHICON], EAX
;----------Window cursor
PUSH IDC_CROSS
PUSH 0
CALL LoadCursorA@8
MOV [WC.CLSHCURSOR], EAX
;-----------
MOV [WC.CLBKGROUND], 17 ; Window color
MOV DWORD PTR [WC.CLMENUNAME], 0
MOV DWORD PTR [WC.CLNAME], OFFSET CLASSNAME
PUSH OFFSET WC
CALL RegisterClassA@4
; Create a window of the registered class
PUSH 0
PUSH [HINST]
PUSH 0
PUSH 0
PUSH 400 ; DY - Window height
PUSH 400 ; DX - Window width
PUSH 100 ; Y - Coordinate of the window's top left corner
PUSH 100 ; X - Coordinate of the window's top left corner
PUSH WS_OVERLAPPEDWINDOW
PUSH OFFSET TITLENAME ; Window name
PUSH OFFSET CLASSNAME ; Class name
PUSH 0
CALL CreateWindowExA@48
; Check for errors
CMP EAX, 0
JZ _ERR
MOV [NEWHWND], EAX ; Window descriptor
;---------------------
PUSH SW_SHOWNORMAL
PUSH [NEWHWND]
CALL ShowWindow@8 ; Display the newly created window

;-------------------------
PUSH [NEWHWND]
CALL UpdateWindow@4 ; Redraw the visible part of the window
; WM_PAINT message
; Message-handling loop
MSG_LOOP:
PUSH 0
PUSH 0
PUSH 0
PUSH OFFSET MSG
CALL GetMessageA@16
CMP EAX, 0
JE END_LOOP
PUSH OFFSET MSG
CALL TranslateMessage@4
PUSH OFFSET MSG
CALL DispatchMessageA@4
JMP MSG_LOOP
END_LOOP:
; Exit the program (close the process)
PUSH [MSG.MSWPARAM]
CALL ExitProcess@4
_ERR:
JMP END_LOOP
;------------------------------------------
; Window procedure
; Position of parameters in the stack
; [EBP+014H] LPARAM
; [EBP+10H] WAPARAM
; [EBP+0CH] MES
; [EBP+8] HWND
WNDPROC PROC
PUSH EBP
MOV EBP, ESP
PUSH EBX
PUSH ESI
PUSH EDI
CMP DWORD PTR [EBP+0CH], WM_DESTROY
JE WMDESTROY
CMP DWORD PTR [EBP+0CH], WM_CREATE
JE WMCREATE
CMP DWORD PTR [EBP+0CH], WM_LBUTTONDOWN ; Left button
JE LBUTTON

CMP DWORD PTR [EBP+0CH], WM_RBUTTONDOWN ; Right button
JE RBUTTON
JMP DEFWNDPROC
; Clicking the right mouse button closes the window
RBUTTON:
JMP WMDESTROY
; Clicking the left mouse button
LBUTTON:
; Displaying the message
PUSH 0 ; MB_OK
PUSH OFFSET CAP
PUSH OFFSET MES1
PUSH DWORD PTR [EBP+08H]
CALL MessageBoxA@16
MOV EAX, 0
JMP FINISH
WMCREATE:
MOV EAX, 0
JMP FINISH
DEFWNDPROC:
PUSH DWORD PTR [EBP+14H]
PUSH DWORD PTR [EBP+10H]
PUSH DWORD PTR [EBP+0CH]
PUSH DWORD PTR [EBP+08H]
CALL DefWindowProcA@16
JMP FINISH
WMDESTROY:
PUSH 0 ; MB_OK
PUSH OFFSET CAP
PUSH OFFSET MES2
PUSH DWORD PTR [EBP+08H] ; Window descriptor
CALL MessageBoxA@16
PUSH 0
CALL PostQuitMessage@4 ; WM_QUIT message
MOV EAX, 0
FINISH:
POP EDI
POP ESI
POP EBX
POP EBP
RET 16
WNDPROC ENDP
_TEXT ENDS
END START
------------------------------------


j'aimerai bien que quelqu'un m'aide a trouver l'erreur car on peu pa apprendre si on connais pa nos erreur.
0
ToutEnMasm Messages postés 587 Date d'inscription jeudi 28 novembre 2002 Statut Membre Dernière intervention 13 décembre 2022 3
27 déc. 2007 à 14:36
J'insiste,il ne sert à rien que je te trouve ton erreur .On peut utiliser un debugger mais on peut aussi :
Comparer et trouver.
ça doit être suffisant
<hr />
; #########################################################################

;

; GENERIC.ASM is a roadmap around a standard 32 bit

; windows application skeleton written in MASM32.

;

; #########################################################################

; Assembler specific instructions for 32 bit ASM code

.386 ; minimum processor needed for 32 bit

.model flat, stdcall ; FLAT memory model & STDCALL calling

option casemap :none ; set code to case sensitive

; #########################################################################

; ---------------------------------------------

; main include file with equates and structures

; ---------------------------------------------

include \masm32\include\windows.inc

; -------------------------------------------------------------

; In MASM32, each include file created by the L2INC.EXE utility

; has a matching library file. If you need functions from a

; specific library, you use BOTH the include file and library

; file for that library.

; -------------------------------------------------------------

include \masm32\include\user32.inc

include \masm32\include\kernel32.inc

includelib \masm32\lib\user32.lib

includelib \masm32\lib\kernel32.lib

; #########################################################################

; ------------------------------------------------------------------------

; MACROS are a method of expanding text at assembly time. This allows the

; programmer a tidy and convenient way of using COMMON blocks of code with

; the capacity to use DIFFERENT parameters in each block.

; ------------------------------------------------------------------------

; 1. szText

; A macro to insert TEXT into the code section for convenient and

; more intuitive coding of functions that use byte data as text.

szText MACRO Name, Text:VARARG

LOCAL lbl

jmp lbl

Name db Text,0

lbl:

ENDM

; 2. m2m

; There is no mnemonic to copy from one memory location to another,

; this macro saves repeated coding of this process and is easier to

; read in complex code.

m2m MACRO M1, M2

push M2

pop M1

ENDM

; 3. return

; Every procedure MUST have a "ret" to return the instruction

; pointer EIP back to the next instruction after the call that

; branched to it. This macro puts a return value in eax and

; makes the "ret" instruction on one line. It is mainly used

; for clear coding in complex conditionals in large branching

; code such as the WndProc procedure.

return MACRO arg

mov eax, arg

ret

ENDM

; #########################################################################

; ----------------------------------------------------------------------

; Prototypes are used in conjunction with the MASM "invoke" syntax for

; checking the number and size of parameters passed to a procedure. This

; improves the reliability of code that is written where errors in

; parameters are caught and displayed at assembly time.

; ----------------------------------------------------------------------

WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD

WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD

TopXY PROTO :DWORD,:DWORD

; #########################################################################

; ------------------------------------------------------------------------

; This is the INITIALISED data section meaning that data declared here has

; an initial value. You can also use an UNINIALISED section if you need

; data of that type [ .data? ]. Note that they are different and occur in

; different sections.

; ------------------------------------------------------------------------

.data

szDisplayName db "Generic",0

CommandLine dd 0

hWnd dd 0

hInstance dd 0

 

 

; #########################################################################

; ------------------------------------------------------------------------

; This is the start of the code section where executable code begins. This

; section ending with the ExitProcess() API function call is the only

; GLOBAL section of code and it provides access to the WinMain function

; with the necessary parameters, the instance handle and the command line

; address.

; ------------------------------------------------------------------------

.code

; -----------------------------------------------------------------------

; The label "start:" is the address of the start of the code section and

; it has a matching "end start" at the end of the file. All procedures in

; this module must be written between these two.

; -----------------------------------------------------------------------

start:

invoke GetModuleHandle, NULL ; provides the instance handle

mov hInstance, eax

invoke GetCommandLine ; provides the command line address

mov CommandLine, eax

invoke WinMain,hInstance,NULL,CommandLine,SW_SHOWDEFAULT

invoke ExitProcess,eax ; cleanup & return to operating system

; #########################################################################

WinMain proc hInst :DWORD,

hPrevInst :DWORD,

CmdLine :DWORD,

CmdShow :DWORD

;====================

; Put LOCALs on stack

;====================

LOCAL wc :WNDCLASSEX

LOCAL msg :MSG

LOCAL Wwd :DWORD

LOCAL Wht :DWORD

LOCAL Wtx :DWORD

LOCAL Wty :DWORD

szText szClassName,"Generic_Class"

;==================================================

; Fill WNDCLASSEX structure with required variables

;==================================================

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

;================================

; Centre window at following size

;================================

mov Wwd, 500

mov Wht, 350

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

; ==================================

; Create the main application window

; ==================================

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 LoadMenu,hInst,600 ; load resource menu

invoke SetMenu,hWnd,eax ; set it to main window

invoke ShowWindow,hWnd,SW_SHOWNORMAL ; display the window

invoke UpdateWindow,hWnd ; update the display

;===================================

; Loop until PostQuitMessage is sent

;===================================

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

; -------------------------------------------------------------------------

; Message are sent by the operating system to an application through the

; WndProc proc. Each message can have additional values associated with it

; in the two parameters, wParam & lParam. The range of additional data that

; can be passed to an application is determined by the message.

; -------------------------------------------------------------------------

.if uMsg == WM_COMMAND

;----------------------------------------------------------------------

; The WM_COMMAND message is sent by menus, buttons and toolbar buttons.

; Processing the wParam parameter of it is the method of obtaining the

; control's ID number so that the code for each operation can be

; processed. NOTE that the ID number is in the LOWORD of the wParam

; passed with the WM_COMMAND message. There may be some instances where

; an application needs to seperate the high and low words of wParam.

; ---------------------------------------------------------------------
;menu commands

.if wParam == 1000

invoke SendMessage,hWin,WM_SYSCOMMAND,SC_CLOSE,NULL

.elseif wParam == 1900

szText TheMsg,"Assembler, Pure & Simple"

invoke MessageBox,hWin,ADDR TheMsg,ADDR szDisplayName,MB_OK

.endif
;end menu commands

.elseif uMsg == WM_CREATE

; --------------------------------------------------------------------

; This message is sent to WndProc during the CreateWindowEx function

; call and is processed before it returns. This is used as a position

; to start other items such as controls. IMPORTANT, the handle for the

; CreateWindowEx call in the WinMain does not yet exist so the HANDLE

; passed to the WndProc [ hWin ] must be used here for any controls

; or child windows.

; --------------------------------------------------------------------

.elseif uMsg == WM_CLOSE

; -------------------------------------------------------------------

; This is the place where various requirements are performed before

; the application exits to the operating system such as deleting

; resources and testing if files have been saved. You have the option

; of returning ZERO if you don't wish the application to close which

; exits the WndProc procedure without passing this message to the

; default window processing done by the operating system.

; -------------------------------------------------------------------

szText TheText,"Please Confirm Exit"

invoke MessageBox,hWin,ADDR TheText,ADDR szDisplayName,MB_YESNO

.if eax == IDNO

return 0

.endif

.elseif uMsg == WM_DESTROY

; ----------------------------------------------------------------

; This message MUST be processed to cleanly exit the application.

; Calling the PostQuitMessage() function makes the GetMessage()

; function in the WinMain() main loop return ZERO which exits the

; application correctly. If this message is not processed properly

; the window disappears but the code is left in memory.

; ----------------------------------------------------------------

invoke PostQuitMessage,NULL

return 0

.endif

invoke DefWindowProc,hWin,uMsg,wParam,lParam

; --------------------------------------------------------------------

; Default window processing is done by the operating system for any

; message that is not processed by the application in the WndProc

; procedure. If the application requires other than default processing

; it executes the code when the message is trapped and returns ZERO

; to exit the WndProc procedure before the default window processing

; occurs with the call to DefWindowProc().

; --------------------------------------------------------------------

ret

WndProc endp

; ########################################################################

TopXY proc wDim:DWORD, sDim:DWORD

; ----------------------------------------------------

; This procedure calculates the top X & Y co-ordinates

; for the CreateWindowEx call in the WinMain procedure

; ----------------------------------------------------

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

; ########################################################################

end start
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
iscalibar Messages postés 15 Date d'inscription vendredi 22 juin 2007 Statut Membre Dernière intervention 27 mars 2009
27 déc. 2007 à 19:31
J'ai une question tres précise, ou est la faute??? ben a celui qui peu m'aider a trouver la faute merci bien de m'aider sinon merci bien de ne pa ecrir n'importe quel commentaire, et merçi
0
ToutEnMasm Messages postés 587 Date d'inscription jeudi 28 novembre 2002 Statut Membre Dernière intervention 13 décembre 2022 3
27 déc. 2007 à 20:24
J'ai un peu plus de connaissance en assembleur que vous (voir mon site) et je ne me permet pas de mettre "n'importe quel commentaire"
Un exemple de masm32 sur la création d'une fenêtre est une référence,ce n'est pas "n'importe quoi".
0
Rejoignez-nous