如何查找指定窗口的起始坐标,及宽度\高度

坐吃山空 2002-06-22 09:13:33
如何查找指定窗口的起始坐标,及宽度\高度
...全文
117 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
tianxinet 2002-06-22
  • 打赏
  • 举报
回复
问问题要说清楚嘛,都写完了你才说明真正用意^^
上面的代码,如果可以参考的话自己改一改吧
坐吃山空 2002-06-22
  • 打赏
  • 举报
回复
tonton,说得具体些行吗,我的程式是这样的

。。。。
Dim rc As Rect
Dim mDC As Long

GetWindowRect GetDesktopWindow(), rc


结果rc只具有Max,Min两个属性,如何构成起始坐标,宽,高
tianxinet 2002-06-22
  • 打赏
  • 举报
回复
'用API解决你提出的问题
'该例子需要Form上和一个TextBox(text1)和
'一个commandbutton(command1)
'使用时,在text1中输入桌面上任何一个窗体的标题,按command1后,
'会在窗口的左上角显示指定窗体的高度、宽度、四个角的坐标

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long

Private Sub Command1_Click()

Me.Cls

Dim frmHwnd As Long
Dim frmRect As RECT
Dim frmHeight As Long
Dim frmWidth As Long

frmHwnd = FindWindow(vbNullString, Text1.Text)
If frmHwnd = 0 Then
MsgBox "窗体不存在"
Else
GetWindowRect frmHwnd, frmRect

frmHeight = frmRect.Bottom - frmRect.Top
frmWidth = frmRect.Right - frmRect.Left

Me.Print "width=" & frmWidth
Me.Print "height=" & frmHeight
Me.Print "lefttop(" & frmRect.Left & "," & frmRect.Top & ")"
Me.Print "righttop(" & frmRect.Right & "," & frmRect.Top & ")"
Me.Print "rightbottom(" & frmRect.Right & "," & frmRect.Bottom & ")"
Me.Print "leftbottom(" & frmRect.Left & "," & frmRect.Bottom & ")"
End If

End Sub
tonton 2002-06-22
  • 打赏
  • 举报
回复
使用GetWindowRect这个API
rbird 2002-06-22
  • 打赏
  • 举报
回复
王国荣的那本API讲的很详细。
坐吃山空 2002-06-22
  • 打赏
  • 举报
回复
呵呵,我指的不是VB窗口,是任意的Windows窗口...是这样的,我想做一个程序,让它一直在后台运行,遇如开启某个指定的Windows窗口,它就把这个窗口抓下来
luccy 2002-06-22
  • 打赏
  • 举报
回复
横坐标:yourform.left
纵坐标:yourform.top
宽:yourform.width
高:yourform.height

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧