Hello davido28,
at first welcome in the PureBasic Forum...
This is a simple Windows example to automatically capitalize a letter at the
beginning and after each space character. Try it for example with your
"harry genks":
Code: Select all
EnableExplicit
Define CurrentText.S
Define CurrentTextLength.I
OpenWindow(0, 0, 0, 230, 40, "Capitalize leading characters", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
StringGadget(0, 10, 10, WindowWidth(0) - 20, 20, "")
SetActiveGadget(0)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
Break
Case #WM_KEYUP
If EventGadget() = 0
CurrentText = GetGadgetText(0)
CurrentTextLength = Len(CurrentText)
If CurrentTextLength > 0
If CurrentTextLength = 1
CurrentText = UCase(CurrentText)
Else
If Mid(CurrentText, CurrentTextLength - 1, 1) = " "
CurrentText = Left(CurrentText, Len(CurrentText) - 1) + UCase(Right(CurrentText, 1))
EndIf
EndIf
SetGadgetText(0, CurrentText)
SendMessage_(GadgetID(0), #EM_SETSEL, $FFFF, $FFFF) ; Set cursor to end of string
EndIf
EndIf
EndSelect
ForEver
For the capitalization of a complete sentence in the English language you
would have to change the space character in the line
Code: Select all
If Mid(CurrentText, CurrentTextLength - 1, 1) = " "
to a full stop and check the second character before the last one (instead of
just the character before the last one)
Code: Select all
If Mid(CurrentText, CurrentTextLength - 2, 2) = ". "
so that after each full stop followed by a space the next character will be
capitalized. For longer text passages this method doesn't work well because
after each character entry the whole text line has to be rewritten and thus
producing some flicker. In that case you would have to utilize a callback which
probably is a little bit of overkill for a beginner...
This example won't work in Linux or MacOS X because I had to use the Windows
specific API function SendMessage_() to position the cursor at the end of the
text. If you want to know how to set the cursor position in Linux or MacOS X
you may take a look into this thread:
http://www.purebasic.fr/english/viewtopic.php?t=38488