954,492 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

graphics.h problem

#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).

gourav1
Posting Whiz in Training
203 posts since Oct 2011
Reputation Points: -2
Solved Threads: 2
 

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

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 
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.

gourav1
Posting Whiz in Training
203 posts since Oct 2011
Reputation Points: -2
Solved Threads: 2
 
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.

Narue
Bad Cop
Administrator
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
 
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
Posting Whiz in Training
203 posts since Oct 2011
Reputation Points: -2
Solved Threads: 2
 

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?

DeanMSands3
Junior Poster
185 posts since Jan 2012
Reputation Points: 37
Solved Threads: 26
 

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:

WaltP
Posting Sage w/ dash of thyme
Moderator
10,505 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

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);
}
DeanMSands3
Junior Poster
185 posts since Jan 2012
Reputation Points: 37
Solved Threads: 26
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You