Me tarde un buen buscando pero ya esta aqui la solucion
En un boton pones :
Private Sub Command1_Click()
hInst = GetWindowLong(Me.hwnd, GWL_HINSTANCE)
Thread = GetCurrentThreadId()
hHook = SetWindowsHookEx(WH_CBT, AddressOf Manipulate, hInst, Thread)
Resultado = InputBox("Intenta escribir letras", "Solo numeros")
End Sub
Insertas un Modulo y pones :
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Const GWL_STYLE = (-16)
Const ES_NUMBER = &H2000&
' used for placing the hook
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long
Public Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
Public Const GWL_HINSTANCE = (-6)
Public Const SWP_NOSIZE = &H1
Public Const SWP_NOZORDER = &H4
Public Const SWP_NOACTIVATE = &H10
Public Const HCBT_ACTIVATE = 5
Public Const WH_CBT = 5
Public hHook As Long
' used for locating and changing the buttons
Public Declare Function FindWindowEx Lib "user32.dll" Alias "FindWindowExA" (ByVal hwndParent As Long, ByVal hwndChildAfter As Long, ByVal lpszClass As String, ByVal lpszWindow As String) As Long
Public Declare Function SetWindowText Lib "user32.dll" Alias "SetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String) As Long
Public Declare Function GetClassName Lib "user32.dll" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
Public ButtonText(0 To 3) As String
Public Sub SetNumber(hwnd As Long, Flag As Boolean)
Dim curstyle As Long, newstyle As Long
'retrieve the window style
curstyle = GetWindowLong(hwnd, GWL_STYLE)
If Flag Then
curstyle = curstyle Or ES_NUMBER
Else
curstyle = curstyle And (Not ES_NUMBER)
End If
'Set the new style
newstyle = SetWindowLong(hwnd, GWL_STYLE, curstyle)
'refresh
'NumberText.Refresh
End Sub
' function called by hook
Public Function Manipulate(ByVal lMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim Btn(0 To 3) As Long
Dim ButtonCount As Integer
Dim T As Integer
If lMsg = HCBT_ACTIVATE Then
Btn(0) = FindWindowEx(wParam, 0, vbNullString, vbNullString)
Dim cName As String, Length As Long
For T = 1 To 3
Btn(T) = FindWindowEx(wParam, Btn(T - 1), vbNullString, vbNullString)
' no more windows found
If Btn(T) = 0 Then Exit For
Next T
For T = 0 To 3
If Btn(T) <> 0 And Btn(T) <> wParam Then
cName = Space(255)
Length = GetClassName(Btn(T), cName, 255)
cName = Left(cName, Length)
'Debug.Print cName
If UCase(cName) = "EDIT" Then
SetNumber Btn(T), True
End If
'If UCase(cName) = "BUTTON" Then
' a button
' SetWindowText Btn(T), ButtonText(ButtonCount)
' ButtonCount = ButtonCount + 1
'End If
End If
Next T
'Release the CBT hook
UnhookWindowsHookEx hHook
End If
Manip = False
End Function