WndProc proc hWin:DWORD,uMsg:DWORD,wParam:DWORD,lParam:DWORD
LOCAL hDC :DWORD
LOCAL sDC :DWORD
LOCAL xDC :DWORD
LOCAL oldobj :DWORD
LOCAL wwid :DWORD
LOCAL Ps :PAINTSTRUCT
LOCAL Rct :RECT
LOCAL pt :POINT
LOCAL buffer1[260]:BYTE ; these are two spare buffers
LOCAL buffer2[260]:BYTE ; for text manipulation etc..
......
case WM_NCHITTEST
QUESTION! movsx eax, WORD PTR [ebp+20] ; get X-Y coordinates
mov pt.x, eax
movsx eax, WORD PTR [ebp+22]
mov pt.y, eax
in the line i marked QUESTION, if the author of the code want to load the lParam
from stack, why not use esp,and the index might be 16? any thing I miss?
:bg using EBP is more comfortable and easy to read, on x86 processors PUSH instructions always pushed a 32-bit value
well - the stack frame is set into EBP
and - the processor is optimized to use EBP for stack references
but - the main reason
EBP is stationary
ESP goes up and down whenever you push or pop something
that code isn't a very good example
he should reference the stack parameters by name, unless the assembler epilogue has been disabled
also - he should use MOVZX, not MOVSX (not a big deal, but the values should always be positive)
case WM_NCHITTEST
movzx eax, WORD PTR lParam ; get X-Y coordinates
mov pt.x, eax
movzx eax, WORD PTR lParam+2
mov pt.y, eax
also - i am not sure WM_NCHITTEST is the best message to handle to track cursor movement
can't see the rest of the code, but this message should exit via DefWindowProc
Hi,dedndave,actually I think the code should deploy like yours, its more reasonable! :U
besides,where does EBP point to? is it point to the base of the stack? if so, the stack grows backward,if use EBP to reference parameter, should we use something like this mov eax, [ebp - 16]
i will attach the whole code
http://www.masm32.com/board/index.php?topic=17611.msg150119#msg150119
as i mentioned...
EBP is used as a stationary reference to the stack frame
ESP changes when you PUSH or POP values, EBP does not
that is why EBP is used instead of ESP
Quote from: dedndave on April 08, 2012, 02:06:30 PM
http://www.masm32.com/board/index.php?topic=17611.msg150119#msg150119
as i mentioned...
EBP is used as a stationary reference to the stack frame
ESP changes when you PUSH or POP values, EBP does not
that is why EBP is used instead of ESP
i know what you mean now, cause the existence of PROLOGUE AND EPILOGUE(masm32 convenience), the ebp has the value of esp
just like this
OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE
Funk PROC Parm1:DWORD,Parm2:DWORD,Parm3:DWORD
push ebx ;for win32, these 4 registers should generally be preserved
push esi ;EAX, ECX, and EDX can be destroyed and are sometimes used to return results
push edi
push ebp
mov ebp,esp
sub esp,12 ;4*LocalDwordCount
and ebp has the value of esp
:bg Thank you RHL and dedndave, you are both talking the same thing, while I'm a little un-brilliant,cause I'm a newbie, :lol