User Tools

Site Tools


using_20rich_20edit_20controls

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

using_20rich_20edit_20controls [2018/03/31 13:19]
127.0.0.1 external edit
using_20rich_20edit_20controls [2018/04/15 18:48] (current)
tbest3112 Added syntax highlighting
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 "​LoadLibrary",​ "​RICHED20.DLL"​         SYS "​LoadLibrary",​ "​RICHED20.DLL"​
         EM_SETBKGNDCOLOR = 1091         EM_SETBKGNDCOLOR = 1091
Line 30: Line 31:
         SCF_SELECTION = 1         SCF_SELECTION = 1
         SCF_ALL = 4         SCF_ALL = 4
 +</​code>​
 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'​s main window.\\ \\  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'​s main window.\\ \\ 
 ===== 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$+"​WINLIB2"​         INSTALL @lib$+"​WINLIB2"​
 +</​code>​
 (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("​Rich Edit control",​ 250, 20, 150, 140, 8, 1000)         dlg% = FN_newdialog("​Rich Edit control",​ 250, 20, 150, 140, 8, 1000)
         PROC_pushbutton(dlg%,​ "​Cancel",​ 2, 20, 120, 56, 14, 0)         PROC_pushbutton(dlg%,​ "​Cancel",​ 2, 20, 120, 56, 14, 0)
Line 41: Line 46:
         PROC_dlgctrl(dlg%,​ "",​ reid%, 20, 20, 64, 12, WS_CHILD OR WS_VISIBLE OR WS_BORDER, \         PROC_dlgctrl(dlg%,​ "",​ reid%, 20, 20, 64, 12, WS_CHILD OR WS_VISIBLE OR WS_BORDER, \
         \            "​RichEdit20A"​)         \            "​RichEdit20A"​)
 +</​code>​
 Note that the Rich Edit control has been allocated the ID number **101**. Refer to the documentation for [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwing.html#​dlgitem|PROC_dlgitem]] for the meaning of the other parameters.\\ \\  You may want to combine other window styles with the **WS_BORDER** value. Rich Edit controls will respond to most of the style values allocated to multiline edit controls; notable exceptions are ES_LOWERCASE,​ ES_UPPERCASE and ES_OEMCONVERT which are not supported by Rich Edit controls.\\ \\  The dialogue box is displayed in the usual way:\\ \\  Note that the Rich Edit control has been allocated the ID number **101**. Refer to the documentation for [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwing.html#​dlgitem|PROC_dlgitem]] for the meaning of the other parameters.\\ \\  You may want to combine other window styles with the **WS_BORDER** value. Rich Edit controls will respond to most of the style values allocated to multiline edit controls; notable exceptions are ES_LOWERCASE,​ ES_UPPERCASE and ES_OEMCONVERT which are not supported by Rich Edit controls.\\ \\  The dialogue box is displayed in the usual way:\\ \\ 
 +<code bb4w>
         PROC_showdialog(dlg%)         PROC_showdialog(dlg%)
 +</​code>​
 \\  \\ 
 ===== 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$+"​WINLIB5"​         INSTALL @lib$+"​WINLIB5"​
 +</​code>​
 (alternatively install **WINLIB5A**,​ and remember to pass the parent window handle **@hwnd%** as the first parameter of **FN_createwindow**).\\ \\  The Rich Edit control is created as follows:\\ \\  (alternatively install **WINLIB5A**,​ and remember to pass the parent window handle **@hwnd%** as the first parameter of **FN_createwindow**).\\ \\  The Rich Edit control is created as follows:\\ \\ 
 +<code bb4w>
         hre% = FN_createwindow("​RichEdit20A",​ "",​ 200, 50, 140, 200, 0, \         hre% = FN_createwindow("​RichEdit20A",​ "",​ 200, 50, 140, 200, 0, \
         \       ​WS_BORDER OR ES_MULTILINE,​ 0)         \       ​WS_BORDER OR ES_MULTILINE,​ 0)
 +</​code>​
 Refer to the documentation for [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwing.html#​fnwindow|FN_createwindow]] for the meaning of the parameters.\\ \\  You may want to combine other window styles with the **WS_BORDER** value. Rich Edit controls will respond to most of the style values allocated to multiline edit controls; notable exceptions are ES_LOWERCASE,​ ES_UPPERCASE and ES_OEMCONVERT which are not supported by Rich Edit controls.\\ \\  Refer to the documentation for [[http://​www.bbcbasic.co.uk/​bbcwin/​manual/​bbcwing.html#​fnwindow|FN_createwindow]] for the meaning of the parameters.\\ \\  You may want to combine other window styles with the **WS_BORDER** value. Rich Edit controls will respond to most of the style values allocated to multiline edit controls; notable exceptions are ES_LOWERCASE,​ ES_UPPERCASE and ES_OEMCONVERT which are not supported by Rich Edit controls.\\ \\ 
 ===== 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 "​SetDlgItemText",​ !dlg%, reid%, text$         SYS "​SetDlgItemText",​ !dlg%, reid%, text$
Line 58: Line 71:
         REM Control on main window:         REM Control on main window:
         SYS "​SetWindowText",​ hre%, text$         SYS "​SetWindowText",​ hre%, text$
 +</​code>​
 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%,​ id%)         DEF FNgettext(dlg%,​ id%)
Line 72: Line 87:
         SYS "​GetWindowText",​ hedit%, text%, 65536         SYS "​GetWindowText",​ hedit%, text%, 65536
         = $$text%         = $$text%
 +</​code>​
 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 "​SendDlgItemMessage",​ !dlg%, reid%, EM_SETBKGNDCOLOR,​ 0, bgcolor%         SYS "​SendDlgItemMessage",​ !dlg%, reid%, EM_SETBKGNDCOLOR,​ 0, bgcolor%
Line 78: Line 95:
         REM Control on main window:         REM Control on main window:
         SYS "​SendMessage",​ hre%, EM_SETBKGNDCOLOR,​ 0, bgcolor%         SYS "​SendMessage",​ hre%, EM_SETBKGNDCOLOR,​ 0, bgcolor%
 +</​code>​
 Here **bgcolor%** should contain the required colour in the **COLORREF** format, i.e. a hexadecimal value of the form &​00BBGGRR.\\ \\  To change the text font (including its colour and style) you first need to create and initialise a CHARFORMAT structure:​\\ \\  Here **bgcolor%** should contain the required colour in the **COLORREF** format, i.e. a hexadecimal value of the form &​00BBGGRR.\\ \\  To change the text font (including its colour and style) you first need to create and initialise a CHARFORMAT structure:​\\ \\ 
 +<code bb4w>
         DIM cfmt{cbSize%,​ dwMask%, dwEffects%, yHeight%, yOffset%, crTextColor%,​ \         DIM cfmt{cbSize%,​ dwMask%, dwEffects%, yHeight%, yOffset%, crTextColor%,​ \
         \        bCharSet&,​ bPitchAndFamily&,​ szFaceName&​(31),​ padding&​(1)}         \        bCharSet&,​ bPitchAndFamily&,​ szFaceName&​(31),​ padding&​(1)}
Line 88: Line 107:
         cfmt.crTextColor% = fgcolor%         cfmt.crTextColor% = fgcolor%
         cfmt.szFaceName&​() = facename$         cfmt.szFaceName&​() = facename$
 +</​code>​
 Here **style%** is a combination of the **"​CFE_"​** constants (see the initialisation code above), **height%** is the character height in twips (1/1440 inch), **fgcolor%** is the text colour (as for **bgcolor%** above) and **facename$** is the font name (e.g. ""​Arial""​).\\ \\  Once you have initialised the CHARFORMAT structure you can use it to format the text in the control as follows:\\ \\  Here **style%** is a combination of the **"​CFE_"​** constants (see the initialisation code above), **height%** is the character height in twips (1/1440 inch), **fgcolor%** is the text colour (as for **bgcolor%** above) and **facename$** is the font name (e.g. ""​Arial""​).\\ \\  Once you have initialised the CHARFORMAT structure you can use it to format the text in the control as follows:\\ \\ 
 +<code bb4w>
         REM Control in dialogue box:         REM Control in dialogue box:
         SYS "​SendDlgItemMessage",​ !dlg%, reid%, EM_SETCHARFORMAT,​ SCF_ALL, cfmt{}         SYS "​SendDlgItemMessage",​ !dlg%, reid%, EM_SETCHARFORMAT,​ SCF_ALL, cfmt{}
Line 94: Line 115:
         REM Control on main window:         REM Control on main window:
         SYS "​SendMessage",​ hre%, EM_SETCHARFORMAT,​ SCF_ALL, cfmt{}         SYS "​SendMessage",​ hre%, EM_SETCHARFORMAT,​ SCF_ALL, cfmt{}
 +</​code>​
 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'​s documentation.\\ \\ // Addendum: by Michael Hutton, July 2010 //\\  You may want to use the CHARFORMAT2{} with the Rich Edit Control. Here is its definition:​\\ ​ 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'​s documentation.\\ \\ // Addendum: by Michael Hutton, July 2010 //\\  You may want to use the CHARFORMAT2{} with the Rich Edit Control. Here is its definition:​\\ ​
 +<code bb4w>
         DIM CHARFORMAT2{cbSize%, ​                  \         DIM CHARFORMAT2{cbSize%, ​                  \
         \              dwMask%, ​                   \         \              dwMask%, ​                   \
Line 116: Line 139:
         \              bRevAuthor&, ​               \         \              bRevAuthor&, ​               \
         \              bReserved1& ​               }         \              bReserved1& ​               }
 +</​code>​
using_20rich_20edit_20controls.txt ยท Last modified: 2018/04/15 18:48 by tbest3112