- 注册时间
- 2004-9-4
- 最后登录
- 1970-1-1
|
发表于 2005-9-1 10:57:00
|
显示全部楼层
这个是我在灰度绘图器中使用的菜单
- 事先将所有选项保存在opItem字符串数组里面
- int OptionMenu(addr opTitle,char offset,char opNum,char cho);//绘制一个选项菜单,返回-1取消选择
- opTitle 菜单标题
- offset 第一选项在opItem的位置
- opNum 选项数目
- cho 默认选项
- int OptionMenu(addr opTitle,char offset,char opNum,char cho){
- char key;
- char lastMs;
- char lastKey;
- char index;
- index = 0;
- lastKey = 1;
- GetBlock(0,0,160,80,1,imageBuf);
- SetBgColor(4);
- Block(19,6,140,66,0);
- SetBgColor(0);
- SetFgColor(15);
- Rectangle(21,8,138,64,1);
- Line(22,23,137,23,0x42);
- TextOut(80-strlen(opTitle)*3,10,opTitle,5);
- do{
- if (cho - index > 2){
- index = cho - 2;
- }
- if (index > cho && index > 0){
- index--;
- }
- SetBgColor(4);
- Block(22,24,137,63,0);
- SetBgColor(0);
- SetFgColor(15);
- sprintf(textBuf,"%s",opItem[index+offset]);
- TextOut(23,25,textBuf,5);
- sprintf(textBuf,"%s",opItem[index+1+offset]);
- TextOut(23,38,textBuf,5);
- if (opNum > 2 ){
- sprintf(textBuf,"%s",opItem[index+2+offset]);
- TextOut(23,51,textBuf,5);
- }
- if (index < opNum - 3){
- TextOut(125,51,"↓",5);
- }
- if (index > 0){
- TextOut(125,25,"↑",5);
- }
- Refresh();
- Box(22,24+(cho-index)*13,125,37+(cho-index)*13,1,2);
- if (lastKey ==1){
- getchar();
- lastKey = 0;
- }
- ReleaseKey(128);
- do{
- key = getchar();
- }while(key != KEY_UP &&
- key != KEY_DOWN &&
- key != KEY_ESC &&
- key != KEY_ENTER)
- lastMs = Getms();
- if (key == KEY_DOWN && cho < opNum - 1){
- cho++;
- }
- if (key == KEY_UP && cho > 0){
- cho--;
- }
- if (key == KEY_ENTER){
- WriteBlock(0,0,160,80,1,imageBuf);
- Refresh();
- SetFgColor(fgColor);
- SetBgColor(bgColor);
- return cho;
- }
- while (((Getms()-lastMs)&0xff)<256/10);
- }while(key != KEY_ESC);
- WriteBlock(0,0,160,80,1,imageBuf);
- Refresh();
- SetFgColor(fgColor);
- SetBgColor(bgColor);
- return -1;
- }
复制代码 |
|