kumar.shashank wrote:

> I need to create a text editor using C++. Here's the code I have
> developed till now. Let me know more about handling ASCII values during
> input. Specifically here's what I want to do:-
>
> Pressing ...
>
> ESCAPE-->Quits the program
>
> ENTER-->Cursor moves to next line
>
> BACKSPACE-->deletes the character to the left of the cursor.
>
> Make the left and right arrow keys functional.
>
> #include<iostream.h>
> #include<conio.h>
> #include<graphics.h>
> #include<dos.h>
> #include<math.h>
> #include<stdlib.h>

Is this a MS-DOS program? It looks like it from the includes.

I can't help much with DOS, because I've been programming Windows and Mac
since 1991. I have some pointers about how I'd do things in Windows, so
maybe you can transfer these to DOS.

First, the arrow keys don't have ASCII values. ENTER is 13, ESCAPE is ASCII
27, and I think BACKSPACE is 8 (all numbers base 10).

I have a header file where I define the keys with something like this:

#define BKEY_TAB        (U32)9
#define BKEY_PAUSE      (U32)0x13
#define BKEY_ESC        (U32)0x1B
#define BKEY_BACK       (U32)0x08
#define BKEY_ENTER      (U32)0x0D

Then I handle them in a switch construct that goes something like this:

virtual VOID        OnKeyHit(U32 lKey, U32 lRepCount); // declaration

VOID MyClass::OnKeyHit(U32 lKey, U32 lCount)
        switch (lKey)
        {
                case BKEY_ENTER:
                        DoSomething();
                        break;
                case BKEY_ESC:
                        AppClassObj->Quit();
                        break;

                default:
                        inherited::OnKeyUp(lKey, lCount);
                        break;
        }

> closebutton()
> {
> int x,y,a,b,button;
> x=getmaxx();
> y=getmaxy();
> getmouse(&button,&a,&b);
> if((button&=1)==1)
> {
> if((a>=(x/2)+148)&&((a<=(x/2)+162))&&((b>=(y/2)-129))&&(b<=(y/2)-116))
> {
> delay(10000);
> setcolor(DARKGRAY);
> rectangle(((x/2)+1488),((y/2)-130),((x/2)+163),((y/2)-116));
> setcolor(15);
> rectangle(((x/2)+149),((y/2)-129),((x/2)+163),((y/2)-116));
> setfillstyle(SOLID_FILL,LIGHTGRAY);
> bar(((x/2)+149),((y/2)-129),((x/2)+162),((y/2)-117));
> setcolor(0);
> outtextxy(((x/2)+154),((y/2)-126),"x");
> delay(15000);
> closegraph();
> restorecrtmode();
> exit(0);
> }
> }
> return(0);
> }

In your case, I would take some of the code from your closebutton()
function--the part that actually closes the program--and move it into its on
function (e.g., EndProgram()), and call it from either the escape or a click
on the close button.

Likewise, I would handle the arrow keys in the same switch statement.

Hope this helps. You've got a really good start--this is pretty good
student-level code.

Cordially,

Kerry Thompson




To unsubscribe, send a blank message to <mailto:[EMAIL PROTECTED]>. 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/c-prog/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to