If I compile this example from Borje Hagsten with PB8 the highlight of the textcolor works well.
When I compile it with PB9 highlight of the text does not work.
A bug in PB9?
When I compile it with PB9 highlight of the text does not work.
A bug in PB9?
Code:
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ ' Small RichEdit sample, showing how to create a Richedit control ' and mark all occurrences of searched text with a specific color. ' With some tweaking - the base for a color syntax editor? ' It even has drag&drop editing.. :-) ' By Borje Hagsten, released as Public Domain - April 24, 2000 '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ #Compile Exe #Dim All #Include "WIN32API.INC" 'Some include files #Include "COMMCTRL.INC" #Include "RICHEDIT.INC" %ID_RICHEDIT = 500 Global hEdit As Long Declare CallBack Function DlgCallback() Declare Function MarkAll (ByVal myText As String) As Long Declare Function setRichTextColor( ByVal NewColor As Long) As Long '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ Function PBMain Local hDlg As Long, hRichEd As Long, rText As String hRichEd = LoadLibrary("RICHED32.DLL") Call InitCommonControls Dialog New 0, "DDT RichEdit demo",,, 200, 138, %WS_SYSMENU To hDlg Control Add Button, hDlg, %IDOK, "&Mark", 140, 6, 50, 14 Control Add Button, hDlg, %IDCANCEL, "E&xit", 140, 22, 50, 14 Control Add "RichEdit", hDlg, %ID_RICHEDIT, "", 6, 6, 126, 110, _ %WS_CHILD Or %WS_VISIBLE Or %ES_MULTILINE Or %WS_VSCROLL Or _ %WS_HSCROLL Or %ES_AUTOVSCROLL Or %ES_WANTRETURN Or _ %ES_NOHIDESEL, %WS_EX_CLIENTEDGE Control Handle hDlg, %ID_RICHEDIT To hEdit rText = Repeat$(30, "Start and Stop") 'Create and set some text Call SendMessage(hEdit, %WM_SETTEXT, 0, StrPtr(rText)) SetFocus hEdit Dialog Show Modal hDlg Call DlgCallback End Function '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ ' setRichTextColor sets the textcolor for selected text or ' text at the cursor's place in a Richedit control. Example: ' CALL setRichTextColor(&HFF) sets the color to red. ' &HFF0000 is blue, &H8000 is dark green, &H0 is black, etc.. '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ Function setRichTextColor( ByVal NewColor As DWORD) As Long Local cf As CHARFORMAT2 cf.cbSize = Len(cf) 'Length of structure cf.dwMask = %CFM_COLOR 'Set mask to colors only cf.crTextColor = NewColor 'Set the new color value Call SendMessage(hEdit, %EM_SETCHARFORMAT, %SCF_SELECTION, VarPtr(cf)) End Function '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ ' This is a simple "find all" Function '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ Function MarkAll (ByVal myText As String) As Long Local AllText As String, tLen As Long, stopPos As Long '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 'Put Richedit's contents into a string '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ tLen = SendMessage(hEdit, %WM_GETTEXTLENGTH, 0, 0) + 1 AllText = Space$(tLen) Call SendMessage(hEdit, %WM_GETTEXT, tLen, StrPtr(AllText)) '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' Turn off redraw to get faster and smoother action '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Call SendMessage(hEdit, %WM_SETREDRAW, 0, 0) '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' Loop through string, pick out positions, select occurrences and then paint ' Note - Instr returns pos +1 in regards to Selstart, so we have to use -1 '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ stopPos = InStr(AllText, myText) Do While stopPos Call SendMessage(hEdit, %EM_SETSEL, stopPos - 1, stopPos + Len(myText) - 1) Call setRichTextColor(&HFF) '&FF = red stopPos = InStr(stopPos + Len(myText) - 1, AllText, myText) Loop Call SendMessage(hEdit, %EM_SETSEL, 0, 0) SetFocus hEdit 'SetFocus to activate it after work is done, if you like.. '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' Turn on Redraw again and refresh '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ SendMessage hEdit, %WM_SETREDRAW, 1, 0 'Refresh and reset redraw InvalidateRect hEdit, ByVal %NULL, 0 : UpdateWindow hEdit End Function '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ ' Main callback procedure for all controls '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ CallBack Function DlgCallback() If CbMsg = %WM_COMMAND Then Select Case CbCtl Case %IDOK Call MarkAll("Stop") ' "Stop", or any text you'd like to mark Case %IDCANCEL Dialog End CbHndl, (CbCtl = %IDOK) End Select End If End Function
Comment