Author Topic: 過濾 WM_CHAR 事件(KeyPress) 的自訂函數  (Read 3993 times)

admin

  • Administrator
  • *****
  • Posts: 0
    • View Profile
過濾 WM_CHAR 事件(KeyPress) 的自訂函數
« on: November 15, 2011, 06:37:19 PM »
Code: [Select]
Function FilterKeyDown(ByVal  hWndControl As Dword,ByVal chCharCode As Long,ByVal NoMinusSign As Byte,ByVal NoDecimal As Byte) As Byte
    Dim tmpResult As Byte
   
    tmpresult=%true
   
    Select Case chCharCode
    Case 48 To 57 'Number
      tmpResult=%false
   
    Case 8    'BackSpace
      tmpResult=%false
   
    Case 13   'Enter
      tmpResult=%false
   
    Case Asc(".")   'Decimal
      If NoDecimal=0 Then
        If CheckCharExsit(chCharCode,hWndControl)=%false Then
          tmpResult=%false
        End If
      End If
   
    Case Asc("-")
      If NoMinusSign=0 Then
        If CheckCharExsit(chCharCode,hWndControl)=%false Then
          tmpResult=%false
        End If
      End If
   
    Case 127  'Del
        tmpResult=%false
   
    Case 28 To 31  'Arrow Key
        tmpResult=%false
   
    Case 27    'Esc
        tmpResult=%false
   
    End Select
   
    Function=tmpResult

End Function

檢查重複的小數點及負號
Code: [Select]
Function CheckCharExsit(ByVal hWndControl As Dword,ByVal chCharCode As Long) As Byte
    Local intX As Integer
    Local tmpResult As Byte
    Local tmpText As String
   
    tmpresult=%false
    tmptext=FF_TextBox_GetText( hWndControl )
   
    If Len(tmpText) >0 Then
        For intX = 1 To Len(tmpText)
          If Chr$(chCharCode) = Mid$(tmpText, intX, 1) Then
            tmpResult = %True
            Exit For
          End If
        Next
    End If

    Function = tmpresult
     
End Function

« Last Edit: November 29, 2011, 10:59:03 PM by Roy Chan »