Großbuchstaben in Textboxen
Wenn man in Textboxen nur Groß- oder Kleinbuchstaben erlauben will, muß man nicht unbedingt jeden Tastaturcode auslesen und umwandeln.
Viel einfacher geht das mit der API-Funktion SetWindowLong.
Deklaration:Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Const GWL_STYLE = (-16)
Zuerst werden die aktuellen Einstellungen der Textbox ausgelesen und mit SetWindowLong werden diese dann zurückgeschrieben.
Windows wandelt nun alle Buchstaben in Groß- bzw. Kleinbuchstaben um, bevor sie an die Textbox geschickt werden.
Dim f As Long
f = GetWindowLong(Text1.hwnd, GWL_STYLE)
f = f Or &H8
SetWindowLong Text1.hwnd, GWL_STYLE, f
f = GetWindowLong(Text1.hwnd, GWL_STYLE)
f = f And Not &H8
SetWindowLong Text1.hwnd, GWL_STYLE, f