Edit Control

 

About Edit Control

 

A rectangle box that allow users to enter and edit text. 

 

The edit control has many styles, which can be used together.  When you call createctrl to create an edit control, you must specify the combination of styles that defines the appearance and features of an edit control.

 

In general, there are two types of edit controls.  One is Single Line edit control, and the other one is Multiple Line edit control.  By default, edit controls are single line edit control.  You can create a multiple line edit control by using ES_MULTILINE flag.

 

An edit control can also determine how the text is displayed.  The ES_LOWERCASE style will cause the edit control’s text appears in lowercase.  The ES_UPPERCASE style will cause the edit control’s text appears in uppercase. 

 

The text alignment can be adjusted with ES_LEFT, ES_CENTER, and ES_RIGHT.  To avoid showing sensitive text in the edit box, ES_PASSWORD style will turn every character into an asterisk character. 

 

In most cases, programmers don’t know how long the text will be displayed through the edit control.  ES_AUTOVSCROLL will automatically scroll text vertically, and ES_AUTOHSCROLL will automatically scroll text horizontally if necessary. 

 

By default, the edit control has no border around the text.  If WS_BORDER style is not specified as part of the combination of styles, you will not notice the edit control until text is displayed through the control.

 

Using Edit Control

 

createctrl(string strCtrl, string strName, int nStyle, int nExStyle, int xpos, int ypos, int width, int height, int nID)

 

Example 1: Simply create an edit control

 

createctrl(

"EDIT",      /* Predefined Control */

"",           /* No Window Title */

WS_BORDER | WS_CHILD | WS_VISIBLE | ES_LEFT | ES_AUTOHSCROLL,

0,             /* No Ex Styles */

50,30,100,20,     /*Control Size */

601           /* Edit Control ID */

);

 

Example 2: Cut, Paste, Clear, Undo with an edit control

 

/*  Interface Control -- Window */

 

#define     WS_CHILD           0x40000000   

/*Specifies a child window. This should not be changed after the window is created.*/

#define     WS_VISIBLE         0x10000000   

/*Specifies a window that is initially visible. This style can be turned on and off to change window visibility.*/

#define     WS_BORDER               0x00800000   

/*draw a border around the control*/

 

#define WM_CUT                         0x0300

#define WM_COPY                        0x0301

#define WM_PASTE                       0x0302

#define WM_CLEAR                       0x0303

#define WM_UNDO                        0x0304

 

#define PM_COMMAND 8

 

/* custom define values */

#define ED_TEST_ID    600

#define BTN_UNDO_ID        601

#define BTN_COPY_ID        602

#define BTN_PASTE_ID       603

#define BTN_CLEAR_ID       604

 

main()

{

    

int ev; int gui_msg;

 

createctrl("EDIT","",WS_BORDER|WS_CHILD|WS_VISIBLE,0,50,30,100,20, ED_TEST_ID);

createctrl("BUTTON","Undo",WS_VISIBLE|WS_CHILD|WS_BORDER,0,50,75,100,20, BTN_UNDO_ID);

createctrl("BUTTON","Copy",WS_VISIBLE|WS_CHILD|WS_BORDER,0,50,100,100,20, BTN_COPY_ID);

createctrl("BUTTON","Paste",WS_VISIBLE|WS_CHILD|WS_BORDER,0,50,125,100,20, BTN_PASTE_ID);

createctrl("BUTTON","Clear",WS_VISIBLE|WS_CHILD|WS_BORDER,0,50,150,100,20, BTN_CLEAR_ID);

 

while(1)

{

ev = event(0);

switch (ev){

 

case PM_COMMAND :

 

     gui_msg = guiid();

switch  (gui_msg)

{

case BTN_UNDO_ID:

sendmsg(ED_TEST_ID,WM_UNDO,0,0);

break;

               case BTN_COPY_ID:

                    sendmsg(ED_TEST_ID,WM_COPY,0,0);

                    break;

               case BTN_PASTE_ID:

                    sendmsg(ED_TEST_ID,WM_PASTE,0,0);

                    break;

               case BTN_CLEAR_ID:

                    sendmsg(ED_TEST_ID,WM_CLEAR,0,0);

                    break;

     };

    

     break;

};

}

}

 

Edit Control Reference

 

ES_AUTOHSCROLL    0x0080      /*Automatically scrolls text to the right by 10 characters when the user types a character at the end of the line. When the user presses the enter key, the control scrolls all text back to position zero.*/

 

ES_AUTOVSCROLL          0x0040      /*Scrolls text up one page when the user presses the ENTER key on the last line.*/

 

ES_CENTER         0x0001      /*Centers text in a multiline edit control.*/

 

ES_LEFT           0x0000      /*Left-aligns text.*/

 

ES_LOWERCASE            0x0010      /*Converts all characters to

lowercase as they are typed into the edit control.*/

 

ES_MULTILINE            0x0004      /*Designates a multiline edit control. The default is a single-line edit control.*/

 

ES_NOHIDESEL            0x0100      /*Negates the default behavior for an edit control. The default behavior hides the selection when the control loses the input focus and inverts the selection when the control receives the input focus. If you specify ES_NOHIDESEL, the selected text is inverted, even if the control does not have the focus.*/

 

ES_NUMBER         0x2000      /*Allows only digits to be typed into the edit control.*/

 

ES_OEMCONVERT           0x0400      /*Converts text typed in the edit control from the Windows character set to the OEM character set, and then converts it back to the Windows set. This style is most useful for edit controls that contain file names.*/

 

ES_PASSWORD       0x0020      /*Displays an asterisk (*) for each character typed into the edit control. You can use the EM_SETPASSWORDCHAR message to change the character that is displayed.*/

 

ES_READONLY       0x0800      /*Prevents the user from typing or editing text in the edit control.*/

 

ES_RIGHT          0x0002      /*Right-aligns text in a multiline edit control.*/

 

ES_UPPERCASE            0x0008      /*Converts all characters to uppercase as they are typed into the edit control.*/

 

ES_WANTRETURN           0x1000      /*Specifies that a carriage return be inserted when the user presses the ENTER key while typing text into a multiline edit control in a dialog box. If you do not specify this style, pressing the ENTER key has the same effect as pressing the dialog box's default push button. This style has no effect on a single-line edit control.*/