我现在有个收银系统,但一定要在当前窗口扫描才能扫进,现在要实现在任何窗口都可以扫(台后)。现在的程序这个在非收银系统扫描已经实现,但遇个问题如果当前窗口又在收银系统扫描就会出现两个条型码(一个自己扫描进去的,一个通过程序传递进去的)现在用判断窗口名柄对比却总是不对。请高人指点谢谢 
程序如下:省去模块 
Dim WithEvents hook As ClsHook 
Dim desHwnd As Long 
Dim hookStart As Boolean 
Dim keyValue As String 
Dim firstDownTime As Date 
Dim T As Long 
Private Sub cmdCont_Click() 
If Not hookStart Then 
    Set hook = New ClsHook 
    hook.SetHook 
    hookStart = True 
    'SetWindowPos Me.hwnd, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOSIZE 
End If 
Me.WindowState = 1 
End Sub 
Private Sub Command1_Click() 
hookStart = False 
End Sub Private Sub Form_Initialize() 
InitCommonControlsVB 
End Sub Private Sub Form_Load() 
Dim reg As String 
'reg = GetSetting("scan", "can", "name") 
If Date > #10/30/2009# Then Timer1.Interval = 100     SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE End Sub Private Sub Form_Unload(Cancel As Integer) 
If hookStart Then hook.UnHook 
End Sub Private Sub Frame1_Click() 
T = Timer() End Sub Private Sub hook_KeyDown(KeyCode As Integer, Shift As Integer) 
    Dim sendStr As String 
    If KeyCode >= 48 And KeyCode <= 57 Then 
        If keyValue = "" Then T = Timer() 
        keyValue = keyValue & Chr(KeyCode) 
        Text1.Text = keyValue 
    End If 
    InformationNow = True 
        Call GetWindowInformation(WindowHandle&, WindowClassName$, WindowText$, lstParents) 
        dqwin = WindowHandle& 
    InformationNow = False 
    If KeyCode = 13 And Len(keyValue) >= 13 Then 
        'SendtoWindow 
        If desHwnd > 0 And desHwnd <> dqwin Then 
            sendStr = keyValue 
            keyValue = "" 
            For i = 1 To Len(sendStr) 
    
                    'PostMessage desHwnd, WM_KEYDOWN, Asc(Mid(sendStr, i, 1)), 0 
                    SendMessage desHwnd, WM_CHAR, Asc(Mid(sendStr, i, 1)), 0 
                    
                    'PostMessage desHwnd, WM_KEYUP, Asc(Mid(sendStr, i, 1)), 0 
                    
            Next 
                    'PostMessage desHwnd, WM_KEYDOWN, 13, 0 
                    SendMessage desHwnd, WM_CHAR, 13, 0 
                  ' PostMessage desHwnd, WM_KEYUP, 13, 0 
          For i = 1 To Len(sendStr) + 1 
                SendKeys "{BACKSPACE}" 
          Next 
        End If 
    End If 
    
End Sub Private Sub picDrag_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single) 
    If hookStart Then Exit Sub 
    picDrag.MousePointer = 99 
    Me.MousePointer = 99 
    picDrag.Picture = Me.Picture 
    InformationNow = True 
End Sub Private Sub picDrag_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single) 
    If hookStart Then Exit Sub 
    If InformationNow = True Then 
        Call GetWindowInformation(WindowHandle&, WindowClassName$, WindowText$, lstParents) 
        desHwnd = WindowHandle 
        txtWindowHandle.Text = WindowHandle& 
        txtWindowClassName.Text = WindowClassName$ 
        txtWindowText.Text = WindowText$ 
    End If 
End Sub Private Sub picDrag_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single) 
If hookStart Then Exit Sub 
Dim WindowHandle& 
Dim WindowClassName$, WindowText$ 
    picDrag.MousePointer = 0 
    Me.MousePointer = 0 
    picDrag.Picture = cmdCont.MouseIcon 
    Call GetWindowInformation(WindowHandle&, WindowClassName$, WindowText$, lstParents) 
    txtWindowHandle.Text = WindowHandle& 
    txtWindowClassName.Text = WindowClassName$ 
    txtWindowText.Text = WindowText$ 
    InformationNow = False 
End Sub Private Sub Text1_Change() 
Frame4.Caption = "扫描码(" & Len(Text1.Text) & ")" 
End Sub Private Sub Timer1_Timer() 
  If (Timer() - T > 0.5) Then keyValue = "" 
End Sub