| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 865 人关注过本帖
标题:[获取窗口信息的代码
只看楼主 加入收藏
sd287054
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2007-7-27
收藏
 问题点数:0 回复次数:5 
[获取窗口信息的代码

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 lpSting 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 Long

Private Const GWL_ID = (-12)

Private Const GWL_STYLE = (-16)
Private Const GWL_EXSTYLE = (-20)

Private Type POINTAPI
x As Long
y As Long
End Type

Private Sub Command1_Click()
Timer1.Interval = Text4.Text
Timer1.Enabled = True
Text4.Enabled = False
Command1.Enabled = False
Command2.Enabled = True
End Sub

Private Sub Command2_Click()
Timer1.Enabled = False
Text4.Enabled = True
Command1.enablel = True
Command2.enablel = False
End Sub

Private Sub Command3_Click()
End
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Command2.Enabled = False
End Sub

Private Sub Timer1_Timer()
Dim hwnd As Long
Dim pt As POINTAPI
Dim st As String
st = Space(256)
GetCursorPos pt
Text2.Text = pt.x
Text3.Text = pt.y
hwnd = WindowFromPoint(pt.x, pt.y)
GetWindowText hwnd, st, 256
Text1.Text = st
GetClassName hwnd, sl, 256
Text5.Text = st
Text6.Text = GetWindowlong(hwnd, GWL_ID)
Text7.Text = GetWindowlong(hwnd, GWL, Style)
Text8.Text = GetWindowlong(hwnd, GWL_EXSTYLE)
End Sub
这段代码是我从书上抄写下来的,不知道到哪错了老是运行不起来~!

搜索更多相关主题的帖子: Long ByVal Lib Function 
2007-10-17 03:00
永夜的极光
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:2721
专家分:1
注 册:2007-10-9
收藏
得分:0 
把错误提示带上,错误现象说清楚点

从BFS(Breadth First Study)到DFS(Depth First Study)
2007-10-17 07:54
随风逐流
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:passerby
等 级:版主
威 望:8
帖 子:4054
专家分:271
注 册:2007-6-13
收藏
得分:0 

'修改如下,测试通过.
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 lpSting 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 Long

Private Const GWL_ID = (-12)

Private Const GWL_STYLE = (-16)
Private Const GWL_EXSTYLE = (-20)

Private Type POINTAPI
x As Long
y As Long
End Type

Private Sub Command1_Click()
Timer1.Interval = Text4.Text
Timer1.Enabled = True
Text4.Enabled = False
Command1.Enabled = False
Command2.Enabled = True
End Sub

Private Sub Command2_Click()
Timer1.Enabled = False
Text4.Enabled = True
Command1.enabled = True
Command2.enabled = False
End Sub

Private Sub Command3_Click()
End
End Sub
Private Sub Form_Load()
Timer1.Enabled = False
Command2.Enabled = False
End Sub

Private Sub Timer1_Timer()
Dim hwnd As Long
Dim pt As POINTAPI
Dim st As String
st = Space(256)
GetCursorPos pt
Text2.Text = pt.x
Text3.Text = pt.y
hwnd = WindowFromPoint(pt.x, pt.y)
GetWindowText hwnd, st, 256
Text1.Text = st
GetClassName hwnd, st, 256
Text5.Text = st
Text6.Text = GetWindowLong(hwnd, GWL_ID)
Text7.Text = GetWindowLong(hwnd, GWL_STYLE)
Text8.Text = GetWindowLong(hwnd, GWL_EXSTYLE)
End Sub


[此贴子已经被作者于2007-10-17 8:58:24编辑过]


[url=http://www./html/6/6694/]极道金丹[/url][url=http://www./html/2/2849/]九阴九阳[/url][url=http://www./html/2/2596/]凡人修仙传[/url]
2007-10-17 08:53
sd287054
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2007-7-27
收藏
得分:0 
谢谢,我去测试下,因为昨天上夜班,所以到现在才起来~!
2007-10-17 21:36
sd287054
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2007-7-27
收藏
得分:0 
这样我直接发源代码和程序给你们看吧,运行还是出错~!
HjPgjU5x.rar (2.84 KB) [获取窗口信息的代码


因本人很菜,VB里指明错误但我还是很多地方都看不出错在哪~!
所以还请哥哥门多费心了~!
2007-10-17 21:43
sd287054
Rank: 1
等 级:新手上路
帖 子:34
专家分:0
注 册:2007-7-27
收藏
得分:0 

都24小时了都没人看么~!

2007-10-18 22:41
快速回复:[获取窗口信息的代码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015602 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved