如何获取活动窗口的name属性,而不是标题名称。
解决方案 »
- MediaPlayer控件循环播放音乐的问题
- 求救!数据集rst不能用rst.MoveFirst,rst.MoveNext,Movelast...
- 我打算买个笔记本,请大家来推荐个好本本,价格在5000-9000元之间的
- 用VB怎样调用sys驱动文件与USB接口设备进行通讯
- 一个SELECT语句
- 急急的问:请问我能不能用form.reload的方法一劳永逸的解决这些问题:还是关于socket的
- 问个菜鸟问题 望高手费点时间 1。什么时候需要自己做类模块 2.ActiveX文档为什么网页上使用很少,有什么限制吗?
- VB能开发基于UNIX平台的应用程序吗?VC可以吗?怎么做?一定给分,还可加分.
- DateTimePicker中什么时候触发CallbackKeyDown事件
- 用VB程序写出四杆机构各部分运动状态
- 关于SQL查询语句
- 开机优先启动问题
Debug.Print Command1.Name
End Sub
Option Explicit
'获取目前选择的鼠标指针的句柄
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
'返回包含了指定点的窗口的句柄
Private Declare Function WindowFromPoint Lib "user32" (ByVal xPoint As Long, ByVal yPoint As Long) As Long
'取得一个窗体的标题文字
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
'为指定的窗口取得类名
Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
'从指定窗口的结构中取得信息
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As LongPrivate Const GWL_ID = (-12) '对话框中一个子窗口的标识符
Private Const GWL_STYLE = (-16) '窗口样式
Private Const GWL_EXSTYLE = (-20) '扩展窗口样式Private Type POINTAPI
X As Long
Y As Long
End TypePrivate Sub Command1_Click()
Timer1.Interval = Text4.Text
Timer1.Enabled = True
Text4.Enabled = False
Command1.Enabled = False
Command2.Enabled = True
End SubPrivate Sub Command2_Click()
Timer1.Enabled = False
Text4.Enabled = True
Command1.Enabled = True
Command2.Enabled = False
End SubPrivate Sub Command3_Click()
End
End SubPrivate Sub Form_Load()
Timer1.Enabled = False
Command2.Enabled = False
End SubPrivate Sub Timer1_Timer()
Dim hwnd As Long
Dim pt As POINTAPI
Dim st As Stringst = Space(256)GetCursorPos pt '取得鼠标坐标信息
Text2.Text = pt.X
Text3.Text = pt.Yhwnd = WindowFromPoint(pt.X, pt.Y)GetWindowText hwnd, st, 256 '取得窗口标题
Text1.Text = stGetClassName hwnd, st, 256 '取得窗口类名
Text5.Text = stText6.Text = GetWindowLong(hwnd, GWL_ID) '取得窗口ID
Text7.Text = GetWindowLong(hwnd, GWL_STYLE) '取得窗口风格
Text8.Text = GetWindowLong(hwnd, GWL_EXSTYLE) '取得窗口扩展风格
End Sub
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Sub Timer1_Timer()
Dim hWnd1 As Long
hWnd1 = GetForegroundWindow()
Dim lRect As RECT
Call GetWindowRect(hWnd1, lRect)
Debug.Print "left:" & lRect.Left & ";top:" & lRect.Top & ";right:" & lRect.Right & ";bottom:" & lRect.Bottom
End Sub
Private Sub Timer1_Timer()
Dim lPoint As POINTAPI
Call GetCursorPos(lPoint)
Dim hWnd1 As Long
hWnd1 = WindowFromPoint(lPoint.X, lPoint.Y)
' hWnd1 = GetForegroundWindow() Dim lRect As RECT
Call GetWindowRect(hWnd1, lRect)
Debug.Print "left:" & lRect.Left & ";top:" & lRect.Top & ";right:" & lRect.Right & ";bottom:" & lRect.Bottom
End Sub