注册 登录
编程论坛 VB.NET论坛

各位前輩好!!該如何在VS2008中調用GetWindowRect

uirty 发布于 2010-12-04 02:51, 1175 次点击
2008中並無報告出錯 ,但是程式按鍵執行就當.....請各位前輩指導T_T.
程序代码:
Public Class Form1
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
    Private Declare Function SetCursorPos Lib "user32" Alias "SetCursorPos" (ByVal x As Long, ByVal y As Long) As Integer
    Private Declare Function GetWindowRect Lib "user32" Alias "GetWindowRect" (ByVal hwnd As Long, ByVal lpRect As RECT) As Integer
    Private Structure RECT
        Public Left As Integer
        Public Top As Integer
        Public Right As Integer
        Public Bottom As Integer
    End Structure
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim windoh As Integer
        Dim windoxy As RECT
        Dim windoxd As Integer
        windoh = FindWindow(vbNullString, "新增文字文件 (6).txt - 記事本")

        If windoh = 0 Then
            MsgBox("無法獲取窗口")
            Threading.Thread.Sleep(100) ' 暫停1秒
            SetCursorPos(0, 0) ' 將滑鼠位置設定為0, 0
        End If

        windoxd = GetWindowRect(windoh, windoxy)

        TextBoxX.Text = windoxy.Top
        TextBoxY.Text = windoxy.Left
    End Sub
End Class

 
2 回复
#2
不说也罢2010-12-04 16:15
程序代码:
Public Class Form1
    Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
    Private Declare Function SetCursorPos Lib "user32" Alias "SetCursorPos" (ByVal x As Long, ByVal y As Long) As Integer
    Private Declare Function GetWindowRect Lib "user32 " Alias "GetWindowRect" (ByVal hwnd As Integer, ByRef lpRect As RECT) As Boolean
    Private Structure RECT
        Public Left As Integer
        Public Top As Integer
        Public Right As Integer
        Public Bottom As Integer
    End Structure
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim windoh As Integer
        Dim windoxy As New RECT
        Dim windoxd As Long
        windoh = FindWindow(vbNullString, "新增文字文件 (6).txt - 记事本")

        If windoh = 0 Then
            MsgBox("無法獲取窗口")
            Threading.Thread.Sleep(100) ' 暫停1秒
            SetCursorPos(0, 0) ' 將滑鼠位置設定為0, 0
        End If

        windoxd = GetWindowRect(windoh, windoxy)

        TextBoxX.Text = windoxy.Top
        TextBoxY.Text = windoxy.Left
    End Sub
End Class
注意GetWindowRect的声明
#3
uirty2010-12-04 23:35
回复 2楼 不说也罢
感謝前輩的指導 我的腦亂了
1