通过句柄向文本框中写本文出现乱码解决方法

通过句柄向文本框中写本文出现乱码
高手看看,我很苦恼,憋我半天了!
  Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
  Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
  Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
  Dim cwnd As Long, mwnd As Long
   
  Private Const WM_SETTEXT = &HC
  Private Sub Command1_Click()
  mwnd = FindWindow(vbNullString, "12345") '可以得到句柄值,wnd有返回值
  cwnd = FindWindowEx(mwnd, 0, vbNullString, "Text1") '得不到句柄,wnd返回为0
  ccwnd = FindWindowEx(mwnd, 0, vbNullString, "取消")
  Print mwnd
  Print cwnd
  Print ccwnd
  Dim iResult As Long
  iResult = SendMessage(cwnd, WM_SETTEXT, 1, "victory")
  End Sub

Private Sub Form_Load()
Shell ("D:\Program Files\Microsoft Visual Studio\VB98\project\b\工程1.exe")
End Sub


------解决方案--------------------
VB code
iResult = SendMessage(cwnd, WM_SETTEXT, 0&, ByVal "victory")

------解决方案--------------------
1、参数顺序有点问题;2、控件要用类名。


VB code
Option Explicit

Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Dim Cwnd As Long, mwnd As Long

Private Const WM_SETTEXT = &HC&
Private Sub Command1_Click()
        Dim mwnd As Long, Cwnd As Long, CCwnd As Long
        mwnd = FindWindow(vbNullString, "Form1") '可以得到句柄值,wnd有返回值
        Cwnd = FindWindowEx(mwnd, ByVal 0&, "ThunderRT6TextBox", vbNullString)    '得不到句柄,wnd返回为0
        CCwnd = FindWindowEx(mwnd, ByVal 0&, "ThunderRT6CommandButton", vbNullString)
        Print mwnd
        Print Cwnd
        Print CCwnd
        Dim iResult As Long, cText As String
        cText = "victory"
        iResult = SendMessage(Cwnd, WM_SETTEXT, Len(cText), ByVal cText)
        cText = "显示取消没有"
        iResult = SendMessage(CCwnd, WM_SETTEXT, Len(cText), ByVal cText)
        
End Sub

Private Sub Form_Load()
        Form2.Show
        Shell ("D:\Microsoft Visual Studio\VB98\工程1.exe"), vbNormalFocus
End Sub

------解决方案--------------------
对字符串传值UP UP UPUPUPUPUPUPUP
------解决方案--------------------
推荐我这个新鲜出炉的:)

VB code
Option Explicit

Private Const WM_SETTEXT = &HC
'unicode版的哟
Private Declare Function SendMessage Lib "user32" Alias "SendMessageW" (ByVal hwnd As Long, _
    ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    
Private Sub MySetWindowText(ByVal hwnd As Long, ByVal Text As String)
    Dim iResult As Long
    iResult = SendMessage(hwnd, WM_SETTEXT, 0, ByVal StrPtr(Text))

End Sub
Private Sub Command1_Click()
    MySetWindowText Text1.hwnd, "vic胜利"
End Sub