excel的Worksheet_Change不能及时判断输入文字的改变,如果想直接响应键盘消息,应该办。
应该是用windows API 的hook对巴,能不能说一下怎么具体怎么做啊

解决方案 »

  1.   

    我写了下面这个hook,但是在取得hInst的时候总是失败(hinst为0),请大家帮忙看看
    Public Sub Hook()
        Dim hInst As Long
        Dim Thread As Long
        Dim hwnd As Long
        
        'Set up the CBT hook
        hwnd = FindWindow("XLMAIN", Application.Caption)
        hInst = GetWindowLong(hwnd, GWL_HINSTANCE)
        
        If (hInst = 0) Then
            MsgBox "GetWindowLong 失敗"
        End If
        
        Thread = GetCurrentThreadId()
        
        If IsHooked Then
            MsgBox "Don't hook it twice without " & _
                "unhooking, or you will be unable to unhook it."
        Else
            glngHwndProc = SetWindowsHookEx(WH_KEYBOARD, AddressOf ワード暗誦, hInst, Thread)
            IsHooked = True
        End If
    End Sub
      

  2.   

    我刚刚把问题解决了,问题原因是WH_KEYBOARD,GWL_HINSTANCE为empty,没有被定义。
    追加一个const定义就可以了。
    但是有个新问题:
    WH_KEYBOARD,GWL_HINSTANCE是不应该由我来定义的,是不是要在程序中包含某个定义文件阿?
      

  3.   


    这些好象是Win32 API规定的常量,在VB的API函数浏览器中可以查到它们的声明。
    在MSDN中也可以查到相应的宏定义。