当打开一个窗体时,希望窗体根据鼠标的位置出现在相应地方.
解决方案 »
- 任务管理器里应用程序选项卡里的状态栏如何获得??
- 怎么隐藏EXCEL窗口
- vb中怎样取得像“%Windir%”、“%UserProfile%”这样的系统变量的实际路径?
- 怎样让控件获取RS的返回值!
- 读取Excel数据问题
- vb实现远程控制
- 一个CommandButton的简单问题,请大家帮帮忙!
- 用打包展开的方式做了一个安装程序?但在别的机子上安装后,运行始终显示一个类未注册的问题?请高手指教!小弟急用,解决不了:(
- 如何让 picturebox里的图片 变成黑白的
- 分数多多,VB
- 如何用DataGrid中的数据更新本地数据库数据
- 把UserControl设置成透明后,UserControl中的Image控件中的图片变成不透明了?
x As Long
y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) 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 Sub Command1_Click()
Dim t As POINTAPI
GetCursorPos t
MoveWindow Me.hwnd, t.x, t.y, Me.Width / Screen.TwipsPerPixelX, Me.Height / Screen.TwipsPerPixelY, 1
End Sub本例中窗体的ScaleMode属性为1。
x As Long
y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As LongDim t As POINTAPI
GetCursorPos t
Debug.? t.x
Debug.? t.y
Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long
说明
获取鼠标指针的当前位置
返回值
Long,非零表示成功,零表示失败。会设置GetLastError
参数表
参数 类型及说明
lpPoint POINTAPI,随同指针在屏幕像素坐标中的位置载入的一个结构
X As Long
Y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As LongPrivate Sub Form_Load()
Dim p As POINTAPI
GetCursorPos p
Me.Move p.X * Screen.TwipsPerPixelX, p.Y * Screen.TwipsPerPixelY
End Sub
Private Type POINTAPI
X As Long
Y As Long
End Type【VB声明】
Private Declare Function GetCursorPos Lib "user32" Alias "GetCursorPos" (lpPoint As POINTAPI) As Long【说明】
获取鼠标指针的当前位置 【返回值】
Long,非零表示成功,零表示失败。会设置GetLastError 【参数表】
lpPoint -------- POINTAPI,随同指针在屏幕像素坐标中的位置载入的一个结构