|
1鱼币
WIN32第四章的第一程序窗口代码,我照着敲出来,但编译不能过。
我一行一行的对照,发了几处打错了,又对照了两遍,确认没了,便编译还是不通过。
- .386 ;CPU支持的指令集
- .model flat,stdcall ;定义内存寻址模式及子程序的调用方式
- option casemap:none ;选项,设置变量是否区分大小写,支持
-
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- ;Include 文件定义
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- include windows.inc ;包含系统类库
- include gdi32.inc ;图形相关函数库
- includelib gdi32.lib ;图形函数导入库
- include user32.inc ;用户函数函数库
- includelib user32.lib ;用户导入库
- include kernel32.inc ;核心库
- includelib kernel32.lib ;核心类库
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- ;数据段
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- .data? ;定义数据段
- hInstance dd ? ;
- hWinMain dd ? ; .const ;定义常量数据段
-
- SzClassName dd 'MyClass',0
- SzCaptionMain dd 'My first Window!',0
- SzText dd 'Win32 Assembly,Simple and powerful !',0
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- ;代码段
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- .code
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- ;窗口过程
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- _ProcWinMain proc USES ebx edi esi,hWnd,uMsg,wParam,lParam ;uses这关键字的作用是,无论哪个函数的返回值都永远都是放在eax中的。
- local @stPs:PAINTSTRUCT
- local @stRect:RECT
- local @hDc
-
- mov eax,uMsg
- ;**********************************************************************
- .if eax == WM_PAINT
- invoke BeginPaint,hWnd,addr @stPs
- mov @hDc,eax
-
- invoke GetClientRect,hWnd,addr @stRect
- invoke DrawText,@hDc,addr szText,-1,\
- addr @stRect,\
- DT_SINGLELINE or DT_CENTER or DT_VCENTER
-
- invoke EndPaint,hWnd,addr @stPs
- ;**********************************************************************
- .elseif eax == WM_CLOSE
- invoke DestroyWindow,hWinMain
- invoke PostQuitMessage,NULL
- ;**********************************************************************
- .else
- invoke DefWindowProc,hWnd,uMsg,wParam,lParam
- ret
- .endif
- ;**********************************************************************
- xor eax,eax
- ret
-
- _ProcWinMain endp
- ;**********************************************************************
- _WinMain proc
- local @stWndClass:WNDCLASSEX ;冒号的含义是什么?
- local @stMsg:MSG
-
- invoke GetModuleHandle,NULL
- mov hInstance,eax
- invoke RtlZeroMemory,addr @stWndClass,sizeof @stWndClass
- ;**********************************************************************
- ;注册窗口类
- ;**********************************************************************
- invoke LoadCursor,0,IDC_ARROW
- mov @stWndClass.hCursor,eax
- push hInstance
- pop @stWndClass.hInstance
- mov @stWndClass.cbSize,sizeof WNDCLASSEX
- mov @stWndClass.style,CS_HREDRAW OR CS_VREDRAW
- mov @stWndClass.lpfnWndProc,offset _ProcWinMain
- mov @stWndClass.hbrBackground,COLOR_WINDOW + 1
- mov @stWndClass.lpszClassName,offset szClassName
- invoke RegisterClassEx,add @stWndClass
- ;**********************************************************************
- ;建立并显示窗口
- ;**********************************************************************
- invoke CreatewindowEx,WS_EX_CLIENTEDGE,\
- offset szClassName,offset szCaptionMain,\
- WS_OVERLAPPEDWINDOW,\
- 100,100,600,400,\
- NULL,NULL,hInstance,NULL
- mov hWinMain,eax
- invoke ShowWindow,hWinMain,SW_SHOWNORMAL
- invoke updateWindow,hWinMain
- ;**********************************************************************
- ;消息循环
- ;**********************************************************************
- .while TRUE
- invoke GetMessage,addr @stMsg,NULL,0,0
- .break .if eax == 0
- invoke TranslateMessage,addr @stMsg
- invoke DispatchMessage,addr @stMsg
- .endw
- ret
- _WinMain endp
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- start:
- call _WinMain
- invoke ExitProcess,NULL
- ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
- end start
-
复制代码 编译结果
|
最佳答案
查看完整内容
46: szText用db定义 szText db "Win32 Assembly,Simple and powerful !",0
85: 把83行的add改成addr
89: 是CreateWindowEx
96: 是UpdateWindow
24,25,26: 22 23 24行的代码 都用db定义
|