我的程序为什么不能正常运行呀?

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
...全文
24 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
hgwi 2003-05-04
  • 打赏
  • 举报
回复
对呀我把两个参数传送到EAX,EDX中原因是.IF指令必须比较至少含1个寄存器的两个内容
abutter 2003-05-04
  • 打赏
  • 举报
回复
什么运行不了,是编译不了还是运行出错。

我的经验是,如果你的程序出错但能编译成功,一般是指针的问题,就是API中的指针参数你没有写对造成空指针。

仔细看看程序吧。
用户 昵称 2003-05-04
  • 打赏
  • 举报
回复
有两个地方可能需要注意
1)就是屏幕坐标和窗体坐标的关系
2)就是可能按钮的鼠标移动的消息你接收不到。
用户 昵称 2003-05-02
  • 打赏
  • 举报
回复
我对32位程序不太懂,觉得你对MousePoint.x和MousePoint.y都判断eax,edx是不是不对?
.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
invoke SetWindowPos,hwndButton,NULL,ButtonRect.left, ButtonRect.right,NULL,NULL,SWP_NOSIZE
.ENDIF

21,459

社区成员

发帖
与我相关
我的任务
社区描述
汇编语言(Assembly Language)是任何一种用于电子计算机、微处理器、微控制器或其他可编程器件的低级语言,亦称为符号语言。
社区管理员
  • 汇编语言
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧