| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 877 人关注过本帖
标题:鼠标编程分享
只看楼主 加入收藏
红影
Rank: 1
等 级:新手上路
威 望:2
帖 子:659
专家分:0
注 册:2006-2-22
结帖率:66.67%
收藏
 问题点数:0 回复次数:5 
鼠标编程分享
调试环境为TC2.0或者TC3.0。

#include<dos.h>
#include<conio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
#define HEX 0
#define DEC 1
#define OCT 2
#define BIN 3

int index=0,choice=0;
/*初始化鼠标器*/
void initmouse()
{
    _AX=0;
    geninterrupt(0x33);

}
/*显示鼠标光标*/
void showmouse()
{
    _AX=1;
    geninterrupt(0x33);
}
/*隐藏鼠标*/
void hidemouse()
{
    _AX=2;
    geninterrupt(0x33);
}
/*取鼠标状态和鼠标位置*/
void getmouse(int *button,int *x,int *y)
{
    _AX=3;
    _BX=0;
    geninterrupt(0x33);
    *button=_BL;
    *x=_CX;
    *y=_DX;
}
/*设置程序中的数字字符表*/
int getnum(char c)
{
    int    j;
    char alpha_set[36]="0123456789abcdefghijklmnopqrstuvwzyz";
    for(j=0;j<36;j++)
    {
        if(alpha_set[j]==c)
            break;
    }
    return j;
}
/*把任意radix进制的数,转换为十进制数*/
unsigned long convert_to_decimal(char *_num,int radix)
{
    int i,len;
    unsigned long dec=0;
    len=strlen(_num);
    len--;
    for(i=0;_num[i]!=NULL;i++,len--)
    {
        dec+=(getnum(_num[i])*pow(radix,len));
    }
    return dec;
}
/*在给定的坐标(x,y)的位置显示一个字符串*/
void display(int x,int y,char string[80])
{    gotoxy(x,y);
    cprintf(string);
}
/*清屏,并且把背景色设置为青绿色*/
void make_screen_cyan()
{
    textbackground(CYAN);
    clrscr();
}
/*绘制程序的初始界面*/
void start_screen()
{
    index=0;
    hidemouse();
    make_screen_cyan();
    textbackground(RED);
    textcolor(BLACK);
    display(20,1,"Radix Converter by NILOY MONDAL.");
    display(10,2,"Email:-yiwei@zju.);
    display(30,3,"Press Escape to Quit");
    textbackground(CYAN);
    display(10,5,"Hexadecimal:- ");
    display(10,7,"Decimal    :- ");
    display(10,9,"Octal      :- ");
    display(10,11,"Binary     :- ");
    textbackground(BLUE);
    display(23,5,"                                                      ");
    display(23,7,"                                                      ");
    display(23,9,"                                                      ");
    display(23,11,"                                                      ");
    if(choice==HEX)
        gotoxy(24,5);
    else if(choice==DEC)
        gotoxy(24,7);
    else if(choice==OCT)
        gotoxy(24,9);
    else if(choice==BIN)
        gotoxy(24,11);
    showmouse();
}

void main()
{
    char text[80]="\0",buffer[80];
    char ch,*charhex,*chardec,*charoct,*charbin;
    int button,mousex,mousey,x,y;
    unsigned long deci;

    initmouse();
    start_screen();
    showmouse();
    while(1)
    {
        if(kbhit())
        {
            ch=getch();
/*ESCAPE键的ASCII值是27,如果用户按下ESC,程序结束*/
            if(ch==27)        
                break;
/*如果按删除键并且光标没有越过输入框的边界*/
            if(ch=='\b'&&wherex()>=24)   
            {
/*把光标退后一格,并且放一个空格在那里*/
                cprintf("\b");
                cprintf("%c",255);
/*再把光标退后一格,弹出删除的字符*/
                cprintf("\b");
                if(index!=0)
                    index--;            
                text[index]=NULL;
            }
            else if(wherex()>=24&&ch>='0'&&ch<='f')
            {
                cprintf("%c",ch);
/*把字符放入字符数组*/
                text[index]=ch;            
/*把数组最后一位置零*/
                text[index+1]=NULL;    
                index++;
            }
/*保存当前的坐标*/
            x=wherex(),y=wherey();
/*程序首先把字符串通过convert_to_decimal()转化为十进制数,之后调用stdlib.h定义的ltoa()把十进制数转换为其它进制数,比如二进制、八进制、十六进制等等.*/
            switch(choice)
            {
                case HEX:
                    deci=convert_to_decimal(text,16);
                    gotoxy(24,7);
                    printf("%ld                             ",deci);
                    gotoxy(24,11);
                    printf("%s                              ",ltoa(deci,buffer,2));
                    gotoxy(24,9);
                    printf("%s                              ",ltoa(deci,buffer,8));
                    break;
                case DEC:
                    deci=atol(text);
                    gotoxy(24,5);
                    printf("%s                             ",ltoa(deci,buffer,16));
                    gotoxy(24,9);
                    printf("%s                             ",ltoa(deci,buffer,8));
                    gotoxy(24,11);
                    printf("%s                             ",ltoa(deci,buffer,2));
                    break;
                case OCT:
                    deci=convert_to_decimal(text,8);
                    gotoxy(24,7);
                    printf("%ld                             ",deci);
                    gotoxy(24,5);
                    printf("%s                             ",ltoa(deci,buffer,16));
                    gotoxy(24,11);
                    printf("%s                              ",ltoa(deci,buffer,2));
                    break;
                case BIN:
                    deci=convert_to_decimal(text,2);
                    gotoxy(24,5);
                    printf("%s                            ",ltoa(deci,buffer,16));
                    gotoxy(24,7);
                    printf("%ld                            ",deci);
                    gotoxy(24,9);
                    printf("%s                            ",ltoa(deci,buffer,8));
                    break;
            }
            gotoxy(x,y);
        }
        getmouse(&button,&mousex,&mousey);
        mousex++,mousey++;
/*下面的代码检测用户在什么地方按了什么按钮*/
        if(mousex/8>23&&mousex/8<50&&mousey/16==2&&button&1==1)
        {
            choice=HEX;
            start_screen();
        }
        else if(mousex/8>23&&mousex/8<50&&mousey/16==3&&button&1==1)
        {
            choice=DEC;
            start_screen();
        }

        else if(mousex/8>23&&mousex/8<50&&mousey/16==4&&button&1==1)
        {
            choice=OCT;
            start_screen();
        }
        else if(mousex/8>23&&mousex/8<50&&mousey/16==5&&button&1==1)
        {
            choice=BIN;
            start_screen();
        }
    }

}
搜索更多相关主题的帖子: 鼠标 分享 
2008-04-24 14:59
yemuzi
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2008-3-6
收藏
得分:0 
Very good, 谢了
2008-04-24 15:07
海纳百川
Rank: 1
来 自:湖北荆州
等 级:新手上路
帖 子:186
专家分:5
注 册:2007-10-2
收藏
得分:0 
这不错什么时候我有这个实力去编写这样的程序

2008-04-24 15:53
hoodlum1980
Rank: 2
来 自:浙江大学
等 级:论坛游民
威 望:2
帖 子:289
专家分:23
注 册:2008-2-24
收藏
得分:0 
不错!
PS:你是zju的吗?竟然是校友。
2008-04-25 01:54
neverTheSame
Rank: 3Rank: 3
来 自:江西农业大学
等 级:新手上路
威 望:9
帖 子:1511
专家分:0
注 册:2006-11-24
收藏
得分:0 
不错。还有一些关于鼠标操作的程序:
《发布TC2.0下实现鼠标操作的模块》
URL:https://hi.bccn.net/108519/viewspace-10092.html

wap酷禾网(http://wap.),提供免费的、优质的、快捷的wap资源下载服务。
2008-04-25 02:02
快速回复:鼠标编程分享
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016194 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved