唉,尼康對於寫出真正蹩腳的鏟子非常臭名昭着。這並不令人失望。以下是一些應該起作用的聲明。首先嚐試Unicode版本。如果沒有工作,那麼你很可能使用了錯誤的窗口句柄
NativeMethods.SetWindowTextUnicode(handleYouFound, WM_SETTTEXT, IntPtr.Zero, "shoot")
:如果產生中國文字然後使用ANSI版本:
Imports System.Runtime.InteropServices
Class NativeMethods
Friend Const WM_SETTEXT As Integer = 12
<DllImport("user32.dll", EntryPoint:="SendMessageW", CharSet:=CharSet.Unicode)> _
Friend Shared Function SetWindowTextUnicode(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, ByVal lParam As String) As IntPtr
End Function
<DllImport("user32.dll", EntryPoint:="SendMessageA", CharSet:=CharSet.Ansi)> _
Friend Shared Function SetWindowTextAnsi(ByVal hWnd As IntPtr, ByVal Msg As Integer, ByVal wParam As IntPtr, ByVal lParam As String) As IntPtr
End Function
End Class
用法。使用Spy ++來仔細檢查你是否正確定位了窗口。