using_20rich_20edit_20controls
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
using_20rich_20edit_20controls [2018/03/31 13:19] – external edit 127.0.0.1 | using_20rich_20edit_20controls [2024/01/05 00:21] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 10: | Line 10: | ||
===== Initialisation ===== | ===== Initialisation ===== | ||
\\ To start off with we need to include this initialisation code:\\ \\ | \\ To start off with we need to include this initialisation code:\\ \\ | ||
+ | <code bb4w> | ||
SYS " | SYS " | ||
EM_SETBKGNDCOLOR = 1091 | EM_SETBKGNDCOLOR = 1091 | ||
Line 30: | Line 31: | ||
SCF_SELECTION = 1 | SCF_SELECTION = 1 | ||
SCF_ALL = 4 | SCF_ALL = 4 | ||
+ | </ | ||
Now we can create the Rich Edit control itself. The process depends on whether you want to display it in a dialogue box or directly on your program' | Now we can create the Rich Edit control itself. The process depends on whether you want to display it in a dialogue box or directly on your program' | ||
===== Dialogue box ===== | ===== Dialogue box ===== | ||
\\ As usual, we must install the appropriate library for working with dialogue boxes:\\ \\ | \\ As usual, we must install the appropriate library for working with dialogue boxes:\\ \\ | ||
+ | <code bb4w> | ||
INSTALL @lib$+" | INSTALL @lib$+" | ||
+ | </ | ||
(alternatively install **WINLIB2A** or **WINLIB2B** if you need the facilities they provide).\\ \\ Now we will create a simple dialogue box containing just a cancel button and a Rich Edit control:\\ \\ | (alternatively install **WINLIB2A** or **WINLIB2B** if you need the facilities they provide).\\ \\ Now we will create a simple dialogue box containing just a cancel button and a Rich Edit control:\\ \\ | ||
+ | <code bb4w> | ||
dlg% = FN_newdialog(" | dlg% = FN_newdialog(" | ||
PROC_pushbutton(dlg%, | PROC_pushbutton(dlg%, | ||
Line 41: | Line 46: | ||
PROC_dlgctrl(dlg%, | PROC_dlgctrl(dlg%, | ||
\ " | \ " | ||
+ | </ | ||
Note that the Rich Edit control has been allocated the ID number **101**. Refer to the documentation for [[http:// | Note that the Rich Edit control has been allocated the ID number **101**. Refer to the documentation for [[http:// | ||
+ | <code bb4w> | ||
PROC_showdialog(dlg%) | PROC_showdialog(dlg%) | ||
+ | </ | ||
\\ | \\ | ||
===== Main output window ===== | ===== Main output window ===== | ||
\\ As usual, we must install the appropriate library for working with boxes and buttons:\\ \\ | \\ As usual, we must install the appropriate library for working with boxes and buttons:\\ \\ | ||
+ | <code bb4w> | ||
INSTALL @lib$+" | INSTALL @lib$+" | ||
+ | </ | ||
(alternatively install **WINLIB5A**, | (alternatively install **WINLIB5A**, | ||
+ | <code bb4w> | ||
hre% = FN_createwindow(" | hre% = FN_createwindow(" | ||
\ | \ | ||
+ | </ | ||
Refer to the documentation for [[http:// | Refer to the documentation for [[http:// | ||
===== Controlling the control ===== | ===== Controlling the control ===== | ||
\\ Each of the sections below lists code for both the Dialogue Box and Main Window cases; use whichever version is applicable to your program.\\ \\ You load text into a Rich Edit control in exactly the same way as a multiline edit control:\\ \\ | \\ Each of the sections below lists code for both the Dialogue Box and Main Window cases; use whichever version is applicable to your program.\\ \\ You load text into a Rich Edit control in exactly the same way as a multiline edit control:\\ \\ | ||
+ | <code bb4w> | ||
REM Control in dialogue box: | REM Control in dialogue box: | ||
SYS " | SYS " | ||
Line 58: | Line 71: | ||
REM Control on main window: | REM Control on main window: | ||
SYS " | SYS " | ||
+ | </ | ||
Lines of text should be delimited by the CRLF (CHR$13+CHR$10) character sequence.\\ \\ Similarly, to read (edited) text from the control, use the same method as for a regular edit box:\\ \\ | Lines of text should be delimited by the CRLF (CHR$13+CHR$10) character sequence.\\ \\ Similarly, to read (edited) text from the control, use the same method as for a regular edit box:\\ \\ | ||
+ | <code bb4w> | ||
REM Control in dialogue box: | REM Control in dialogue box: | ||
DEF FNgettext(dlg%, | DEF FNgettext(dlg%, | ||
Line 72: | Line 87: | ||
SYS " | SYS " | ||
= $$text% | = $$text% | ||
+ | </ | ||
You may want to adapt the above code to reduce the size of the buffer. You can discover the length of text in the Rich Edit control using the **GetWindowTextLength** API function.\\ \\ To change the background colour use code similar to the following: | You may want to adapt the above code to reduce the size of the buffer. You can discover the length of text in the Rich Edit control using the **GetWindowTextLength** API function.\\ \\ To change the background colour use code similar to the following: | ||
+ | <code bb4w> | ||
REM Control in dialogue box: | REM Control in dialogue box: | ||
SYS " | SYS " | ||
Line 78: | Line 95: | ||
REM Control on main window: | REM Control on main window: | ||
SYS " | SYS " | ||
+ | </ | ||
Here **bgcolor%** should contain the required colour in the **COLORREF** format, i.e. a hexadecimal value of the form & | Here **bgcolor%** should contain the required colour in the **COLORREF** format, i.e. a hexadecimal value of the form & | ||
+ | <code bb4w> | ||
DIM cfmt{cbSize%, | DIM cfmt{cbSize%, | ||
\ bCharSet&, | \ bCharSet&, | ||
Line 88: | Line 107: | ||
cfmt.crTextColor% = fgcolor% | cfmt.crTextColor% = fgcolor% | ||
cfmt.szFaceName& | cfmt.szFaceName& | ||
+ | </ | ||
Here **style%** is a combination of the **" | Here **style%** is a combination of the **" | ||
+ | <code bb4w> | ||
REM Control in dialogue box: | REM Control in dialogue box: | ||
SYS " | SYS " | ||
Line 94: | Line 115: | ||
REM Control on main window: | REM Control on main window: | ||
SYS " | SYS " | ||
+ | </ | ||
As shown //all// the text is affected; if you want to format only the currently selected text change **SCF_ALL** to **SCF_SELECTION**.\\ \\ This article only scratches the surface of what can be achieved using Rich Edit controls. For more information consult Microsoft' | As shown //all// the text is affected; if you want to format only the currently selected text change **SCF_ALL** to **SCF_SELECTION**.\\ \\ This article only scratches the surface of what can be achieved using Rich Edit controls. For more information consult Microsoft' | ||
+ | <code bb4w> | ||
DIM CHARFORMAT2{cbSize%, | DIM CHARFORMAT2{cbSize%, | ||
\ dwMask%, | \ dwMask%, | ||
Line 116: | Line 139: | ||
\ bRevAuthor&, | \ bRevAuthor&, | ||
\ bReserved1& | \ bReserved1& | ||
+ | </ |
using_20rich_20edit_20controls.1522502389.txt.gz · Last modified: 2024/01/05 00:16 (external edit)