Mouse Class in C++
hi all there.
i have written a class to implement the features of mouse IN C++.
it is pretty much what u get to use in VC++.
in VC++
u get mouse events like LBUTTON_UP etc.
however in my class i m not returning specific button events.
rather i m returning the whole absolute status of the mouse buttons.
for eg.
the events will be..
MOUSE_LURUMU
i.e. Left Up right Up middle Up
etc.
i have no problem upto here.
in fact my class runs perfectly in all the cases...well almost.
but i m having a small problem in implementing this class.
suppose i m using this class in some project and there
i m doing some activity on MOUSE_LURDMU
and something else on MOUSE_LURUMD
this much is happening.
but suppose i want to exit on MOUSE_LDRUMU.
then even though i m exiting i the firts case.
but when i m running thee program again,
i m immediately exiting.
this is to say that the previous event is still being returned instead of a fresh event.
i have printed these events on the screen and i m sure bout what is happening.
however i DO NOT KNOW why i m getting this
old event when i have exited from the previous program.
it is surely not a case f not freeing up memory cos i did not allocated any.
the dtor has no work here to do and i m not using one here.
one thing more.
this problem happens only within the Turbo C++ IDE.
the standalone EXE works fine...everytime.
can anybody tell me what might be the reason that i m getting the old previous event instead of a fresh event since i m anyway invoking the event returning method.
help me.
:o :o :o
[1819 byte] By [
King] at [2007-11-18 17:45:48]

# 1 Re: Mouse Class in C++
Are you sure this happens only when you start your application in Turbo C++ IDE debugger?
If this is the case, it may be due to Turbo C++ IDE and you can safely ignore it.
ferox at 2007-11-9 0:30:52 >

# 2 Re: Mouse Class in C++
King,
It seems that you are not clearing the mouse states at the beggining of the program, and at the constroction you need to do a initial check.
Besides that, I havent seen your code but it seems that your class suffer of a design mistake.
Why you need to know the whole absolute status of the mouse buttons? normally you need to know WHEN a button change occurs.
As far I got, you are getting the mouse state at your wish. It is not a good idea for event oriented programming, because youll have to check all mouse states when you need to know the mouse state.
The action must be taken on the event happening, not soon or later. If is it, you better change you class to take the action on the mouse event instant, not when you wish. It will be more clear and easy to manipulate.
regards
Rabelo
# 3 Re: Mouse Class in C++
thanks rebalo for ur answer.
it was high time somebody came up with an answer that was honest and not heart breaking.
i earlier got some answers but most of them were just useless that offered nothing concrete.
some of them criticised me for my typing style !!!.
maybe u r right when u pointed out my basic error in the class design.
what u say is right that i should perform an activity when it's event occurs and not when i test for that event.
but plz give me some hint as to how to do this in turboc++ ide?
i know this could be done in vc++ but how in tc++?
secondly ...
u have said that i m not clearing up the events initially n i should check it out at the time of construction.
but i m always initializing the mouse event variable MOUSE_EVENT STATUS to MOUSE_LURUMU i.e to the default state of all buttons up.
let me restate the problem.
initially in the constructor , i do this ...
MOUSE_EVENT_STATUS=MOUSE_LURUMU;
then suppose i decided to change the drawing color at MOUSE_LURDMU (Right CLick)
then in the main()
i trapped the mouse events in a switch case
with a total of 7 cases.
at case MOUSE_LURDMU i do setcolor(YELLOW) (say)
then suppose i wanted to exit at MOUSE_LDRUMU
then at case MOUSE_LDRUMU i clear up ne memory i allocated and i do an exit(0);
i hope this is fine and not erroneous
exit(0) denotes successful termination of program.
so at MOUSE_LDRUMU the program ends with no memory leaks.
the trouble starts now...
the next time when i run this program
naturally the MOUSE_EVENT_STATUS variable should be again initialized to MOUSE_LURUMU
and so the program should run again.
but surprisingly the variable comes back with it's old value
(the one with which it exited)
and so the program terminates in the first iteration itself cos the exiting condition is satisfied.
i have no explanation for this
moreover this strange thing happens only when i m running the program frm within the ide
when i make the exe of the project and run it al alone it works fine.
but why does this thing occur from within the ide?
i hope my problem is clear.
kindly help rebalo
and of course thanks for ur relply which was really constructive and helpful.
bye.
King at 2007-11-9 0:32:58 >

# 4 Re: Mouse Class in C++
King
This behavior is kind a initialization problem. When reinitializing the program, often the new call falls on the old memory adress and the memory variable values dont change.
also, Have you traced MOUSE_EVENT_STATUS?. If no try, to check if after initialization something is changing MOUSE_EVENT_STATUS.
Trace it, Ive made on TC, not TC++ a program to get the mouse status. On that time there was not event oriented programming
and the aproach was exately like yours: on a while get the mouse status and if it is not like the previous an action must be taken.
I dont know if TC++ has some event oriented functions for mouse handling. If so, youll need to learn how to use it, if not, youll have to do as youre doing. But certainly, there is a bug that you need to catch.
I develop a driver for mouse handling in TC (not C++) and it work fine on DOS programs. All states are getting by calls to DOS interruption routines. If you wish I can sent it to you.
Good Luck,
Rabelo
# 5 Re: Mouse Class in C++
hi rebalo,
i m truly delighted that u have helped me in getting my problem solved.
i feel i m now nearer to to base of the problem.
i will begin the tracing process later but if u could send me that utilit of urs in tc for mouse handling the it would be great news for me.
however i m sure that the only 2 places where MOUSE_EVENT_STATUS gets changed is :
1. inside constructor
2. inside the while loop at only 1 place.
apart from these 2 there r no other assignmenst to this variable.
so there is no question of it being unknowingly changed.
neway,
thnz for ur answer.
King at 2007-11-9 0:34:57 >

# 6 Re: Mouse Class in C++
King,
Another things can be changing the value of MOUSE_EVENT_STATUS: A non initialized pointer can be changing its value when you use this pointer. Or, a overflow on a char[] or a buffer close of it can also be changing its value. Note that this can happen elsewhere on the program. So there is only one way : trace step by step. Dont trace only the line close of MOUSE_EVENT_STATUS , trace all lines since the beginning, watching its value line by line. Another important and basic issue is which operational system will you class run on? Windows is a event oriented S.O. so its easy to aply on it event oriented programming, because the events come on rigth time for you, but DOS isnt, so youll have to simulate this behavior inside your program, a litle harder, but quite possible,
I havent the driver handy now and Ill send it for you tomorow.
Regards,
Rabelo
# 7 Re: Mouse Class in C++
Attached is the mouse buffer. I Also atached a tex file with pieces of code I used with the driver.
Regards,
Rabelo