Here's an example I wrote for someone a little while ago.
Type some text into the string gadget at the bottom of the window and then hit send. Any occurrences of a colon followed by a close bracket will be converted to a smilie.
(If the code doesn't work properly then it will be because I didn't post the most up to date version of the 'OLEedit.pbi' source file. In this case, just let me know.)
Code: Select all
;NOTE - I've made this more complex than it has to be in order for it to be
; flexible enough to handle more than one type of smiley etc.
; Indeed, it is now trivial to add more smileys.
;**************MUST INCLUDE*****************************************************************
XIncludeFile "OLEedit.pbi"
;*******************************************************************************************
Enumeration
#editViewer
#strUser
#btnSend
EndEnumeration
If OpenWindow(0, 0, 0, 600, 400, "Smiley test!", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
EditorGadget(#editViewer, 8, 8, 500, 300,#PB_Editor_ReadOnly)
StringGadget(#strUser, 8, 320, 500, 40,"",#ES_MULTILINE|#WS_VSCROLL|#ESB_DISABLE_LEFT|#ESB_DISABLE_RIGHT)
ButtonGadget(#btnSend,520,320,60,40,"SEND")
;Set up the com interface for the editor gadget.
RichEdit_SetInterface(GadgetID(#editViewer))
SetActiveGadget(#strUser)
Repeat
EV=WaitWindowEvent()
Select EV
Case #PB_Event_Gadget
Select EventGadget()
Case #btnSend
;We need to parse the string looking for ':)' smilies!
text$ = GetGadgetText(#strUser)
If text$
Repeat
loc = FindString(text$, ":",1)
If loc And loc<Len(text$)
;We have encountered a possible smiley. Need to examine more closely.
smiley$=Mid(text$, loc,2)
Select smiley$
Case ":)" ;Add all other valid smileys separated by commas. E.g. Case ":)", ";)" etc.
;Stream the text up to the smiley.
temp$ = Left(text$,loc-1)
If temp$
CatchRTF(#editViewer, @temp$, @temp$+Len(temp$)*SizeOf(CHARACTER),#SF_TEXT, #SFF_SELECTION)
EndIf
;Look at individual smileys.
;THIS IS WHERE YOU ADD MORE SMILEYS BY ADDING 'ElseIf's etc.
If smiley$=":)"
CatchRTF(#editViewer, ?smiley1, ?endsmiley1,#SF_RTF, #SFF_SELECTION)
EndIf
;Remove the already processed text.
text$=Right(text$, Len(text$)-loc-1)
Default
;Stream the text up to the colon.
temp$ = Left(text$,loc)
CatchRTF(#editViewer, @temp$, @temp$+Len(temp$)*SizeOf(CHARACTER),#SF_TEXT, #SFF_SELECTION)
;Remove the already processed text.
text$=Right(text$, Len(text$)-loc)
EndSelect
Else ; No further smileys so we stream in the remainder of the text.
CatchRTF(0, @text$, @text$+Len(text$)*SizeOf(CHARACTER),#SF_TEXT, #SFF_SELECTION)
text$="" ;This will force an exit from the loop.
EndIf
Until text$=""
AddGadgetItem(#editViewer,-1,"")
SetGadgetText(#strUser,"")
EndIf
SetActiveGadget(#strUser)
EndSelect
EndSelect
Until EV = #PB_Event_CloseWindow
EndIf
End
DataSection
smiley1:
Data.b 123, 92, 114, 116, 102, 49, 92, 97, 110, 115, 105, 92, 97, 110, 115, 105, 99, 112, 103, 49, 50, 53, 50, 92, 100, 101, 102, 102, 48, 92, 100, 101, 102, 108, 97, 110, 103, 50, 48, 53
Data.b 55, 123, 92, 102, 111, 110, 116, 116, 98, 108, 123, 92, 102, 48, 92, 102, 115, 119, 105, 115, 115, 92, 102, 99, 104, 97, 114, 115, 101, 116, 48, 32, 65, 114, 105, 97, 108, 59, 125, 125
Data.b 13, 10, 123, 92, 42, 92, 103, 101, 110, 101, 114, 97, 116, 111, 114, 32, 77, 115, 102, 116, 101, 100, 105, 116, 32, 53, 46, 52, 49, 46, 49, 53, 46, 49, 53, 48, 55, 59, 125, 92
Data.b 118, 105, 101, 119, 107, 105, 110, 100, 52, 92, 117, 99, 49, 92, 112, 97, 114, 100, 92, 102, 48, 92, 102, 115, 50, 48, 123, 92, 112, 105, 99, 116, 92, 119, 109, 101, 116, 97, 102, 105
Data.b 108, 101, 56, 92, 112, 105, 99, 119, 103, 111, 97, 108, 50, 49, 48, 92, 112, 105, 99, 104, 103, 111, 97, 108, 50, 52, 48, 32, 13, 10, 48, 49, 48, 48, 48, 57, 48, 48, 48, 48
Data.b 48, 51, 102, 53, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 55, 100, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 52, 48, 48, 48, 48, 48, 48, 48, 51, 48, 49, 48, 56
Data.b 48, 48, 48, 53, 48, 48, 48, 48, 48, 48, 48, 98, 48, 50, 48, 48, 48, 48, 48, 48, 48, 48, 48, 53, 48, 48, 48, 48, 13, 10, 48, 48, 48, 99, 48, 50, 49, 48, 48, 48
Data.b 49, 48, 48, 48, 48, 51, 48, 48, 48, 48, 48, 48, 49, 101, 48, 48, 48, 52, 48, 48, 48, 48, 48, 48, 48, 55, 48, 49, 48, 52, 48, 48, 48, 56, 48, 48, 48, 48, 48, 48
Data.b 50, 54, 48, 54, 48, 102, 48, 48, 48, 54, 48, 48, 53, 52, 52, 101, 53, 48, 53, 48, 48, 54, 48, 49, 52, 51, 48, 48, 13, 10, 48, 48, 48, 48, 52, 49, 48, 98, 56, 54
Data.b 48, 48, 101, 101, 48, 48, 48, 102, 48, 48, 48, 102, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 102, 48, 48, 48, 102, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 50, 56
Data.b 48, 48, 48, 48, 48, 48, 48, 102, 48, 48, 48, 48, 48, 48, 48, 102, 48, 48, 48, 48, 48, 48, 48, 49, 48, 48, 48, 49, 13, 10, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48
Data.b 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48
Data.b 48, 48, 48, 48, 48, 48, 48, 48, 102, 102, 102, 102, 102, 102, 48, 48, 48, 55, 99, 48, 100, 57, 48, 51, 49, 102, 102, 48, 13, 10, 52, 57, 52, 99, 51, 102, 102, 56, 98, 102
Data.b 48, 51, 55, 102, 102, 99, 48, 48, 48, 48, 55, 102, 102, 99, 48, 48, 48, 48, 102, 102, 102, 101, 48, 48, 48, 48, 102, 102, 102, 101, 48, 48, 48, 48, 102, 102, 102, 101, 48, 48
Data.b 48, 48, 102, 102, 102, 101, 48, 48, 48, 48, 102, 102, 102, 101, 48, 48, 48, 48, 55, 102, 102, 99, 102, 102, 102, 102, 55, 102, 13, 10, 102, 99, 48, 48, 48, 48, 51, 102, 102, 56
Data.b 102, 102, 102, 102, 49, 102, 102, 48, 98, 102, 48, 51, 48, 55, 99, 48, 48, 48, 48, 48, 55, 100, 48, 48, 48, 48, 48, 48, 52, 49, 48, 98, 99, 54, 48, 48, 56, 56, 48, 48
Data.b 48, 102, 48, 48, 48, 102, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 102, 48, 48, 48, 102, 48, 48, 48, 48, 48, 48, 13, 10, 48, 48, 48, 48, 50, 56, 48, 48, 48, 48
Data.b 48, 48, 48, 102, 48, 48, 48, 48, 48, 48, 48, 102, 48, 48, 48, 48, 48, 48, 48, 49, 48, 48, 48, 52, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48
Data.b 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 13, 10, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48
Data.b 48, 48, 48, 48, 102, 102, 102, 102, 102, 102, 48, 48, 52, 53, 52, 53, 52, 53, 48, 48, 101, 98, 102, 102, 102, 102, 48, 48, 99, 55, 102, 102, 102, 102, 48, 48, 57, 51, 102, 101
Data.b 102, 102, 48, 48, 48, 48, 99, 101, 102, 102, 48, 48, 49, 51, 102, 100, 102, 102, 48, 48, 48, 48, 101, 97, 102, 102, 48, 48, 13, 10, 48, 48, 57, 100, 102, 101, 48, 48, 48, 48
Data.b 99, 57, 102, 102, 48, 48, 48, 48, 98, 52, 102, 102, 48, 48, 48, 48, 101, 53, 102, 102, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48
Data.b 48, 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 50, 50, 50, 50, 50, 49, 49, 49, 49, 49, 48, 49, 49, 49, 50, 50, 98, 13, 10, 98, 98, 98, 57, 50, 50, 49, 49, 49, 48
Data.b 49, 49, 50, 54, 54, 97, 97, 97, 97, 97, 54, 57, 50, 49, 49, 48, 49, 50, 54, 54, 99, 48, 48, 48, 48, 48, 97, 54, 57, 50, 49, 48, 49, 50, 54, 56, 48, 49, 49, 49
Data.b 49, 49, 48, 97, 54, 50, 49, 48, 50, 54, 56, 48, 49, 49, 49, 49, 49, 49, 49, 48, 97, 57, 50, 48, 50, 55, 56, 48, 13, 10, 49, 49, 49, 49, 49, 49, 49, 48, 97, 98
Data.b 50, 48, 50, 53, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 98, 50, 48, 50, 53, 48, 56, 56, 56, 56, 56, 56, 56, 56, 56, 48, 98, 50, 48, 50, 52, 55, 56, 56, 48
Data.b 56, 56, 56, 48, 56, 56, 97, 57, 50, 48, 49, 50, 53, 55, 56, 48, 56, 56, 56, 48, 56, 56, 54, 50, 49, 48, 49, 50, 13, 10, 52, 53, 55, 56, 56, 56, 56, 56, 56, 54
Data.b 57, 50, 49, 48, 49, 49, 50, 51, 52, 55, 55, 56, 56, 56, 54, 57, 50, 49, 49, 48, 49, 49, 49, 50, 50, 51, 52, 53, 53, 54, 50, 50, 49, 49, 49, 48, 49, 49, 49, 49
Data.b 49, 50, 50, 50, 50, 50, 49, 49, 49, 49, 49, 48, 48, 56, 48, 48, 48, 48, 48, 48, 50, 54, 48, 54, 48, 102, 48, 48, 13, 10, 48, 54, 48, 48, 53, 52, 52, 101, 53, 48
Data.b 53, 48, 48, 55, 48, 49, 48, 52, 48, 48, 48, 48, 48, 48, 50, 55, 48, 49, 102, 102, 102, 102, 48, 51, 48, 48, 48, 48, 48, 48, 48, 48, 48, 48, 13, 10, 125, 125, 13, 10
Data.b 32
endsmiley1:
EndDataSection