展开全部
代码如下。
=============
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
=============
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
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
先根据窗口标题 或者 类名 取得 该窗口 句柄
然后这个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).
然后这个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).
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
'获取窗体为"酷狗"的 屏幕坐标 声明部分
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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
_xposition()=
_yposition()=
_yposition()=
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
使用API。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询