求助!关于WM_MOVE消息,如何从WM_MOVE消息中提取新窗口的坐标位置?

SteveYoung 2004-12-07 04:05:49
各位高手好!我看到了MSDN中对于WM_MOVE消息的描述:

lParam:
Specifies the x and y coordinates of the upper-left corner of the client area of the window. The low-order word contains the x-coordinate while the high-order word contains the y coordinate.

----------
但是我使用下述代码却无法提取这个参数中的新窗口的位置坐标

local @movedX ;窗口移动之后的x坐标
local @movedY ;窗口移动之后的y坐标

................

.elseif eax == WM_MOVE
mov ebx, lParam
and ebx, 0000ffffh ;低16位中是x坐标
mov @movedX, ebx
mov ebx, lParam
and ebx, 0ffff0000h ;高16位中是y坐标
mov ecx, 16
.while ecx != 0
shr ebx,1
.endw
mov @movedY, ebx


程序运行后,占用CPU高达100%,而且变成“无响应”,另外窗口客户区原先使用的GRAY_BRUSH画的背景,也变成白的了,在该程序中,鼠标一直处于漏斗状,不知为何?

请高手解释一下!!!非常感谢了!!!!!!!!!!!
...全文
219 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
Areslee 2004-12-08
  • 打赏
  • 举报
回复
偶不用汇编写Windows代码,看看别人的建议吧
SteveYoung 2004-12-07
  • 打赏
  • 举报
回复
;(接上述程序)
_WinMain proc

LOCAL @stWndClass:WNDCLASSEX
local @stMsg:MSG
local @dwAppX ;程序窗口的 x 坐标
local @dwAppHeight ;程序窗口的高度
LOCAL @szBuffer[1024]:byte


invoke GetModuleHandle, NULL
mov hInstance, eax
invoke LoadIcon, hInstance, IDI_ICON
mov hIcon, eax
invoke RtlZeroMemory, addr @stWndClass, sizeof @stWndClass
invoke LoadCursor, 0, IDC_ARROW
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, GRAY_BRUSH
mov @stWndClass.hbrBackground, eax
mov @stWndClass.lpszClassName, offset szCustomClassName
mov eax, hIcon
mov @stWndClass.hIcon, eax
mov @stWndClass.hIconSm, eax

invoke RegisterClassEx, addr @stWndClass

invoke GetSystemMetrics, SM_CXFULLSCREEN ;获取屏幕分辨率
mov dwXScreen, eax
invoke GetSystemMetrics, SM_CYFULLSCREEN
mov dwYScreen, eax

mov eax, dwXScreen ;设置窗口初始化时的 x 坐标
shr eax, 1
sub eax, 6 ;分辨率宽度/2之后,总比理论值多6,遂减去之
mov @dwAppX, eax ; x 坐标存入 @dwAppX 变量

mov eax, dwYScreen
add eax, 20
mov @dwAppHeight, eax ;程序窗口高度,这个高度可根据分辨率及任务栏大小自适应

invoke CreateWindowEx, WS_EX_CLIENTEDGE or WS_EX_APPWINDOW, offset szCustomClassName, offset szWndTitle,\
WS_OVERLAPPED or WS_CAPTION or WS_SYSMENU or WS_MINIMIZEBOX or WS_THICKFRAME,\
@dwAppX, 2, 150, @dwAppHeight, 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
---------------
程序有点乱,麻烦大哥复制到记事本中看一下吧,我水平很烂,程序写得很菜,大哥不要笑话啊 -_-!
SteveYoung 2004-12-07
  • 打赏
  • 举报
回复
我把源程序贴上来吧
------------------------
.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

IDI_ICON equ 101

.data?

hInstance dd ?
hIcon dd ?
hWinMain dd ?
dwXScreen dd ? ;屏幕分辨率.x
dwYScreen dd ? ;屏幕分辨率.y
stRectAppWnd RECT <> ;程序窗口结构,并非客户区结构

.const

szCustomClassName db 'AutoHide',0
szWndText db 'You should see these characters in the window custom RECT', 0
szWndTitle db 'Auto-hiding', 0
szMsgBoxFormat db '新窗口的坐标为: x = %d, y = %d', 0

.code

_ProcWinMain proc uses ebx esi edi hWnd, uMsg, wParam, lParam

local @stPS:PAINTSTRUCT
local @hDC
LOCAL @stRect:RECT
local @movedX
local @movedY
local @szBuffer[1024]:byte

mov eax, uMsg


.if eax == WM_PAINT

invoke BeginPaint, hWinMain, addr @stPS
mov @hDC, eax
invoke GetClientRect, hWnd, addr @stRect
invoke DrawText, @hDC, addr szWndText, -1, addr @stRect, DT_SINGLELINE or DT_CENTER or DT_VCENTER
invoke EndPaint, hWnd, addr @stPS


.elseif eax == WM_MOVE
push lParam
mov ebx, lParam
and ebx, 0000ffffh ;低 16 位中是 x 坐标
mov @movedX, ebx ;存入移动窗口之后的 x 坐标

pop ebx
and ebx, 0ffff0000h ;高 16 位中是 y 坐标
shr ebx, 16
mov @movedY, ebx ;存入移动窗口之后的 y 坐标
invoke wsprintf, addr @szBuffer, addr szMsgBoxFormat, @movedX, @movedY
invoke MessageBox, NULL, addr @szBuffer, addr @szBuffer, MB_OK or MB_ICONINFORMATION







.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

SteveYoung 2004-12-07
  • 打赏
  • 举报
回复
谢谢Areslee大哥的解答,非常感谢!可是我还有一些不明白的地方,在创建窗口的时候,我指定的y坐标是2,为什么这里创建之后,却出来了27的坐标呢?
Areslee 2004-12-07
  • 打赏
  • 举报
回复
mov ecx, 16
.while ecx != 0
shr ebx,1
.endw
换成:
shr ebx,16
SteveYoung 2004-12-07
  • 打赏
  • 举报
回复
更迷惑了,我把.while -- .endw 改成了 .repeat --- .until,竟然没有CPU占用率高的情况了,程序也正常了!!!!太奇怪了吧?

21,497

社区成员

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

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