lyoal 发表于 2013-2-15 22:12:50

Win32汇编语言程序设计,捣鼓老久也没成功。

本帖最后由 lyoal 于 2013-2-15 22:25 编辑

;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;基础数据定义
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
   .386
   .model flat,stdcall
   option casemap:none
   
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;所需要的include头文件和导入库
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
includewindows.inc
includeuser32.inc
includelib user32.lib
includekernel32.inc
includelib kernel32.lib
includegdi32.inc
includelib gdi32.lib;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;数据变量
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
   .data?
hInstance dd?
hWinMain dd?   .const
szMinCaption db'窗口标题',0
szWinClassdb'窗口类名',0
szMBCaptiondb'错误提示',0
szMBCont1db'获取模块句柄失败!',0
szWndContdb'这是我写的第一个窗口,请参观一下,呵呵。。。',0
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;窗口过程
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    local @stPs:PAINTSTRUCT
    local @stRect:RECT
    local @hDc:HDC
   
    mov eax,uMsg
   
    .ifeax == WM_PAINT
      invoke BeginPaint,hWnd,addr @stPs
      mov@hDc,eax
      
      invoke GetClientRect,hWnd,addr @stRect
      invoke DrawText,@hDc,addr szWndCont,-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
_ProcWinMain endp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;主函数,注册窗口,创建窗口,显示窗口,更新窗口,消息循环等
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
_WinMain proc
   local @stWndClass:WNDCLASSEX
   local @stMsg:MSG
   
   
   ;获取模块句柄
   invoke GetModuleHandle,NULL
   .if eax
    mov hInstance,eax
   .else
    invoke MessageBox,NULL,offset szMBCont1,offset szMBCaption,MB_OK
   .endif
   
   invoke RtlZeroMemory,addr @stWndClass,sizeof @stWndClass
   xor eax,eax
   
;**************************************************************************
;注册窗口类
;**************************************************************************
   invoke LoadIcon,hInstance,IDI_APPLICATION
   mov@stWndClass.hIcon,eax
   
   xor eax,eax
   invoke LoadCursor,hInstance,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 szWinClass
   invoke RegisterClassEx,addr @stWndClass
   
;**********************************************************************
;建立并显示窗口
;**********************************************************************
   invoke CreateWindowEx,WS_EX_CLIENTEDGE,\
   offset szWinClass,offset szMinCaption,\
   WS_OVERLAPPEDWINDOW,\
   100,100,300,400,\
   NULL,NULL,hInstance,NULL
   movhWinMain,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_WinMainendp
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;入口
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
start:
call _WinMain
invoke ExitProcess,NULL

END start

海柯 发表于 2013-2-16 11:38:24

程序结构对着那!怎么运行失败,??

牡丹花下死做鬼 发表于 2013-2-17 12:47:48

诶    没看出为什么我技术太差了我还是多问问别人吧

海柯 发表于 2013-3-3 08:36:27

这么慌张!把窗口过程的函数地址都丢了,_ProcWinMain proc
页: [1]
查看完整版本: Win32汇编语言程序设计,捣鼓老久也没成功。