#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include<dos.h>
#include<math.h>
union REGS in,out;

void hide_mouse();
void show_mouse();
void detect_mouse();
void detect(int*,int*,int*);

void main(void)
{

   int gdriver = DETECT, gmode, errorcode;
   int xmax, ymax;


   initgraph(&gdriver, &gmode, "");


   errorcode = graphresult();

   if (errorcode != grOk)
   {
      printf("Graphics error: %s\n", grapherrormsg(errorcode));
      printf("Press any key to halt:");
      getch();
      exit(1);
   }
   int x1,y1,button=1,t=0;
   setcolor(getmaxcolor());
   detect_mouse();
   show_mouse();
  // detect(&x1,&y1,&button);
   while(!kbhit())
   {
	while(button==1)
	{
		detect(&x1,&y1,&button);
		printf("%d %d",x1,y1);
		putpixel(x1,y1,15);
	}


   }
   getch();
}

void detect_mouse()
{
     in.x.ax=0;
     int86(0X33,&in,&out);
     if(out.x.ax==0)
     printf("not initialized!!");
     else
     printf("initialized!!");

}


void show_mouse()
{
	in.x.ax=1;
	int86(0X33,&in,&out);
	getch();

}

void hide_mouse()
{
    in.x.ax=2;
    int86(0X33,&in,&out);
}

void detect(int*x,int*y,int *button)
{
	in.x.ax=3;
	int86(0X33,&in,&out);
	*x=out.x.cx;
	*y=out.x.dx;
	*button=(out.x.bx)&1;
}

in this code, there is no compilation error.but when i click on the screen, it is not putting the pixel on it. BUT it is terminating properly. :'( have gave time to it but not getting what the problem is!! in this code, i am printing pixel at that co-ordinate on which i am clicking(MY AIM).

Edited 4 Years Ago by gourav1: n/a

graphics.h is certainly a problem, why do you use a graphics library from two decades ago?

because my teacher in university want us to work on this. you can talk to him if u want for this.

you can talk to him if u want for this.

Invite him to Daniweb and I'll be happy to tear him a new one.

Invite him to Daniweb and I'll be happy to tear him a new one.

lol. okies. jokes apart. please tell the solution please

Gourav1, you are now my new favorite poster. You give us problems from 15 years ago. To check and debug your code, we'd need DOSBox and an ancient (and completely legitimately obtained) copy of Turbo C++ 4.5. Epic win.

http://www.go4expert.com/forums/showthread.php?t=21153

Have a look at this page. Run all the examples. And see what works.
I'm wondering if perhaps your mouse coordinates are outside the drawing range of the screen. Who knows?

I think you're going to have to wait for someone from India to join the board that can help since it seems only India teaches with outdated equipment and tools. The rest of the world left Turbo-C over 10 years ago.

And Narue wasn't joking... :icon_wink:

Edited 4 Years Ago by WaltP: n/a

Look at this function from the site I mentioned earlier. I did some debugging and the mouse coordinates start way out in never never land even though the cursor is clearly visible on the screen. Restrict the mouse coordinates to the display min and max and you're good. Look into getmaxx() and getmaxy() on getting those.

void restrict (int x1,int y1,int x2, int y2)
{
	in.x.ax = 7;
	in.x.cx = x1;
	in.x.dx = x2;
	int86 (0X33,&in,&out);
	in.x.ax = 8;
	in.x.cx = y1;
	in.x.dx = y2;
	int86 (0X33,&in,&out);
}
This question has already been answered. Start a new discussion instead.