我的程序为什么不能正常运行呀?
hgwi 2003-05-02 01:05:22 本来想让鼠标一进入窗口按钮就自动移开,但为什么鼠标一进入窗口,按钮就不见了,到底是什么地方出的问题呀?请帮帮我谢谢!
.386
.model flat,stdcall
option casemap:none
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
iRand proto :DWORD, :DWORD
include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib
.data
ClassName db "SimpleWinClass",0
AppName db "程序演示-控件",0
ButtonClassName db "button",0
ButtonText db "来点我",0
.data?
hInstance HINSTANCE ?
CommandLine LPSTR ?
hwndButton HWND ?
MousePoint POINT <>
ButtonPoint POINT <>
ButtonRect RECT <>
WinRect RECT<>
.const
ButtonID equ 1
.code
start:
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke GetCommandLine
mov CommandLine,eax
invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
invoke ExitProcess,eax
WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND
mov wc.cbSize,SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,NULL
push hInst
pop wc.hInstance
mov wc.hbrBackground,COLOR_BTNFACE+1
mov wc.lpszMenuName,NULL
mov wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,NULL,IDI_APPLICATION
mov wc.hIcon,eax
mov wc.hIconSm,eax
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax
invoke RegisterClassEx, addr wc
invoke CreateWindowEx,NULL,ADDR ClassName, \
ADDR AppName, WS_OVERLAPPEDWINDOW,\
CW_USEDEFAULT, CW_USEDEFAULT,\
300,200,NULL,NULL, hInst,NULL
mov hwnd,eax
invoke ShowWindow, hwnd,SW_SHOWNORMAL
invoke UpdateWindow, hwnd
.WHILE TRUE
invoke GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDW
mov eax,msg.wParam
ret
WinMain endp
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
.IF uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.ELSEIF uMsg==WM_CREATE
invoke CreateWindowEx,NULL, ADDR uttonClassName,ADDR \ButtonText,WS_CHILD or WS_VISIBLE or \BS_DEFPUSHBUTTON,70,75,140,25,hWnd,ButtonID,hInstance,NULL
mov hwndButton,eax
invoke SetFocus, hwndButton
.ELSEIF uMsg==WM_MOUSEMOVE
mov eax,lParam
and eax,0FFFFH
mov MousePoint.x,eax
mov eax,lParam
shr eax,16
mov MousePoint.y,eax
invoke GetWindowRect,hwndButton,ADDR ButtonRect
mov eax,ButtonRect.left
mov edx,ButtonRect.right
.IF MousePoint.x>eax&&MousePoint.x<edx
mov eax,ButtonRect.top
mov edx,ButtonRect.bottom
.IF MousePoint.y>eax&&MousePoint.y<edx
invoke GetWindowRect,hInstance,ADDR WinRect invoke iRand,WinRect.left,WinRect.right
mov ButtonRect.left,eax
invoke iRand,WinRect.top,WinRect.bottom mov ButtonRect.right,eax
.ENDIF
.ENDIF
invoke SetWindowPos,hwndButton,NULL,ButtonRect.left,
\ButtonRect.right,NULL,NULL,SWP_NOSIZE
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
xor eax,eax
ret
WndProc endp
iRand proc uses ecx edx first:DWORD, second:DWORD
invoke GetTickCount ; 取得随机数种子,当然,可用别的方法代替
mov ecx, 23 ; X = ecx = 23
mul ecx ; eax = eax * X
add eax, 7 ; eax = eax + Y (Y = 7)
mov ecx, second ; ecx = 上限
sub ecx, first ; ecx = 上限 - 下限
inc ecx ; Z = ecx + 1 (得到了范围)
xor edx, edx ; edx = 0
div ecx ; eax = eax mod Z (余数在edx里面)
add edx, first ; 修正产生的随机数的范围
mov eax, edx ; eax = Rand_Number
ret
iRand endp
end start