雪绒★~花飘 发表于 2013-1-7 23:01:12

关于win32第四章第一个窗口程序的问题

.386.model flat,stdcalloption casemap:none;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>; Include 文件定义;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>include windows.incinclude gdi32.incincludelib gdi32.libinclude user32.incincludelib user32.libinclude kernel32.incincludelib kernel32.lib;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>; 数据段;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.data?hInstance dd ?hWinMain dd ?.constszClassName db 'MyClass',0szCaptionMain db 'My first Window !',0szText db 'Win32 Assembly, Simple and powerful !',0;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>; 代码段;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>.code;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>; 窗口过程;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>_ProcWinMain proc uses ebx edi esi,hWnd,uMsg,wParam,lParamlocal @stPs:PAINTSTRUCTlocal @stRect:RECTlocal @hDcmov eax,uMsg;********************************************************************.if eax == WM_PAINTinvoke BeginPaint,hWnd,addr @stPsmov @hDc,eaxinvoke GetClientRect,hWnd,addr @stRectinvoke DrawText,@hDc,addr szText,-1,\addr @stRect,\DT_SINGLELINE or DT_CENTER or DT_VCENTERinvoke EndPaint,hWnd,addr @stPs;********************************************************************.elseif eax == WM_CLOSEinvoke DestroyWindow,hWinMaininvoke PostQuitMessage,NULL;********************************************************************.elseinvoke DefWindowProc,hWnd,uMsg,wParam,lParamret.endif;********************************************************************xor eax,eaxret_ProcWinMain endp;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>_WinMain proclocal @stWndClass:WNDCLASSEXlocal @stMsg:MSGinvoke GetModuleHandle,NULLmov hInstance,eaxinvoke RtlZeroMemory,addr @stWndClass,sizeof @stWndClass;********************************************************************; 注册窗口类;********************************************************************invoke LoadCursor,0,IDC_ARROWmov @stWndClass.hCursor,eaxpush hInstancepop @stWndClass.hInstancemov @stWndClass.cbSize,sizeof WNDCLASSEXmov @stWndClass.style,CS_HREDRAW or CS_VREDRAWmov @stWndClass.lpfnWndProc,offset _ProcWinMainmov @stWndClass.hbrBackground,COLOR_WINDOW + 1mov @stWndClass.lpszClassName,offset szClassNameinvoke RegisterClassEx,addr @stWndClass;********************************************************************; 建立并显示窗口;********************************************************************invoke CreateWindowEx,WS_EX_CLIENTEDGE,\offset szClassName,offset szCaptionMain,\WS_OVERLAPPEDWINDOW,\100,100,600,400,\NULL,NULL,hInstance,NULLmov hWinMain,eaxinvoke ShowWindow,hWinMain,SW_SHOWNORMALinvoke UpdateWindow,hWinMain;********************************************************************; 消息循环;********************************************************************.while TRUEinvoke GetMessage,addr @stMsg,NULL,0,0.break .if eax == 0invoke TranslateMessage,addr @stMsginvoke DispatchMessage,addr @stMsg.endwret_WinMain endp;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>start:call _WinMaininvoke ExitProcess,NULL;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>end start在上面代码中,建立并显示窗口那段代码中 mov hWinMain,eax,eax返回的为什么是窗口的句柄值??eax不是在前面获得光标句柄的值被改变了吗,为什么到mov hWinMain,eax返回的会是窗口句柄的值呢???

メ㊣逆ご帅☆ 发表于 2013-1-7 23:01:13

CreateWindowEx创建窗口后返回的就是窗口句柄
通过eax返回(大部分api都这样)

1236 发表于 2013-1-8 01:54:53

是的如果CreateWindowEx创建成功 则默认返回窗口句柄

大头石 发表于 2013-1-9 09:58:12

我想这里的提问者对EAX寄存器的功能不是很理解,除了作为通用寄存器以外,EAX寄存器在API编程中作为函数的返回值寄存器(绝大多数是这样的)。每调用一个函数,EAX的值自动被修改成函数的返回值,那么参考一下你的问题,相信你应该能有所了解了。
页: [1]
查看完整版本: 关于win32第四章第一个窗口程序的问题