Beispiel #1
0
/* Allows the user to edit a string with only certain characters allowed -
    Returns TRUE if ESC was not pressed, FALSE is ESC was pressed. */
int editstring(char *s, char *legal, int maxlength)
{
    int c, len = strlen(s), pos = len, insert = TRUE;

    changecursor(insert);
    do {
        writef(1, 25, WHITE, 79, "%s", s);
        gotoxy(pos + 1, 25);
        switch(c = getkey()) {
        case HOMEKEY :
            pos = 0;
            break;
        case ENDKEY :
            pos = len;
            break;
        case INSKEY :
            insert = !insert;
            changecursor(insert);
            break;
        case LEFTKEY :
            if (pos > 0)
                pos--;
            break;
        case RIGHTKEY :
            if (pos < len)
                pos++;
            break;
        case BS :
            if (pos > 0) {
                movmem(&s[pos], &s[pos - 1], len - pos + 1);
                pos--;
                len--;
            }
            break;
        case DELKEY :
            if (pos < len) {
                movmem(&s[pos + 1], &s[pos], len - pos);
                len--;
            }
            break;
        case CR :
            break;
        case UPKEY :
            break;
        case DOWNKEY :
            break;
        case ESC :
            break;
        default :
            if (((legal[0] == 0) || (strchr(legal, c) != NULL)) &&
                    ((c >= ' ') && (c <= '~')) &&
                    (len < maxlength)) {
                if (insert) {
                    memmove(&s[pos + 1], &s[pos], len - pos + 1);
                    len++;
                }
                else if (pos >= len)
                    len++;
                s[pos++] = c;
            }
            break;
        } /* switch */
        s[len] = 0;
    }
    while ((c!=UPKEY)&&(c!=DOWNKEY)&&(c!=CR)&&(c!=ESC));
    clearinput();
    changecursor(FALSE);
    setcursor(nocursor);
    return(c != ESC);
} /* editstring */
Beispiel #2
0
void main()
{
int gd=DETECT,gm,button,x,y,area,i,choice;
char *p;

initgraph(&gd,&gm,"d:\\tc\\bgi");

if(initmouse()==0)
	{
	closegraph();
	puts("Mouse not installed");
	exit(1);
	}

for(i=0;i<2;i++)
	{
	changecursor(c[i]);
	showmouseptr();
	getmousepos(&button,&x,&y);
	area=imagesize(x-15,y-7,x+32,y+24);
	(char)p=(char)malloc(area);
	getimage(x-15,y-7,x+32,y+24,p);
	putimage(i*48+1,1,p,COPY_PUT);
	rectangle(i*60,0,(i+1)*60,45);
	}

gotoxy(10,25);
printf("click on the rectangles to see the cursors \n \n \npress any key to exit");
choice=1;
disp(choice,p);
changecursor(c[choice-1]);

while(!kbhit())
	{
	getmousepos(&button,&x,&y);

	if((button & 1)==1)
		{
		for(i=0;i<4;i++)
			{
			if(choice-1==i)
			   continue;

			if(y>0 && y<33)
				{
				if(x>i*48 && x<(i+1)*48)
					{
					hidemouseptr();
					disp(choice,p);
					choice=i+1;
					disp(choice,p);
					changecursor(c[choice-1]);
					showmouseptr();
					}
				}

			}
		}
	}

getch();
}