| Header file: | edit.h |
| Object name: | fEDIT |
| Object index: | 1 of 1 Object |
The fEDIT control is a wrapper for the window class "edit". It is an edit control that is fully functional and very useful. It can get text from the user in either a single-line form or a multiline form. It can accept the TAB key or allow this key to change the focus of controls. It is a rather versatile component that you should find useful.
This component is derived from _GUIBASE, and inherits the properties from that.
Also, this component is derived via the common edit class too - as some of the properties available on an edit control are also available/applicable on a richedit control, this makes it possible to share the properties with the richedit control too. Don't bother yourself too much with this, it's just something that you might like to be aware of should you wish to modify these controls. These common properties are in the file commonedit.h.
| Name | Description | Value |
| txUsual | This style is the style which you will most likely use. It simply gives the edit control a 3D carved border. | WS_EX_CLIENTEDGE |
| txRaisedBorder | This style gives the edit control a raised border. | WS_EX_WINDOWEDGE |
| txNoStyle | This style gives the edit control no 3D border at all. Providing you do not have the WS_BORDER style for the secondary style, the edit control will not have a border at all. | 0 |
| Name | Description | Value |
| txNormal | This is the style that you would use for a standard edit control. | WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL |
| txMemo | This is the style that you would use for a small Memo control. A memo control is just like an edit control, except that it can handle more than one line, and up to 64 kilobytes of text. This style has been set up in such a way that it will word wrap by default. You will need to combine a style which is shown further down to make it scroll horizontally. | WS_VISIBLE | WS_CHILD | ES_AUTOVSCROLL | ES_MULTILINE | ES_WANTRETURN |
| txPassword | This style is just like the first style, except that it is preconfigured to work as a password box - it masks all the characters that you type in with another character that you can specify. | WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL | ES_PASSWORD |
| The following options are a little different. Whereas the above options are a mixture of styles to create one type of object, the following styles are by themselves. You can mix them up to make more customised objects. You mix the styles with the OR (|) operator. You can even mix them with the above styles to enhance them further. Mix and match away! | ||
| tsBorder | This style makes the edit control have a thin (1-pixel wide) black border. You can only see this border if you do not have a 3D border. | WS_BORDER |
| tsMultiline | This style makes the edit control able to accept multiple lines of text. | ES_MULTILINE |
| tsScrollBars | This style makes the edit control show both scrollbars. Because both scrollbars are enabled, the scrollbars will be shown even if they are not needed, but disabled until they are needed. The scrollbars can only be shown if the edit control has a multiline style. | ES_AUTOVSCROLL | ES_AUTOHSCROLL |
| tsNoWordWrap | This style disables word wrap in a multiline edit control. Please note that this style will also display a scrollbar at the bottom of the window. | ES_AUTOHSCROLL |
| tsWantEnter | This style allows a multiline edit control to accept the enter key, and go to the next line. | ES_WANTRETURN |
| tsReadOnly | This style disables the ability to be able to edit the contents of an edit control. However, the user may still select text and copy it. | ES_READONLY |
| tsNumbersOnly | This style allows only number keys to be pressed inside an edit control. All other keys will be ignored. An unfortunate exclusion of the keys that can be pressed is the dot/full stop (.). This means that you can not use this style to create an edit control that will accept numbers with decimal points. What a shame - this addition would make this style a be-all-and-end-all of number entry. Instead, you will need to devise a method of allowing the entry of decimal points. | ES_NUMBER |
|
tsLowerCase tsUpperCase | These two styles do exactly what the name would suggest - automatically convert the characters as they are typed in to the corresponding case. Please do not use both of these styles simultaneously - I don't know what happens if you do. | ES_LOWERCASE and ES_UPPERCASE |
|
txLeft txCenter txRight | These three styles align the text as the name suggests. Simple and easy. I would advise against applying any more than one of these styles at once. | WS_VISIBLE | etc... |
| Prototype | Description |
| int GetNoLines(void); | This function returns the number of lines of text in a multiline edit control. |
| int GetTextLength(void); | This function returns the size of the text in the edit control. The size returned is in bytes. |
| char* GetLine(int Index); | This function returns the text of one line only in a multiline edit control. Please note that index is Zero based, so the first line is index 0 (Zero). |
| int GetTopLineIndex(void); | This function returns the index of the line that is currently being shown at the top of the multiline edit control. |
| void AddText(char* Text); | This function adds text to the contents of the edit control. |
| void AddNumber(int Number); | This function converts the number to a string, and then adds that to the contents of the edit control. |
| void AddNumber(double Number); | This function converts a number of the double type (or equivalent) to a string, and then adds that to the contents of the edit control. |
| void SetModifiedFlag(bool Set); | Internally, the edit control remembers whether or not the contents have been modified. You can reset the flag with this function, or you can set the flag to say that it has been modified. You would pass TRUE to set the flag to say that "the control HAS been modified", but you would pass FALSE to set the flag to say that "the control HAS NOT been modified". |
| bool GetModifiedFlag(void); | This function checks to see if the contents of the edit control has been changed, causing the edit control to change it's internal flag to sat that it has changed (or not). |
| void ChangePasswordCharacter(char* Character); | This function sets the character that it used to mask the text in an edit control if it is of the password style. |
| void SetMaxLength(int Length); | This function sets the maximum length of the text able to be placed into the edit control. This can be up to 32,766 bytes for a single line edit control, and 65,535 bytes for a multiline edit control. If you want a multiline edit control with more text, then please use the fRICHEDIT control. |
| void SetReadOnly(bool Set); | This function sets whether or not the edit control is read only or not. Pass TRUE to make the edit control read only, or pass FALSE to make the edit control not-read only. |
| void SetBackGroundColour(COLORREF Colour); | This function sets the background colour for the object. You do not need to have the GUI controller enabled to be able to use this function. |
| void SetSelection(int Start, int End); | This function sets the text that is selected in the edit control. The text selected will start at Start and finish at End. |
| int GetSelStart(void); | This function returns the position at which the currently selected text starts. If no text is selected, then the value returned is the position of the cursor. |
| int GetSelFinish(void); | This function returns the position at which the currently selected text finishes. If no text is selected, then the value returned is the position of the cursor. |
| char* GetSelText(void); | This function returns the text that is currently selected. |
| void ScrollToShowCaret(void); | This function makes the edit control scroll to the point where the user can see the cursor (or caret, or whatever you want to call it). |
| void ReplaceSelection(char* Text, bool CanUndo = TRUE); | This function replaces the text that is currently selected with the text that you specify. The CanUndo parameter tells the edit control whether or not to allow the user to undo your change. Pass TRUE to enable the user to undo the changes, and FALSE to disable this. The default is TRUE. |
|
void ScrollLineUp(void); void ScrollLineDown(void); void ScrollPageUp(void); void ScrollPageDown(void); | Each of these functions allow a multiline edit control to scroll in one way or another. I think these should be self explanatory. |
Please note that the events listed here are done in pairs; one as a property, and the other as a function. The property is assigned a function name, ie. Object.OnClick = &FunctionName, whilst the function is called to verify that an event has occured. Please see the chapter on event handling for information on how to use these correctly.
| Prototype | Description | Sent under |
|
bool CheckChanged(wParam, lParam); void (*OnChange)(fEDIT* Sender); | This event occurs when the contents of the edit control has been changed. Windows sends this event after it has updated the screen. | WM_COMMAND |
|
bool CheckUpdate(wParam, lParam); void (*OnUpdate)(fEDIT* Sender); | This event occurs when Windows is about to display the altered text. | WM_COMMAND |
|
bool CheckHScroll(wParam, lParam); void (*OnHScroll)(fEDIT* Sender); | This event occurs when the user scrolls the edit control horizontally. | WM_COMMAND |
|
bool CheckVScroll(wParam, lParam); void (*OnVScroll)(fEDIT* Sender); | This event occurs when the edit control is scrolled vertically. | WM_COMMAND |
|
bool CheckMaxText(wParam, lParam); void (*OnMaxText)(fEDIT* Sender); | This event occurs when the user has reached the maximum text allowed for this edit control. This event is also sent if you have an edit control without any scrolling styles and the edit control can not fit the last character the user typed in. | WM_COMMAND |
The following snippet gives a basic idea of how to use this component.
//This component is pretty simple to use.
fEDIT Edit;
Edit.CreateWin(&Window, "Initial Text", ID_EDIT, txUsual, txNormal);
Edit.SetCaption("Hello!!"); //This completely replaces the text.
bstring EditData = Edit.GetCaption();
//Please note that the .Set/.GetCaption() functions are inherited from GUIBASE.
//Anyway, that's basically how you use it. As for the rest? Experiment!
| Back to index | The FreeFoote Foundation Classes Documentation |