vb 如何获取一个窗口的坐标

vb如何获取一个程序窗口(例如:酷狗)在屏幕中的坐标... vb 如何获取一个程序窗口(例如:酷狗) 在屏幕中的坐标 展开
 我来答
ARTERIOSCLEROS
推荐于2018-05-09 · TA获得超过4185个赞
知道大有可为答主
回答量:1672
采纳率:0%
帮助的人:2454万
展开全部
代码如下。
=============
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
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 Form_Load()
Dim h As Long, r As RECT
h = FindWindow(vbNullString, "酷狗") '这里写上你的窗口标题,必须一字不差
GetWindowRect h, r
MsgBox "左上角坐标(" & r.Left & "," & r.Top & ")" & vbCrLf & "右下角坐标(" & r.Right & "," & r.Bottom & ")" & vbCrLf & "窗口高" & r.Bottom - r.Top & "窗口宽" & r.Right - r.Left
End
End Sub
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
cindy9966
2008-11-15 · 超过28用户采纳过TA的回答
知道小有建树答主
回答量:174
采纳率:0%
帮助的人:62.4万
展开全部
先根据窗口标题 或者 类名 取得 该窗口 句柄

然后这个API
Declare Function GetWindowPlacement Lib "user32" Alias "GetWindowPlacement" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long

lpwndpl 包好该窗口位置信息

Type WINDOWPLACEMENT
Length As Long
flags As Long
showCmd As Long
ptMinPosition As POINTAPI
ptMaxPosition As POINTAPI
rcNormalPosition As RECT
End Type
字段表
字段 类型及说明
Length Long,这个结构的长度(size),必须是44
flags Long,以下的两个常数之一
WPF_SETMINPOSITION The ptMinPosition specifies the x,y location of the window when minimized.
WPF_RESTORETOMAXIMIZED The SW_SHOWMINIMIZED constant must be specified in the showCmd parameter. Indicates that the window should be maximized the next time it is restored.
showCmd Long,Visibility flags
ptMinPosition POINTAPI,The x,y location of the window when minimized.
ptMaxPosition POINTAPI,The x,y location of the window location when maximized.
rcNormalPosition RECT,The position and size of the window when it is restored (normal condition).
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
瞧红尘
2008-11-15 · TA获得超过305个赞
知道小有建树答主
回答量:64
采纳率:0%
帮助的人:39.9万
展开全部
'获取窗体为"酷狗"的 屏幕坐标 声明部分
Private Declare Function GetWindowPlacement Lib "user32" (ByVal hwnd As Long, lpwndpl As WINDOWPLACEMENT) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Type WINDOWPLACEMENT
Length As Long
flags As Long
showCmd As Long
ptMinPosition As POINTAPI
ptMaxPosition As POINTAPI
rcNormalPosition As RECT
End Type
Dim LookhcWinForm As WINDOWPLACEMENT
'-----------------------------------------代码

Private Sub Form_Load()
GetWindowPlacement FindWindow(vbNullString, "酷狗"), LookhcWinForm

MsgBox "左=" & LookhcWinForm.rcNormalPosition.Left & vbCrLf & _
"右=" & LookhcWinForm.rcNormalPosition.Right & vbCrLf & _
"顶=" & LookhcWinForm.rcNormalPosition.Top & vbCrLf & _
"底=" & LookhcWinForm.rcNormalPosition.Bottom
End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
方之起
2008-11-15
知道答主
回答量:34
采纳率:0%
帮助的人:18.8万
展开全部
_xposition()=
_yposition()=
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
ba527
2008-11-16 · TA获得超过120个赞
知道小有建树答主
回答量:474
采纳率:0%
帮助的人:221万
展开全部
使用API。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 2条折叠回答
收起 更多回答(4)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

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

类别

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

说明

0/200

提交
取消

辅 助

模 式