0

My code:

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

There are errors in the import statements. I want the form title to change as per the active window title..

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

0 Answers0