社区
C语言
帖子详情
请问在TC中如何实现鼠标操作
jinweifu
2005-12-02 04:35:15
我想用鼠标在C程序中画图 不知道如何实现 请大家给个方向,最好有代码
...全文
688
9
打赏
收藏
请问在TC中如何实现鼠标操作
我想用鼠标在C程序中画图 不知道如何实现 请大家给个方向,最好有代码
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
9 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
jinweifu
2005-12-03
打赏
举报
回复
顶出来 有人能详细做答吗?
jinweifu
2005-12-02
打赏
举报
回复
我想他调用中断是用33H号功能调用 它用了一个geninterrupt(0x33);函数 不过不能看到他的代码 可惜 它里面是不是用了汇编代码
是不是在_CX=vx; 这个是放了X坐标
_DX=vy;放了Y坐标
_AX=0x0f;这个决定了什么
jixingzhong
2005-12-02
打赏
举报
回复
看看 C高级程序设计 中的中断相关内容吧 ~
在 C 中要用鼠标作图, 一定要用中断的 ~
上面的程序,也是用的中断技术~
类似 _AX=0x03; 的语句都是 中断号 或者是 功能号 ...
jixingzhong
2005-12-02
打赏
举报
回复
是用的中断技术 ...
x86
2005-12-02
打赏
举报
回复
通过设置不同寄存器参数去调用中断0x33可以实现鼠标的各种功能。
比如说
void MouseGetXY(int *x,int *y)
{
_AX=0x03;
geninterrupt(0x33);
*x=_CX;
*y=_DX;
}
这个函数通过调用汇编代码来得到鼠标的坐标。
那个Cursor数组是一个16x16的整形数组,表示一个16x16的掩码。相应位置为1就在屏幕上画一个点,这样就可以画出一个鼠标图像。
MouseSave将鼠标坐标位置的图形先保存下来,然后再显示鼠标。MouseOff时将之前保存的图像恢复到屏幕。
jsjjms
2005-12-02
打赏
举报
回复
涉及硬件了,比较麻烦的。
jinweifu
2005-12-02
打赏
举报
回复
那些符号是C宏吗
jinweifu
2005-12-02
打赏
举报
回复
我看到了这样的鼠标代码 下面有人帮我分析一下吗
为什么要设置__AX,__DX等寄存器
这个是MOUSE.C文件
#include <graphics.h>
void MouseOn(int x,int y)
{
int Cursor[16][16]={
{1},
{1,1},
{1,1,1},
{1,1,1,1},
{1,1,1,1,1},
{1,1,1,1,1,1},
{1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1},
{1,1,1,1,1,1,1,1,1,1},
{1,1,1,1,1},
{1,1,1,0,1,1},
{1,1,0,0,1,1},
{1,0,0,0,0,1,1},
{0,0,0,0,0,1,1},
{0,0,0,0,0,0,1}
};
int i,j;
for(i=0;i<16;i++)
for(j=0;j<16;j++)
{
if(Cursor[i][j]!=0)
putpixel(x+j,y+i,RED);
}
}
void MouseSave(int Cursor[16][16],int x,int y)
{
int i,j;
for(i=0;i<16;i++)
for(j=0;j<16;j++)
Cursor[j][i]=getpixel(x+j,y+i);
}
MouseOff(int Cursor[16][16],int x,int y)
{
int i,j;
for(i=0;i<16;i++)
for(j=0;j<16;j++)
putpixel(x+j,y+i,Cursor[j][i]);
}
/*获取鼠标当前位置*/
void MouseGetXY(int *x,int *y)
{
_AX=0x03;
geninterrupt(0x33);
*x=_CX;
*y=_DX;
}
/*鼠标状态值初始化*/
void MouseReset()
{
_AX=0x00;
geninterrupt(0x33);
}
/*设置鼠标左右边界
lx:左边界
gx:右边界 */
void MouseSetX(int lx,int rx)
{
_CX=lx;
_DX=rx;
_AX=0x07;
geninterrupt(0x33);
}
/*设置鼠标速度(缺省值:vx=8,vy=1)
值越大速度越慢 */
void MouseSpeed(int vx,int vy)
{
_CX=vx;
_DX=vy;
_AX=0x0f;
geninterrupt(0x33);
}
/*获取鼠标按下键的信息*/
/*是否按下左键
返回值: 1=按下 0=释放*/
int LeftPress()
{
_AX=0x03;
geninterrupt(0x33);
return(_BX&1);
}
/*是否按下右键
返回值同上 */
int RightPress()
{
_AX=0x03;
geninterrupt(0x33);
return(_BX&2);
}
#include<graphics.h>
#include<conio.h>
#include<dos.h>
#include<stdio.h>
#include<f:\gui\mouse.c>
typedef struct MSG
{
int event;
int data;
struct MSG *next;
} msg;
typedef struct Window
{
int x,y;
int color,bkcolor;
int style;
}win;
typedef struct MENU{
int x,y;
int width,hight;
int bkcolor;
int fcolor;
int itemnum;
char *text;
void (*proc)(void *m,int e,msg data);
}menu;
typedef struct POINT
{
int x,y;
}point;
void *Buffer;
int x,y;
int Cursor[16][16];
point pt;
msg message[10];
msg TranslateMsg(menu *m,point *pt)
{
msg Msg;
int x=pt->y;
if(m==NULL)
{
Msg.event=3;
return Msg;
}
if((pt->x>m->x)&&(pt->x<(m->x+m->x+m->width))&&(pt->y>m->y)&&(pt->y<(m->y+m->hight)))
{
x=x-m->y;
Msg.data=x/18;
}
return Msg;
}
void drawmenu(menu *m)
{
int i;
if(m==NULL)
return;
setcolor(m->bkcolor);
bar(m->x,m->y,m->x+m->width,m->y+m->itemnum*18+2);
setcolor(m->fcolor);
settextstyle(1,0,1);
for(i=0;i<m->itemnum;i++)
outtextxy((m->x)+10,(m->y)+i*18,(m->text+i*16));
}
void MenuMsgProc(menu *m,int Msg,msg menumsg)
{
int i,j,color;
if(m==NULL)
return;
switch(Msg)
{
case 0:
for(i=m->x+1;i<m->x+100;i++)
for(j=m->y+1+menumsg.data*18;j<m->y+20+menumsg.data*18;j++)
{
color=getpixel(i,j);
if(color!=0&&color!=3)
putpixel(i,j,3);
}
break;
case 1:
for(i=m->x+1;i<m->x+100;i++)
for(j=m->y+1+menumsg.data*18;j<m->y+20+menumsg.data*18;j++)
{
color=getpixel(i,j);
if(color==3&&color!=WHITE)
putpixel(i,j,WHITE);
}
break;
case 3:
getimage(m->x,m->y,m->width,m->hight,Buffer);
break;
putimage(x,y,Buffer,COPY_PUT);
case 4:
break;
}
}
void MessageBox(win Box,char *text)
{
int i,j,color;
setcolor(RED);
line(Box.x-1,Box.y-1,Box.x+Box.width,Box.y+Box.hight);
line(Box.x-2,Box.y-2,Box.x+Box.width,Box.y+Box.hight);
bar(Box.x,Box.y,Box.x+Box.width,Box.y+Box.hight);
for(i=Box.x+1;i<Box.x+Box.width;i++)
for(j=Box.y+1;j<Box.y+20;j++)
{
color=getpixel(i,j);
if(color!=BLACK)
putpixel(i,j,3);
}
setcolor(BLACK);
outtextxy(Box.x+5,Box.y,"MessageBox");
outtextxy(Box.x+50,Box.y+70,text);
for(i=Box.x+100;i<Box.x+170;i++)
for(j=Box.y+100;j<Box.y+120;j++)
{
putpixel(i,j,2);
}
outtextxy(Box.x+120,Box.y+100,"OK");
}
void Init()
{
int gm=VGA,gd=VGAHI,i;
initgraph(&gm,&gd,"");
MouseReset();
Buffer=malloc(100*200);
if(Buffer==NULL)
{
printf("Error");
exit();
}
message[9].next=NULL;
for(i=0;i<9;i++)
message[i]=message[i+1];
}
main()
{
int mx,my,ox,oy,n=2,menuitem=100,mousestatus;
msg newMsg,oldMsg;
win MsgBox={180,150,300,150};
menu tmenu={100,100,100,200,BLACK,BLACK,6,NULL,MenuMsgProc},*disp=NULL;
char menutext[][16]={"New","Clean","Save","Save as","Exit"};
tmenu.text=menutext;
Init();
setbkcolor(BLUE);
MouseGetXY(&ox,&oy);
MouseSave(Cursor,ox,oy);
while(1)
{
MouseGetXY(&mx,&my);
pt.x=mx;
pt.y=my;
if(mx!=ox||my!=oy)
{
MouseOff(Cursor,ox,oy);
newMsg=TranslateMsg(&tmenu,&pt);
if(newMsg.data!=oldMsg.data)
{
(*tmenu.proc)(&tmenu,1,oldMsg);
(*tmenu.proc)(&tmenu,0,newMsg);
oldMsg.data=newMsg.data;
}
MouseSave(Cursor,mx,my);
MouseOn(mx,my);
ox=mx;oy=my;
}
if(newMsg.data==4&&LeftPress()!=0)
exit();
if(newMsg.data==1&&LeftPress()!=0)
{
cleardevice();
MouseSave(Cursor,mx,my);
MouseOn(mx,my);
}
if(RightPress()!=0)
{
tmenu.x=mx;
tmenu.y=my;
cleardevice();
drawmenu(&tmenu);
MouseSave(Cursor,mx,my);
MouseOn(mx,my);
}
if(newMsg.data!=4&&newMsg.data!=1&&LeftPress()!=0)
{
cleardevice();
MessageBox(MsgBox,menutext[newMsg.data]);
getch();
cleardevice();
MouseSave(Cursor,mx,my);
MouseOn(mx,my);
}
}
}
fiftymetre
2005-12-02
打赏
举报
回复
这个...等高手了
TC
实现
鼠标
模拟人工移动.rar
tc
实现
鼠标
模拟人工移动,人工
操作
鼠标
移动时会产生轨迹,切
鼠标
移动轨迹由-直线-上曲线-下曲线组成,每次移动距离不同速度不同,靠近目标点会减速移动,360度无死角,此源码做到了以上几点。有需要的粉丝欢迎下载学习,仅供技术 交流,禁止商用,违规
操作
引发的事宜,均与本人无关。
TC
2.0下
实现
鼠标
操作
的模块
TC
2.0下
实现
鼠标
操作
的模块
TC
2.0下
实现
鼠标
操作
的模块
TC
鼠标
5种移动代码
TC
鼠标
5种移动代码
tc
2.0 支持
鼠标
程序
在
tc
2.0 环境
中
支持
鼠标
程序. 方便在图形界面时的使用
扫雷(
鼠标
键盘均可
操作
、
TC
)
扫雷(
鼠标
键盘均可
操作
、
TC
),功能基本同windows
中
的扫雷游戏
C语言
70,020
社区成员
243,264
社区内容
发帖
与我相关
我的任务
C语言
C语言相关问题讨论
复制链接
扫一扫
分享
社区描述
C语言相关问题讨论
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章