#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    36
    Rep Power
    13

    Problem Running Example..


    Hi,

    I was over at pscode.com and ran across an example for Mouse Programming. I tried running the example but I was getting a bunch of errors such as..

    c:\Documents and Settings\default\My Documents\Visual Studio Projects\mouse\mouse.cpp(33): error C2065: '_AX' : undeclared identifier

    c:\Documents and Settings\default\My Documents\Visual Studio Projects\mouse\mouse.cpp(34): error C2065: 'geninterrupt' : undeclared identifier

    c:\Documents and Settings\default\My Documents\Visual Studio Projects\mouse\mouse.cpp(58): error C2065: '_CX' : undeclared identifier

    Here is the code for the example:

    Code:
    //The Compiler used is Turbo C, I dont know if it will compile in others also.
    //Didn't Compile in Microsoft C Compiler. Make the respective change then.
    //The function geninterrupt() generates interrupts, it is defined in dos.h
    //_AX,_BX,_CX,_DX are defined in dos.h & correspond to ax,bx,cx,dx registers respectively.
    //Make a header file out of this one and use it in your programs.
    #include<dos.h>//this header file is necessary
    #include<stdio.h>//only for displaying messages
    #include<conio.h>//for other stuff like getch() etc.
    unsigned initmouse()
    {
    	_AX=0;
    	geninterrupt(0x33);	//Generate Inpterrupt
    	return _AX;
    }
    
    void showmouse()
    {
    	_AX=1;
    	geninterrupt(0x33);
    }
    
    void hidemouse()
    {
    	_AX=2;
    	geninterrupt(0x33);
    }
    
    void restrictmouse(int x1,int y1,int x2,int y2)
    {
    	_AX=7;
    	_CX=x1;
    	_DX=x2;
    	geninterrupt(0x33);
    	_AX=8;
    	_CX=y1;
    	_DX=y2;
    	geninterrupt(0x33);
    }
    
    void getmouse(int *button,int *x,int *y)
    {
    	_AX=3;
    	geninterrupt(0x33);
    	*button=_BX;
    	*x=_CX;
    	*y=_DX;
    }
    
    void setmouse(int x,int y)
    {
    	_AX=4;
    	_CX=x;
    	_DX=y;
    	geninterrupt(0x33);
    }
    
    void main()
    {
    	int x,y,button;
    	clrscr();
    	gotoxy(29,18);
    	textbackground(GREEN);
    	cprintf("EXIT");
    	gotoxy(1,1);
    	if(initmouse()==0)
    	{
    		printf("Mouse support unavailable");
    		return;
    	}
    	printf("\n\nPress any key to Show Mouse");
    	getch();
    	showmouse();
    	printf("\nPress any key to Hide Mouse");
    	getch();
    	hidemouse();
    	printf("\nPress any key to Show Mouse again");
    	getch();
    	restrictmouse(208,80,416,160);
    	showmouse();
    	printf("\nMouse has been restricted");
    	printf("\nPress on Exit button to quit the Program");
    	while(1)
    	{
    		getmouse(&button,&x,&y);
    		gotoxy(35,1);
    		printf("Coordinates:-(%d,%d)  ",x,y);
    		gotoxy(35,2);
    		if(button&1)//<- Here '&' means ANDing, remember bitwise operators of C/C++
    			printf("Left button pressed  ");
    		else if(button&2)
    			printf("Right button pressed ");
    		else if(button&4)
    			printf("Center button pressed");
    		else
    			printf("No button Pressed    ");
    		if(x>=224&&x<=248&&y==136&&button==1)//checks if exit button is pressed or not
    			break;
    	}
    }
    As you can see in the comments, it says "_AX,_BX,_CX,_DX are defined in dos.h & correspond to ax,bx,cx,dx registers respectively." dos.h is included in this example, so does anyone know why I am getting these errors?

    Thanks.

    -0pt!x
  2. #2
  3. No Profile Picture
    Offensive Member
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Location
    in the perfect world
    Posts
    622
    Rep Power
    28
    You could always OPEN dos.h and SEE if they are defined. (highlight the text 'dos.h' RIGHT click and select 'open document "dos.h" ' from the pop-up menu in MS Visual Studio (i know it is in from ver 5)



    And then find they are not in dos.h.

    "//The Compiler used is Turbo C, I dont know if it will compile in others also.
    //Didn't Compile in Microsoft C Compiler."
    The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

    Frank Zappa
  4. #3
  5. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
    Even though dos.h was included with the code, I don't think you are calling that file that.
    by using: #include<dos.h>
    you are including the dos.h file from your compiler's include path. If you want to use a different dos.h file then the one that is in the include path, then give the complete path to it. i.e.
    #include "drive:/path/to/dos.h"
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    36
    Rep Power
    13
    Well I want to use the dos.h that came with my compiler. I looked in the header and it didnt define the _AX and stuff.. But .. :confused: I am confused because it says that it is sposed to be defined in my dos.h. Is my dos.h screwed up or something?
  8. #5
  9. /(bb|[^b]{2})/

    Join Date
    Nov 2001
    Location
    Somewhere in the great unknown
    Posts
    5,163
    Rep Power
    792
  10. #6
  11. No Profile Picture
    Offensive Member
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Location
    in the perfect world
    Posts
    622
    Rep Power
    28
    >>Is my dos.h screwed up or something?

    No. It is a just a difference between compliers.

    as the code stated and I pointed out

    "//The Compiler used is Turbo C, I dont know if it will compile in others also.
    //Didn't Compile in Microsoft C Compiler."

    Is that not clear enough for you?

    You are obviously using a Microsoft Compiler, a version of MSVC

    "c:\Documents and Settings\default\My Documents\Visual Studio Projects\"



    What did you want to do with the mouse?
    The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

    Frank Zappa
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    36
    Rep Power
    13
    I know i was using a diff compiler but shouldnt the header files be the same?

    >>What did you want to do with the mouse?

    I wanted to make a prog that would click the mouse every 1 second untill i closed my prog. Like..

    int main()
    {
    while(1)
    {
    click;
    sleep(1000);
    }
    }

    somethin like that.
  14. #8
  15. No Profile Picture
    Offensive Member
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2002
    Location
    in the perfect world
    Posts
    622
    Rep Power
    28
    >>I know i was using a diff compiler but shouldnt the header files be the same?

    No.


    A good coder comments his work and its limitations. This coder did, bad coders ignore instructions and commented code.
    In the comments the coder TOLD you it would not compile in MSVC, he could not have been plainer. You have MSVC.

    Did you not READ that line or did you not UNDERSTAND that line? (the bold one above)

    If in doubt RTFM!

    Ahhh
    Some app that pretends you are still there surfing away.


    If they had any sense when they wrote it they will have locked out external use of SendMessage() like functions.

    If you can't read simple code comments then a WIN32 API app that sends mouse click messages to another application is most definately beyond the scope of your abilites.

    You most probably need to send mouse messages thru windows to the other app as you will not know the client co-ordinates that the ckick happens at. That is WHERE the mouse is clicked ( in the other apps client coodinates).
    Try a search for mouse_event(), which has been superceded by SendInput () ect. See what it turns up.
    The essence of Christianity is told us in the Garden of Eden history. The fruit that was forbidden was on the Tree of Knowledge. The subtext is, All the suffering you have is because you wanted to find out what was going on. You could be in the Garden of Eden if you had just kept your f***ing mouth shut and hadn't asked any questions.

    Frank Zappa

IMN logo majestic logo threadwatch logo seochat tools logo