如何使用VB控制鼠标
- 提问者网友:wodetian
- 2021-04-12 20:49
小弟是新手,问一个很菜的问题,希望高手们能帮帮我。
使用Loadcursor函数已实现,如何实现改变鼠标形状后,将鼠标单击或双击的功能屏蔽掉?谢谢
- 五星知识达人网友:撞了怀
- 2021-04-12 22:17
- 1楼网友:洎扰庸人
- 2021-04-12 22:34
form1添加两个command控件和一个timer控件,添加如下代码:
dim moulast as pointapi dim moubegin as pointapi dim movecount as integer dim mousestep as pointapi
private sub command1_mouseup(button as integer, shift as integer, x as single, y as single) msgbox ("你按下了command1键") timer1.enabled = false end sub
private sub command2_click() dim destrect as rect '获得command1在屏幕上的坐标。 getwindowrect command1.hwnd, destrect '获得要移动到的位置的光标的坐标。 moulast.x = destrect.left moulast.y = destrect.top '获得当前光标的坐标。 getcursorpos moubegin timer1.enabled = true stepx = moulast.x - moubegin.x stepy = moulast.y - moubegin.y mousestep = moubegin end sub
private sub timer1_timer() mousestep.x = mousestep.x + 15 mousestep.y = mousestep.y + 10 setcursorpos mousestep.x, mousestep.y if mousestep.x > moulast.x and mousestep.y > moulast.y then timer1.enabled = false sendmessage command1.hwnd, wm_lbuttonup, 10, 10 end if end sub module1代码:
public type rect left as long top as long right as long bottom as long end type
public type pointapi x as long y as long end type
public const wm_lbuttonup = &h202
public declare function getwindowrect lib "user32" (byval hwnd as long, lprect as rect) as long public declare function setcursorpos lib "user32" (byval x as long, byval y as long) as long public declare function getcursorpos lib "user32" (lppoint as pointapi) as long public declare function sendmessage lib "user32" alias "sendmessagea" (byval hwnd as long, byval wmsg as long, byval wparam as long, lparam as any) as long