当前位置: 代码迷 >> 汇编语言 >> 按照琢石成器下写的,为什么不行
  详细解决方案

按照琢石成器下写的,为什么不行

热度:3626   发布时间:2013-02-26 00:00:00.0
按照琢石成器上写的,为什么不行
最近在罗云彬老师的《琢石成器:Windows下32位汇编语言程序设计》,按照其中的源码敲了一个显示窗口的程序,但是运行起来却不能显示窗口,求指教!
源码如下:
.386
.model flat , stdcall
option casemap:none

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 db "MyClass" , 0
szCaptionMain db "First Window" , 0
szText db "Win32 Assemble , Simple and powerful !" , 0

.code
_ProcWinMain proc uses ebx edi esi , hwnd ,uMsg , wParam , lParam

LOCAL @stPs : PAINTSTRUCT
LOCAL @stRect : RECT
LOCAL @hDc
ret
mov eax ,uMsg
.if eax==WM_PAINT
invoke BeginPaint, hwnd , addr @stPs
mov @hDc , eax
invoke GetClientRect , hwnd , addr @stRect
invoke DrawText, addr @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,hwnd
invoke PostQuitMessage,NULL
.else 
invoke DefWindowProc, hwnd , uMsg , wParam , lParam
ret
.endif
xor eax , eax
ret



_ProcWinMain endp
_WinMain proc

LOCAL @stWindowClass : WNDCLASS
LOCAL @stMsg : MSG
invoke GetModuleHandle, NULL
mov hInstance , eax
invoke RtlZeroMemory,addr @stWindowClass , sizeof WNDCLASS

invoke LoadCursor , 0 ,IDC_ARROW
mov @stWindowClass.hCursor , eax
push hInstance
pop @stWindowClass.hInstance
mov @stWindowClass.style , CS_HREDRAW or CS_VREDRAW
mov @stWindowClass.lpfnWndProc , offset _ProcWinMain
mov @stWindowClass.hbrBackground , COLOR_WINDOW+1
mov @stWindowClass.lpszMenuName , offset szClassname
invoke RegisterClassEx, addr @stWindowClass

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

------解决方案--------------------------------------------------------
其实你可以参考一下VC的代码。
  相关解决方案