?? 鼠標(biāo)滾輪問題 .txt
字號(hào):
鼠標(biāo)滾輪問題
相關(guān)的例子:下載>>> 作者:山原依綱 于2008-7-19上傳
--------------------------------------------------------------------------------
前幾天在CSDN上看到一個(gè)VB高手準(zhǔn)備收徒弟,面試的題目是“編寫通過鼠標(biāo)滾輪來(lái)控制窗口大小的程序”。居然很多人認(rèn)為這個(gè)題目很困難。趁著這個(gè)機(jī)會(huì),我也研究了一下鼠標(biāo)滾輪的問題。
當(dāng)鼠標(biāo)滾輪轉(zhuǎn)動(dòng)時(shí),WM_MOUSEWHEEL消息將會(huì)送至當(dāng)前聚焦的窗口。
WM_MOUSEWHEEL Notification
The WM_MOUSEWHEEL message is sent to the focus window when the mouse wheel is rotated. The DefWindowProc function propagates the message to the window's parent. There should be no internal forwarding of the message, since DefWindowProc propagates it up the parent chain until it finds a window that processes it.
A window receives this message through its WindowProc function.
Syntax
WM_MOUSEWHEEL
WPARAM wParam
LPARAM lParam;
Parameters
wParam
The high-order word indicates the distance the wheel is rotated, expressed in multiples or divisions of WHEEL_DELTA, which is 120. A positive value indicates that the wheel was rotated forward, away from the user; a negative value indicates that the wheel was rotated backward, toward the user.
高word表明滾輪轉(zhuǎn)動(dòng)的距離,以WHEEL_DELTA(120)為單位。正數(shù)表明向前轉(zhuǎn)動(dòng),方向是遠(yuǎn)離使用者。負(fù)數(shù)表示向回轉(zhuǎn)動(dòng),轉(zhuǎn)向使用者。
The low-order word indicates whether various virtual keys are down. This parameter can be one or more of the following values.
低word表明此時(shí)是否有虛擬鍵按下。這個(gè)參數(shù)是如下一個(gè)或者多個(gè)值的組合,
MK_CONTROL
The CTRL key is down.
MK_LBUTTON
The left mouse button is down.
MK_MBUTTON
The middle mouse button is down.
MK_RBUTTON
The right mouse button is down.
MK_SHIFT
The SHIFT key is down.
MK_XBUTTON1
Windows 2000/XP: The first X button is down.
MK_XBUTTON2
Windows 2000/XP: The second X button is down.
lParam
The low-order word specifies the x-coordinate of the pointer, relative to the upper-left corner of the screen.
低word表明以左上角為原點(diǎn)的當(dāng)前鼠標(biāo)所在的x坐標(biāo)。
The high-order word specifies the y-coordinate of the pointer, relative to the upper-left corner of the screen.
高word表明以左上角為起點(diǎn)的當(dāng)前鼠標(biāo)所在的y坐標(biāo)。
Return Value
If an application processes this message, it should return zero.
如果應(yīng)用程序處理了這個(gè)消息,應(yīng)該返回0.
看上去應(yīng)用起來(lái)應(yīng)該非常簡(jiǎn)單,于是編寫了簡(jiǎn)單的Demo:
;MASMPlus 代碼模板 - 普通的 Windows 程序代碼
.386
.Model Flat, StdCall
Option Casemap :None
Include windows.inc
Include user32.inc
Include kernel32.inc
Include gdi32.inc
includelib gdi32.lib
IncludeLib user32.lib
IncludeLib kernel32.lib
include macro.asm
WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
.DATA
szClassName db "MASMPlus_Class",0
.DATA?
hInstance dd ?
.CODE
START:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke WinMain,hInstance,NULL,NULL,SW_SHOWDEFAULT
invoke ExitProcess,0
WinMain proc hInst:DWORD,hPrevInst:DWORD,CmdLine:DWORD,CmdShow:DWORD
LOCAL wc :WNDCLASSEX
LOCAL msg :MSG
local hWnd :HWND
mov wc.cbSize,sizeof WNDCLASSEX
mov wc.style,CS_HREDRAW or CS_VREDRAW or CS_BYTEALIGNWINDOW
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 szClassName
invoke LoadIcon,hInst,100
mov wc.hIcon,eax
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax
mov wc.hIconSm,0
invoke RegisterClassEx, ADDR wc
invoke CreateWindowEx,NULL,ADDR szClassName,CTXT("http://www.aogosoft.com"),WS_OVERLAPPEDWINDOW,200,200,400,200,NULL,NULL,hInst,NULL
mov hWnd,eax
invoke ShowWindow,hWnd,SW_SHOWNORMAL
invoke UpdateWindow,hWnd
StartLoop:
invoke GetMessage,ADDR msg,NULL,0,0
cmp eax, 0
je ExitLoop
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
jmp StartLoop
ExitLoop:
mov eax,msg.wParam
ret
WinMain endp
WndProc proc hWin:DWORD,uMsg:DWORD,wParam :DWORD,lParam :DWORD
.if uMsg==WM_CREATE
.elseif uMsg == WM_MOUSEWHEEL
mov eax,wParam ;真正有用的代碼只有紅色一點(diǎn)點(diǎn)
shr eax,16
test eax,8000h
jz wheeldown
invoke SetWindowText,hWin,CTXT("向下滾!")
jmp @f
wheeldown:
invoke SetWindowText,hWin,CTXT("向上滾!")
@@:
.elseif uMsg == WM_DESTROY
invoke PostQuitMessage,NULL
.else
invoke DefWindowProc,hWin,uMsg,wParam,lParam
.endif
ret
WndProc endp
END START
希望本文能起到拋磚引玉的作用,記得鼠標(biāo)除了左右鍵,還有這樣一個(gè)非常方便的功能。
--------------------------------------------------------------------------------
<<<上一篇 歡迎訪問AoGo匯編小站:http://www.aogosoft.com 下一篇>>>
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -