如何使用Visual Basic在VS2010中检索和显示当前活动窗口标题

时间:2013-12-18 06:01:57

标签: vb.net windows visual-studio-2010

我的代码:

Public Class Form1

    <DllImport("USER32.DLL", EntryPoint:="GetActiveWindow", SetLastError:=True,
    CharSet:=CharSet.Unicode, ExactSpelling:=True,
    CallingConvention:=CallingConvention.StdCall)>

    Public Shared Function GetActiveWindowHandle() As System.IntPtr
    End Function

    <DllImport("USER32.DLL", EntryPoint:="GetWindowText", SetLastError:=True,
    CharSet:=CharSet.Unicode, ExactSpelling:=True,
    CallingConvention:=CallingConvention.StdCall)>

    Public Shared Function GetActiveWindowText(ByVal hWnd As System.IntPtr, ByVal lpString As System.Text.StringBuilder, ByVal cch As Integer) As Integer
    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim caption As New System.Text.StringBuilder(256)
        Dim hWnd As IntPtr = GetActiveWindowHandle()
        GetActiveWindowText(hWnd, caption, caption.Capacity)
        MsgBox(caption.ToString)
    End Sub
End Class

import语句中存在错误。我希望表单标题根据活动窗口标题进行更改..

0 个答案:

没有答案