当前位置: 代码迷 >> 汇编语言 >> WIN32 汇编 刚学习的人问一点有关问题
  详细解决方案

WIN32 汇编 刚学习的人问一点有关问题

热度:386   发布时间:2016-05-02 04:46:02.0
WIN32 汇编 刚学习的人问一点问题
正在学win32汇编,使用罗云彬的教科书!目前看到了myfirstwindow那一个源程序了,书上说90%的人在看到这段代码的时候退缩了,呵呵!我盯住看了好几天了,貌似有点头绪了,还是问题多多啊,希望得到大家的帮助!
我先把代码copy进来!我把问题写在代码中间了红色字体,期待大家给我指点!




 .386
                 .model flat,stdcall
                  option casemap:none
 
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
include gdi32.inc
includelib gdi32.lib

                 .data?
hInstance     dd  ?
hWinMain      dd  ?

                 .const
szClassName   db    'My class',0
szCaptionMain db    'My First Window!',0
szText        db    'Win32 Assembly,Simple and powerful!',0

                 .code
_ProcWinMain   proc   uses ebx edi esi,hWnd,uMsg,wParam,lParam
              local  @stPs:PAINTSTRUCT
  local  @stRect:RECT
  local  @HDC
  mov eax,uMsg
;这里的uMsg,包括hWnd,wParam,lParam它们的内容到底是什么?搞不清啊!
;看遍代码也没发现哪里有对这几个参数赋值的语句啊!!
  
  .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
;[email protected],可是全部代码都没有对MSG进行说明,
;这个MSG结构是不是系统自动生成的,不用对它进行操作啊?   
  invoke GetModuleHandle,NULL
  mov hInstance,eax
  ;这个hInstance的值是什么呢?是哪一个句柄呢?程序本身的吗?有什么意义呢?
  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
  invoke GetStockObject,WHITE_BRUSH
  mov @stWndClass.hbrBackground,eax
  mov @stWndClass.lpszClassName,offset szClassName
  invoke RegisterClassEx,addr @stWndClass
;----------------------------------------------------------\
;              建立窗口
;----------------------------------------------------------
  
  invoke CreateWindowEx,WS_EX_TOPMOST,\
         offset szClassName,offset szCaptionMain,\
 WS_OVERLAPPEDWINDOW or WS_VSCROLL or WS_HSCROLL,\
 200,200,500,500,\
 NULL,NULL,hInstance,NULL
  mov    hWinMain,eax
;我想这里的hWinMain是获取的即将建立的窗口的句柄吧?
  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
  相关解决方案