VB窗口跟鼠标走

PrivateDeclareFunctionShellExecuteLib"shell32.dll"Alias"ShellExecuteA"(ByValhwndAsLon... Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long

Private Type POINTAPI
X As Long
Y As Long
End Type

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Sub Form_Load()
Dim myval
myval = SetWindowPos(Me.hwnd, -1, 0, 0, 0, 0, 3)

End Sub

Private Sub Timer1_Timer()
Dim Point As POINTAPI
GetCursorPos Point
Form1.Left = Point.X
Form1.Cls
Print CStr(Point.X)
Print CStr(Point.Y)
Form1.Top = Point.Y
End Sub

为什么这样窗口不会跟着鼠标`怎么让他跟着鼠标`
展开
 我来答
ljl88900
2008-12-01 · TA获得超过2661个赞
知道大有可为答主
回答量:2197
采纳率:100%
帮助的人:2630万
展开全部
这样改:
Option Explicit

Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long

Private Type POINTAPI
x As Long
y As Long
End Type

Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Sub Form_Load()
Dim myval
myval = SetWindowPos(Me.hwnd, -1, 0, 0, 0, 0, 3)

End Sub

Private Sub Timer1_Timer()
Dim mPOINT As POINTAPI
GetCursorPos mPOINT
MoveWindow Me.hwnd, mPOINT.x, mPOINT.y, Me.Width / Screen.TwipsPerPixelX, Me.Height / Screen.TwipsPerPixelY, 1 '移动窗口

Form1.Cls
Print CStr(mPOINT.x)
Print CStr(mPOINT.y)
End Sub
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式