📄 tcxldemo.c
字号:
/*
TCXLDEMO.C - A demonstration program of the TCXL function library.
(c) 1987, 1988 by Mike Smedley
To compile:
from the command line type: tcc tcxldemo tcxl.lib
or:
make -ftcxldemo
or:
from the environment, specify 'TCXLDEMO.PRJ' as the Project Name
*/
#include <conio.h>
#include <dos.h>
#include <process.h>
#include <stdio.h>
#include "tcxldef.h"
#include "tcxlkey.h"
#include "tcxlvid.h"
#include "tcxlwin.h"
void interrupt exit_prog(void);
void error_exit(void);
void pulldown_demo(void);
int row,col,*sbuf1; /* global variables */
main()
{
register int i,j;
int ch;
int whandle[10];
int *sbuf2;
char *fname=" ";
char *mi=" ";
char *lname=" ";
char *phone=" ";
char *pressakey="Press a key";
char *spaces= " ";
videoinit(); /* initialize video */
sbuf1=ssave(); /* save current screen contents */
if(!sbuf1) error_exit();
readcur(&row,&col); /* save current cursor position */
setcursz(32,0); /* turn off cursor */
setvect(0x23,exit_prog); /* redirect Ctrl-Break interrupt */
setcbrk(ON); /* set Ctrl-Break checking on */
for(;;) {
/* open up opening screen windows */
for(i=0;i<6;i++) {
whandle[i]=wopen(i,i+10,i+13,i+47,3,LCYAN|_BLUE);
if(!whandle[i]) error_exit();
/* sound tones of increasing pitch */
sound_(15000-((i+2)*1500),1);
sound_(12000-((i+1)*1500),1);
}
wprints(0,16,LRED,"TCXL");
wprints(1,2,LGREEN,"An Extended Library of Functions");
wprints(2,12,LGREEN,"for Turbo C");
wprints(4,10,YELLOW,"by Mike Smedley");
wprints(6,0,LMAGENTA,"(c) 1987, 1988 - All Rights Reserved");
wprints(8,7,WHITE,"Demonstration Program");
wprints(10,7,LCYAN|_BLUE,"Press any key to begin");
/* change colors of prompt until a key is pressed */
i=LBLUE;
for(;;) {
gotoxy_(16,22);
setattr(i|_BLUE,23);
delay_(2);
if(kbhit()) {
ch=getch();
break;
}
i++;
if(i>WHITE) i=LBLUE;
}
if(ch==ESC) exit_prog(); /* see if Esc key was pressed */
wprints(10,7,_BLUE," ");
/* scroll the window's text up and out of the window */
for(i=0;i<10;i++) {
wscroll(1,UP);
delay_(2);
}
/* close all open windows */
for(i=5;i>=0;i--) {
wclose();
delay_(2);
}
/* open demo window 0 and demonstrate text wraparound and
scrolling from within a window */
whandle[0]=wopen(1,1,11,41,0,LMAGENTA|_RED);
if(!whandle[0]) error_exit();
wtextattr(LCYAN|_RED);
wprintf("\n TCXL's window display functions like"
"\n wprintf() & wputs() allow wrap-around"
"\n and scrolling from within windows.");
wprints(7,14,YELLOW|BLINK|_RED,pressakey);
if(waitkeyt(273)==ESC) exit_prog();
wprints(7,14,_RED,spaces);
wgotoxy(8,0);
for(i=0;i<15;i++) {
if(kbhit()) {
if(getch()==ESC) exit_prog();
break;
}
for(j=DGREY;j<=WHITE;j++) {
wtextattr(j|_RED);
wputs("TCXL ");
delay_(1);
}
}
/* open demo window 1 and demonstrate changing of window attribute */
whandle[1]=wopen(14,35,23,65,2,YELLOW|_BLUE);
if(!whandle[1]) error_exit();
wtextattr(LCYAN|_BLUE);
wputs("\n The wchgattr() function"
"\n allows you to change the"
"\n attribute of the active"
"\n window.");
wprints(6,9,YELLOW|BLINK|_BLUE,pressakey);
if(waitkeyt(273)==ESC) exit_prog();
wprints(6,9,_BLUE,spaces);
wchgattr(WHITE|_GREEN);
delay_(12);
wchgattr(LMAGENTA|_RED);
delay_(12);
wchgattr(LCYAN|_BLUE);
if(kbhit()) { /* check for keypress */
if(getch()==ESC) exit_prog();
}
delay_(12);
wchgattr(YELLOW|_MAGENTA);
delay_(12);
wchgattr(WHITE|_LGREY);
delay_(12);
/* open demo window 2 and demonstrate window titles
and resizing of windows */
whandle[2]=wopen(5,20,19,45,3,LCYAN|_GREEN);
if(!whandle[2]) error_exit();
wtextattr(WHITE|_GREEN);
wputs("\n The wtitle() function"
"\n allows you to give a"
"\n window a title.");
wprints(5,6,YELLOW|BLINK|_GREEN,pressakey);
if(waitkeyt(273)==ESC) exit_prog();
wprints(5,6,_GREEN,spaces);
wtitle("[ My Title ]",TLEFT);
delay_(18);
wtitle("[ My Title ]",TRIGHT);
delay_(18);
wtitle("[ My Title ]",TCENTER);
wtextattr(LGREEN|_GREEN);
wputs("\n\n\n The wsize() function"
"\n allows you to resize"
"\n the active window.");
wprints(10,6,YELLOW|BLINK|_GREEN,pressakey);
if(waitkeyt(273)==ESC) exit_prog();
wprints(10,6,_GREEN,spaces);
wsize(19,60);
delay_(12);;
wsize(19,75);
delay_(12);;
wsize(24,75);
delay_(12);;
wsize(24,60);
delay_(12);;
wsize(24,45);
delay_(12);;
wsize(19,45);
delay_(12);;
/* open demo window 3 and demonstrate multi-field keyboard input */
whandle[3]=wopen(12,10,23,50,1,LCYAN|_BLUE);
if(!whandle[3]) error_exit();
wtextattr(LMAGENTA|_BLUE);
wputs("\n The winpdef() and winpread()"
"\n functions allow multi-field"
"\n keyboard input.");
wprints(3,21,YELLOW|BLINK|_BLUE,pressakey);
if(waitkeyt(273)==ESC) exit_prog();
wprints(3,21,_BLUE,spaces);
wprints(5,2,LCYAN|_BLUE,"First name?");
if(winpdef(5,15,fname,'M',BLACK|_LGREY)) error_exit();
wprints(5,26,LCYAN|_BLUE,"MI?");
if(winpdef(5,31,mi,'U',BLACK|_LGREY)) error_exit();
wprints(7,2,LCYAN|_BLUE,"Last name?");
if(winpdef(7,15,lname,'M',BLACK|_LGREY)) error_exit();
wtextattr(LGREEN|_BLUE);
setcursz(6,7); /* turn cursor on */
i=winpread();
setcursz(32,0); /* turn cursor back off */
if(i) exit_prog(); /* check for Esc press */
/* open demo window 4 and demonstrate controlled keyboard input */
whandle[4]=wopen(8,41,16,78,3,WHITE|_MAGENTA);
if(!whandle[4]) error_exit();
wtextattr(LGREEN|_MAGENTA);
wputs("\n For complete control of keyboard"
"\n input, there is the winputsf()"
"\n function. ");
wprints(3,13,YELLOW|BLINK|_MAGENTA,pressakey);
if(waitkeyt(273)==ESC) exit_prog();
wprints(3,13,_MAGENTA,spaces);
wtextattr(WHITE|_MAGENTA);
setcursz(6,7); /* turn cursor on */
i=winputsf(phone," '\n\n Phone number? ' !R-! "
" !-! '(' !+! ### !-! ') ' !+! ### !-! '-' !+! #### ");
setcursz(32,0); /* turn cursor back off */
if(i) exit_prog(); /* check for Esc press */
/* clear window 4 and demonstrate text line drawing */
wclear();
wsize(22,78);
wtextattr(LGREEN|_MAGENTA);
wputs("\n The whline() & wvline() functions"
"\n are used for drawing 'smart' text"
"\n lines inside the active window.");
wprints(5,12,YELLOW|BLINK|_MAGENTA,pressakey);
if(waitkeyt(273)==ESC) exit_prog();
wprints(5,12,_MAGENTA,spaces);
wtextattr(LCYAN|_MAGENTA);
whline(6,2,23,3);
delay_(18);
wvline(5,5,7,3);
delay_(18);
whline(10,1,25,3);
delay_(18);
wtextattr(LBLUE|_MAGENTA);
if(kbhit()) { /* check for keypress */
if(getch()==ESC) exit_prog();
}
wvline(6,25,5,3);
delay_(18);
whline(8,5,21,3);
delay_(18);
wvline(5,16,6,3);
delay_(18);
wtextattr(LGREEN|_MAGENTA);
whline(7,2,15,3);
delay_(18);
whline(5,9,15,3);
if(waitkeyt(108)==ESC) exit_prog();
/* clear window 4 and demonstrate pull-down & bar-selection menus */
wclear();
wtextattr(LGREEN|_MAGENTA);
wputs("\n With the wmbardef() & wmbarget()"
"\n functions, you can make pull-down"
"\n and bar-select menus.");
wprints(5,12,YELLOW|BLINK|_MAGENTA,pressakey);
if(waitkeyt(273)==ESC) exit_prog();
pulldown_demo();
if(waitkeyt(273)==ESC) exit_prog();
wprints(5,12,_MAGENTA,spaces);
wprints(3,24,YELLOW|_MAGENTA,"Select one:");
wmbardef(5,3,LCYAN|_MAGENTA,"Add record",'A');
wmbardef(5,18,LCYAN|_MAGENTA,"Show record",'S');
wmbardef(7,3,LCYAN|_MAGENTA,"Delete record",'D');
wmbardef(7,18,LCYAN|_MAGENTA,"Update record",'U');
wmbardef(9,3,LCYAN|_MAGENTA,"Print record",'P');
wmbardef(9,18,LCYAN|_MAGENTA,"Quit program",'Q');
i=wmbarget(LCYAN|_LGREY,'A',NO);
wprints(3,24,_MAGENTA,spaces);
if(!i) exit_prog();
wgotoxy(11,10);
wtextattr(WHITE|_MAGENTA);
wprintf("You selected %c!",i);
delay_(12);
/* open demo window 5 and demonstrate screen swapping */
whandle[5]=wopen(3,3,12,33,0,YELLOW|_BLACK);
if(!whandle[5]) error_exit();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -