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

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
...全文
124 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
内容概要:本文围绕基于A星(A*)算法的螺旋式全覆盖路径规划展开研究,提出一种结合A*全局搜索能力与螺旋遍历策略的栅格地图路径规划方法,利用Matlab实现机器人或无人机在指定区域内的无遗漏、高效覆盖路径生成。研究重点在于优化传统往返式扫描路径中存在的转向频繁、路径不连续等问题,通过引入螺旋机制提升路径的连贯性与遍历效率,适用于复杂环境中需要系统性作业的场景。文中提供了完整的Matlab代码实现,便于读者复现与改进算法。; 适合人群:具备一定Matlab编程基础,从事 robotics、自动化、人工智能及相关领域的科研人员与工程技术人员,尤其适合研究生及以上学历或有相关项目开发经验的专业人士。; 使用场景及目标:①应用于农业自动化巡检、环境监测、仓库盘点、无人机航测等需全覆盖作业的场景;②帮助研究人员深入理解A*算法在全覆盖路径规划中的扩展应用,掌握螺旋策略与经典算法融合的设计思路;③为智能移动设备的自主导航与任务规划提供可复用的算法模型与仿真验证手段。; 阅读建议:建议读者结合提供的Matlab代码进行实践操作,重点关注A*算法与螺旋遍历逻辑的协同机制,通过调整参数与地图环境验证算法性能,并参考同类路径规划案例深化对智能优化策略的理解。

21,500

社区成员

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

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