当前位置:编程学习 > VB >>

VB2010中关于使用SendMessage API向外部程序控件中输入字符串的问题。

各位大侠,小弟菜鸟,因工作需要,临时捉刀,需要一个小软件实现这样一个功能,软件启动,在系统中注册一个全局热键,然后,每当按这个热键的时候,程序自动的在光标当前位置(网页,程序文本框,记事本程序等)输入系统时间戳。
我的全部代码如下:

Public Class Main
    Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As Integer, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Integer
    Declare Function WindowFromPoint Lib "user32" (ByVal xPonit As Integer, ByVal yPonit As Integer) As IntPtr
    Private Declare Function GetCursorPos Lib "user32" (ByRef lpPoint As POINTAPI) As Integer
    Private Declare Function SendMessage Lib "user32" (ByVal hwnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As String) As Integer
    Public Const MOD_ALT = &H1
    Public Const WM_SETTEXT = &HC
    Private Structure POINTAPI
        Dim x As Integer
        Dim y As Integer
    End Structure
    Public Sub ww()
        Dim a As POINTAPI
        Dim b As IntPtr
        Dim bb As Long
        GetCursorPos(a)
        b = WindowFromPoint(a.x, a.y)
        Label2.Text = b
        bb = CLng(b)
        SendMessage(b, WM_SETTEXT, 0, CStr(Now))
    End Sub

    Public Sub Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, Timer1.Tick
        RegisterHotKey(Handle, 101, MOD_ALT, Keys.R)
    End Sub
    Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
        If m.Msg = 786 Then
            If m.WParam.ToInt32 = 101 Then
                'MsgBox(CStr(Now))
                Label1.Text = CStr(Now)
                Call ww()
            End If
        End If
        MyBase.WndProc(m)
    End Sub

End Class


运行时竟然会提示“Unable to find an entry point named 'SendMessage' in DLL 'user32'.”。

快崩溃了。。。大侠们帮帮忙啊…………谢谢各位了,问题究竟出在哪里呢。。。 --------------------编程问答-------------------- 试下这个:
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Int32, ByVal wMsg As Int32, ByVal wParam As Int32, ByVal lParam As Int32) As Int32
--------------------编程问答-------------------- 貌似还是不行,一样的现象。。
大戏们针对我的 需求,有什么更好的实现方法吗?我菜鸟。。。
补充:VB ,  API
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,