永发信息网

如何使用VB控制鼠标

答案:2  悬赏:10  手机版
解决时间 2021-04-13 07:05
  • 提问者网友:wodetian
  • 2021-04-12 20:49
经常在操作WINDOWS系统时遇到,程序运行中,鼠标的形状也变成漏沙的形状,请问在VB中如何实现?

小弟是新手,问一个很菜的问题,希望高手们能帮帮我。

使用Loadcursor函数已实现,如何实现改变鼠标形状后,将鼠标单击或双击的功能屏蔽掉?谢谢
最佳答案
  • 五星知识达人网友:撞了怀
  • 2021-04-12 22:17
如果是某个控件上MouseMove 事件可用MouseIcon属性实现,若要在程序运行中改变鼠标形状用API函数:LoadCursor函数实现
全部回答
  • 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

我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯