问题:
请问 vb.net 2008 如何将 一个 指定 窗口 定义为 一个窗口.. 比如说,一个记事本窗口,定庑为 一个窗口form 然后,我就可以用 form.top 来得到这个记事本窗口的纵坐标了. 其实说简单点.我只是想获取指定窗口的位置
答案:
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String,ByVal lpWindowName As String) As Integer Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Integer,lpRect As RECT) As Integer Structure RECT Dim Left As Integer Dim Top As Integer Dim Right As Integer Dim Bottom As Integer End Structure Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles MyBase.Load Dim h As Integer,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