You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
The problem isn't so much in the compiler as with the .inc files released with PBWin9
RichEdit.inc distributed with release of PBWin9:
Dated in the header - ' Last Update: 07 November 2002
Is missing the last member of the Charformat2 UDT
The RichEdit.inc distributed with release of PBWin801:
Dated in the header - ' Last Update: 24 February 2005 Does have the last member of the Charformat2 UDT
bReserved1 AS BYTE ' Reserved. Must be 0
PBHave reverted to earlier versions of RichEdit.inc (and Win32API.inc) in the release of PBWin9.
In the case of RichEdit.inc the only difference is that last member of CharFormat2 - missing from the current release !!
BTW. Both versions of RichEdit.inc have the same definition of the Charformat UDT which is what Borje used with RichEdit version 1.0 (Riched32.dll) in the code he that posted here: http://www.powerbasic.com/support/pb...ad.php?t=22639
I have found the errors in the presentation of the Richedit control.
The bug is in PB9 that the UDT of CHARFORMAT2 is wrong
The UDT of CHARFORMAT2 in PB9 is:
Code:
TYPE CHARFORMAT2 BYTE
cbSize AS DWORD
dwMask AS DWORD
dwEffects AS DWORD
yHeight AS LONG
yOffset AS LONG ' > 0 for superscript, < 0 for subscript
crTextColor AS DWORD
bCharSet AS BYTE
bPitchAndFamily AS BYTE
szFaceName AS ASCIIZ * %LF_FACESIZE
wFiller AS WORD
wWeight AS WORD ' Font weight (LOGFONT value)
sSpacing AS INTEGER ' Amount to space between letters
crBackColor AS DWORD ' Background color
lcid AS DWORD ' Locale ID
dwReserved AS DWORD ' Reserved. Must be 0
sStyle AS INTEGER ' Style handle
wKerning AS WORD ' Twip size above which to kern char pair
bUnderlineType AS BYTE ' Underline type
bAnimation AS BYTE ' Animated text like marching ants
bRevAuthor AS BYTE ' Revision author index
END TYPE
In the MSDN Library the UDT of CHARFORMAT2 in PB9 is:
Code:
typedef struct _charformat2 {
UINT cbSize;
_WPAD _wPad1;
DWORD dwMask;
DWORD dwEffects;
LONG yHeight;
LONG yOffset;
COLORREF crTextColor;
BYTE bCharSet;
BYTE bPitchAndFamily;
WCHAR szFaceName[LF_FACESIZE];
_WPAD _wPad2;
WORD wWeight;
SHORT sSpacing;
COLORREF crBackColor;
LCID lcid;
DWORD dwReserved;
SHORT sStyle;
WORD wKerning;
BYTE bUnderlineType;
BYTE bAnimation;
BYTE bRevAuthor;
BYTE bReserved1;
} CHARFORMAT2;
The last of Variable 'bRevAuthor AS BYTE' is missing!
This error does not existin PB8, so does the example with PB8 works and with PB9 not.
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?
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
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Leave a comment: