Add to Favorites    Make Home Page 3013 Online  
 Language Categories  
 Our Services  

Home » C Home » Games and Graphics Home » Library File for Mouse Activation & Usage

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title Library File for Mouse Activation & Usage
Author Atul Prakash
Author Email varta [at] indiatimes.com
Description Here is a library of functions,KEYMOUSE.C, for MOUSE activation and usage.A simple but powerful programme DEMO.C also is included To show the use of the given Library File : KEYMOUSE.C, to some extent!
The rest remains waiting for you to explore further!!
Category C » Games and Graphics
Hits 317636
Code Select and Copy the Code
Note:Two files are being given in this single file.Separate them first of all. Instructions: 1.Copy and patse keymouse.c at c: 2.Copy and paste demo.c at c: or at some other drive 3.Compile and Run demo.c Note: The two files are being typed in a single file and are separated by dashes.Make separate files breaking the two portions of this file and name them as suggested.Now they are ready for use. ------------------------------------------------------------- ------------------------------------------------------------- ------------------------------------------------------------- /*The first file :keymouse.c*/ /*Header File for keyboard and mouse*/ /*-header files------------------------------*/ #include<dos.h> /*-variables---------------------------------*/ union REGS i,o; /*-function(1)-------------------------------*/ /*it waits for keyhit & gives the ascii-scan codes of the keyhit*/ readKey(int *ascii, int *scan) { i.h.ah=0x00; int86(0x16,&i,&o); *scan=o.h.ah; *ascii=o.h.al; }/*End of readKey()*/ /*-function(2)-------------------------------*/ /*what does it do exaxtly ?:*/ watchKey(int *ascii, int *scan) { i.h.ah=0x01; int86(0x16,&i,&o); *scan=o.h.ah; *ascii=o.h.al; }/*End of watchKey()*/ /*-function(3)-------------------------------*/ /*resets mouse and gets status*/ /*if successful returns zero*/ initMouse() { i.x.ax=0; int86(0x33,&i,&o); return(o.x.ax); }/*End of initMouse()*/ /*-function(4)-------------------------------*/ /*shows mouse pointer*/ showMouse() { i.x.ax=1; int86(0x33,&i,&o); }/*End of showMouse()*/ /*-function(5)-------------------------------*/ /*hides mouse pointer*/ hideMouse() { i.x.ax=2; int86(0x33,&i,&o); }/*End of hideMouse()*/ /*-function(6)-------------------------------*/ /*gets mouse position and button status*/ /* value of *button meaning 0 left button pressed 1 right button pressed 2 centre button pressed */ getMousePos(int *button,int *x,int *y) { i.x.ax=3; int86(0x33,&i,&o); *button=o.x.bx; *x=o.x.cx; *y=o.x.dx; }/*End of getMousePos()*/ /*-function(7)-------------------------------*/ /*sets mouse position */ setMousePos(int x,int y) { i.x.ax=4; i.x.cx=x; i.x.dx=y; int86(0x33,&i,&o); }/*End of setMousePos()*/ /*-function(8)-------------------------------*/ /*sets horizontal limits for pointer*/ setMouseHoriz(int minX,int maxX) { i.x.ax=7; i.x.cx=minX; i.x.dx=maxX; }/*End of setMouseHoriz()*/ /*-function(9)-------------------------------*/ /*sets vertical limits for pointer*/ setMouseVert(int minY,int maxY) { i.x.ax=8; i.x.cx=minY; i.x.dx=maxY; }/*End of setMouseVert()*/ /*-function(10)------------------------------*/ /*restricts mouse pointer within the rectangular range*/ restrictMouse(int left,int top,int right,int bottom) { setMouseHoriz(left,right); setMouseVert(top,bottom); }/*End of restrictMouse()*/ /*-function(11)------------------------------*/ /* It returns 1 if the mouse cursor is within the given range. Otherwise it returns 0. It also returns *button, that is the button of mouse pressed. */ isMouseIn(int left,int top,int right,int bottom,int *button) { int x,y; getMousePos(button,&x,&y); if(x>=left && x<=right && y>=top && y<=bottom) return(1); else return(0); }/*End of isMouseIn()*/  ------------------------------------------------------------- ------------------------------------------------------------- ------------------------------------------------------------- /*The second file:demo.c*/ /*Demonstration of Mouse*/ #include<c:keymouse.c> #include<graphics.h> #include<alloc.h> main() { int x,y,click,test,test1,toggleC=0,togS=0,TOGS=1,togB=0,toggleCC=0,TOGB=1; int togF=0,TOGF=1,area,togBuff=0,togM=0,togR=0,TOGR=0,togRR=0; int togMM=0,togMMM=0,prevx,prevy,jerk=0,togFLG=0; int rpopx,rpopy; char *buff,*buff1; int gd=DETECT,gm; initgraph(&gd,&gm,"c:\tc\bgi"); cleardevice(); /*------------------------------------------*/ /*background window*/ setfillstyle(1,3); bar(0,0,getmaxx(),getmaxy()); /*------------------------------------------*/ /*foreground window*/ setfillstyle(1,7); bar3d(10,10,getmaxx()-10,getmaxy()-10,0,0); setcolor(14); /*------------------------------------------*/ /*title bar*/ setcolor(14); setfillstyle(1,1); bar3d(12,12,getmaxx()-12,32,0,0); outtextxy(22,18,"Mouse Illustration"); setcolor(14); setfillstyle(1,1); bar3d(getmaxx()-32,15,getmaxx()-15,29,0,0); setcolor(14); outtextxy(getmaxx()-26,19,"X"); /*------------------------------------------*/ /*file menu*/ setfillstyle(1,9); setcolor(14); bar3d(14,34,70,50,0,0); outtextxy(26,38,"file"); /*------------------------------------------*/ /*check box*/ setcolor(0); setfillstyle(1,15); bar3d(52,112,62,122,0,0); setcolor(15); line(62,112,62,122); line(52,122,62,122); /*------------------------------------------*/ /*button*/ setcolor(0); setfillstyle(1,7); bar3d(52,132,120,152,0,0); setcolor(15); line(52,132,52,152); line(52,132,120,132); setcolor(0); outtextxy(60,137,"intro"); /*------------------------------------------*/ /*mouse activation*/ initMouse(); setMousePos(50,50); showMouse(); /*------------------------------------------*/ /*Demo of mouse*/ while(1) { /*-reading mouse----------------------------*/ getMousePos(&click,&x,&y); /*-determining if the mouse is moved--------*/ if(prevx!=x || prevy!=y) { jerk=1; } else jerk=0; /*-storing the laest mouse position---------*/ prevx=x; prevy=y; /*------------------------------------------*/ /*-the cross button of the title bar--------*/ test=isInRange(x,y,getmaxx()-32,15,getmaxx()-15,29); if(test==1 && click==1) break; /*-file menu--------------------------------*/ test=isInRange(x,y,14,34,70,50); if(test==1 && click==1 && TOGF==1) { hideMouse(); setcolor(9); outtextxy(26,38,"file"); setcolor(14); outtextxy(25,37,"file"); setcolor(7); rectangle(14,34,70,50); /*washing the right click popup*/ if(togR==1) { putimage(rpopx,rpopy,buff1,COPY_PUT); free(buff1); togR=0; } /*drop down menu*/ if(togM==0) { if(togBuff==0) { area=imagesize(14,52,130,220); buff=malloc(area); getimage(14,52,130,220,buff); togBuff=1; } setcolor(14); setfillstyle(1,9); bar3d(14,52,130,220,0,0); setcolor(14); outtextxy(20,62,"Author"); outtextxy(20,82,"Exit"); togM=1; } else /* togM==1*/ { putimage(14,52,buff,COPY_PUT); free(buff); togBuff=0; togM=0; } showMouse(); togF=1; TOGF=0; } if(togM==1) { test=isInRange(x,y,17,60,124,72); if(test==1 && togMM==0) { hideMouse(); setcolor(9); rectangle(17,80,124,92); setcolor(14); rectangle(17,60,124,72); showMouse(); togMM=1; } test=isInRange(x,y,17,80,124,92); if(test==1 && togMM==0) { hideMouse(); setcolor(9); rectangle(17,60,124,72); setcolor(14); rectangle(17,80,124,92); showMouse(); togMM=1; } if(jerk==1) togMM=0; } test=isInRange(x,y,14,52,130,220); if(test==1 && click==1 && togM==1) { hideMouse(); putimage(14,52,buff,COPY_PUT); free(buff); showMouse(); togM=0; togBuff=0; } if(click==0 && togF==1) { hideMouse(); if(togBuff==1) { test=isInRange(x,y,14,52,130,220); test1=isInRange(x,y,14,34,70,50); if(test!=1 && test1!=1) { putimage(14,52,buff,COPY_PUT); free(buff); togBuff=0; togM=0; } } setcolor(9); outtextxy(25,37,"file"); setcolor(14); outtextxy(26,38,"file"); setcolor(14); rectangle(14,34,70,50); showMouse(); togF=0; TOGF=1; } if(click==1 && togBuff==1) { hideMouse(); test=isInRange(x,y,14,52,130,220); test1=isInRange(x,y,14,34,70,50); if(test!=1 && test1!=1) { putimage(14,52,buff,COPY_PUT); free(buff); togBuff=0; togM=0; } showMouse(); } if(click==2 && togBuff==1) { hideMouse(); putimage(14,52,buff,COPY_PUT); free(buff); togBuff=0; togM=0; showMouse(); } /*-right click popup--------------------------------*/ if(click==2 && togR==0) { hideMouse(); if(x<20) x=20; if(y<52) y=52; if(x+100>getmaxx()-20) x=(getmaxx()-20)-100; if(y+100>getmaxy()-20) y=(getmaxy()-20)-100; setMousePos(x,y); hideMouse(); area=imagesize(x,y,x+100,y+100); buff1=malloc(area); getimage(x,y,x+100,y+100,buff1); setfillstyle(1,9); setcolor(14); bar3d(x,y,x+100,y+100,0,0); showMouse(); outtextxy(x+20,y+10,"About"); outtextxy(x+20,y+30,"Exit"); showMouse(); rpopx=x; rpopy=y; togR=1; } if(togR==1) { test=isInRange(x,y,rpopx+5,rpopy+7,rpopx+95,rpopy+20); if(test==1 && togMMM==0) { hideMouse(); setcolor(9); rectangle(rpopx+5,rpopy+26,rpopx+95,rpopy+40); setcolor(14); rectangle(rpopx+5,rpopy+7,rpopx+95,rpopy+20); showMouse(); togMMM=1; } test=isInRange(x,y,rpopx+5,rpopy+26,rpopx+95,rpopy+40); if(test==1 && togMMM==0) { hideMouse(); setcolor(9); rectangle(rpopx+5,rpopy+7,rpopx+95,rpopy+20); setcolor(14); rectangle(rpopx+5,rpopy+26,rpopx+95,rpopy+40); showMouse(); togMMM=1; } if(jerk==1) togMMM=0; } if(click==1 && togR==1) { hideMouse(); putimage(rpopx,rpopy,buff1,COPY_PUT); free(buff1); test=isInRange(x,y,rpopx+5,rpopy+26,rpopx+95,rpopy+40); if(test==1) break; test=isInRange(x,y,rpopx+5,rpopy+7,rpopx+95,rpopy+20); if(test==1) { setcolor(14); rectangle(45,175,150,415); outtextxy(50,180,"This is a"); outtextxy(50,200,"proramme to"); outtextxy(50,220,"show the"); outtextxy(50,240,"mouse & "); outtextxy(50,260,"window"); outtextxy(50,280,"features."); setfillstyle(1,9); bar3d(70,370,120,390,0,0); outtextxy(85,375,"ok"); } showMouse(); togR=0; } /*-file menu: code of submenus-------------------*/ if(click==1) { hideMouse(); test=isInRange(x,y,17,60,124,72); if(test==1) { setfillstyle(1,7); bar3d(170,60,595,450,0,0); outtextxy(180,70,"Atul Prakash"); outtextxy(180,90,"varta@indiatimes.com"); toggleCC=0; } test=isInRange(x,y,17,80,124,92); if(test==1) { break; } showMouse(); } /*code for "ok" button of the box made by a click at "about" submenu of the right click popup---*/ test=isInRange(x,y,70,370,120,390); if(test==1 && click==1) { hideMouse(); setfillstyle(1,7); bar(45,175,150,415); showMouse(); } /*code for the Comment Flag that popups when the mouse cursor touches the title bar.*/ test=isInRange(x,y,12,12,getmaxx()-12,32); if(test==1 && click==0) { if(togFLG==0) { hideMouse(); setfillstyle(1,9); setcolor(14); bar3d(75,34,620,50,0,0); outtextxy(80,38,"Contact for further discussion: varta@indiatimes.com : Atul Prakash"); showMouse(); togFLG=1; } } else { if(togFLG==1) { hideMouse(); setfillstyle(1,7); setcolor(7); bar3d(75,34,620,50,0,0); showMouse(); togFLG=0; } } /*code segment for right click popup----------*/ if(click==0 && togR==1) { TOGR=1; } if(click==2 && togR==1 && TOGR==1) { hideMouse(); putimage(rpopx,rpopy,buff1,COPY_PUT); free(buff1); showMouse(); togR=0; TOGR=0; } /*-check box----------------------------------*/ test=isInRange(x,y,52,112,62,122); if(test==1 && click==1 && TOGS==1) { hideMouse(); setcolor(toggleC); if(togM==0) outtextxy(54,114,"+"); showMouse(); togS=1; TOGS=0; } if(click==0 && togS==1) { if(toggleC==0) toggleC=15; else toggleC=0; togS=0; TOGS=1; } /*-"intro" button--------------------------------------*/ test=isInRange(x,y,52,132,120,152); if(test==1 && click==1 && TOGB==1) { hideMouse(); if(togM==0) { setcolor(7); outtextxy(60,137,"intro"); setcolor(0); outtextxy(59,136,"intro"); if(toggleCC==7) { setfillstyle(1,toggleCC); bar(170,60,595,450); } else { setcolor(toggleCC); setfillstyle(1,7); bar3d(170,60,595,450,0,0); outtextxy(180,80,"This is a simple programme and its prime intention"); outtextxy(180,94,"is just to give a feel of how a very simple "); outtextxy(180,108,"window application could be developed using mouse."); outtextxy(180,122,"Try your hand to see how different things here "); outtextxy(180,136,"are programmed to interact!"); outtextxy(180,154,"It is basically an illustration of the file"); outtextxy(180,168,"named as keymouse.c"); setcolor(14); outtextxy(180,186,"So the main() function is kept very simple."); outtextxy(180,200,"The essence is, study keymouse.c thoroughly"); outtextxy(180,214,"and then have a look over the main()."); setcolor(14); outtextxy(180,245,"Here are shown: "); setcolor(0); outtextxy(180,265,"1.Drop Down menu"); outtextxy(180,285,"2.Check Box"); outtextxy(180,305,"3.Command Button"); outtextxy(180,325,"4.Right Click PopUp"); outtextxy(180,345,"5.Exit Icon of the Title Bar"); outtextxy(420,265,"6.Comment Flag"); setcolor(6); outtextxy(420,285,"Take the cursor to"); outtextxy(420,305,"the Title Bar to"); outtextxy(420,325,"see it."); setcolor(1); outtextxy(180,380,"A number of wonderful things can be done using such"); outtextxy(180,400,"techniques,..with the help of the keymouse.c file."); } setcolor(0); line(52,132,52,152); line(52,132,120,132); setcolor(15); line(120,132,120,152); line(52,152,120,152); } showMouse(); togB=1; TOGB=0; } if(click==0 && togB==1) { hideMouse(); if(togM==0) { setcolor(7); outtextxy(59,136,"intro"); setcolor(0); outtextxy(60,137,"intro"); setcolor(15); line(52,132,52,152); line(52,132,120,132); setcolor(0); line(120,132,120,152); line(52,152,120,152); } if(toggleCC==0) toggleCC=7; else toggleCC=0; showMouse(); togB=0; TOGB=1; } } /*------------------------------------------*/ closegraph(); restorecrtmode(); } /*This function checks if the coordinates(x,y) are within the range (left,top) ,(right,bottom)*/ isInRange(int x,int y,int left,int top,int right,int bottom) { if(x>=left && x<=right && y>=top && y<=bottom) return(1); else return(0); }

Related Source Codes

Script Name Author
The Game Opposite as seen on Nokia 2300 Mobile Manikanta
RECURSIVE BALANCED QUICK SORT ashish
Radix Sort ashish
Change your mouse pointer Ashim
The blinking star Shashank
Data Validation Crylittlebaby
To search a file by giving file type like mp3 or mpeg or doc Prashanth SR
Menus Demonstration B.Chidhambaram
Employee Database Project Using C. Reenku Raman Nayak
Creating a Lexical Analyzer in c fahad bader al-buhairi դ ? ??
Calendar Program Omkar & Devendra
Stop double Process for start in C Cedrik Jurak
Stop double Process for start in C Cedrik Jurak
Time Scheduler Atiq Anwar
A timepass game between atmost two players Rahul Roy

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2022 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=957


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review