View Full Version : Mouse

01-29-2003, 02:20 AM
I have created some buttons and now I want to link tehm with a function. When I click a botton at this coordinates x=120 to x= 200, y=85 to =95 i want that the programm ends

01-29-2003, 07:03 AM
Is this DOS or windows? And, try http://msdn.microsoft.com and look up the mouse functions. basically what you're going for here is a loop inside your main (or a seperate function) that will keep on looping until that area is clicked. Then the program can return 0.

01-29-2003, 08:05 AM
It is Dos 0x0013

01-29-2003, 09:39 PM
so im assuming the hex is an address of the hardware int for the mouse? so, basically work with something like this:

int * mouseClick;
&mouseClick=0x0013;//address of mouseClick
int returnClick=??;//whatever the mouseClick address will hold when the mouse has been clicked

while (*mouseClick!=returnClick)
return 0;

im not guaranteeing that is bug free, but that's the general idea

01-30-2003, 04:31 AM
If the problem simply is to shut down your program from a function or procedure,
there's a function for that.
I think it's called, exit();
And you type: exit(1); to exit your program, I don't remember what header you have to use for this one, but that shouldn't be to hard to figure out!

01-30-2003, 04:52 AM
I've did it on my own take a lot of time and my source code is now not to understand but it works and this is what i want. exit(1); is in stdlib.h

01-30-2003, 07:25 AM
The theory is simply enough.

When your mouse button is released(!) check whether you're in the given area (x0=120 x1= 200 y0=85 y1=95).

Warning: axis origin is on the top-left corner of the screen (y-axis increases downwards!).

Given your mouse coordinates (mouse_x, mouse_y), check for worst case (pseudo_code)

if mouse_x < x0 return;
if mouse_x > x1 return;
if mouse_y < y0 return;
if mouse_y > y1 return;
do_exit (quit the main program loop and exit)

my source code is now not to understand but it works and this is what i want
That's not the best way, don't you think? :)

Code clean and live long!

01-30-2003, 07:35 AM
I rewrite it so that I understand it.

I know that a not clean code will me my death.

01-30-2003, 07:49 AM
Good idea! :)

Is it Assembly you're coding?
Take a look at my HP, you might find some ideas and sources.
For this case (mouse handling under DOS using BIOS ints in ASM) check this one:AsmMenu (http://www.nexus.hu/n_kari//progsEng.htm#asmmenu)

01-30-2003, 10:08 AM
That was a cool solution, to se if the user has cklicked on the button, of should I say hasn't clicked it!
Haven't seen it before! :-)

But just one thing, if you want to have more then 1 button, how do you do then, with your method?

I would rather advice:
(Or terminate the program in some way)

01-30-2003, 10:14 AM
Oups, looked at your code again, I'm an idiot I admit it! :-)

I don't know how I thougt, but something got a little wrong in my head for a minute there, as I said sorry!

01-30-2003, 10:16 AM
When I said you should rather check whether the user has released the mouse button I meant "released after click" -> that's the way windows does, too.

Just check it out, press the mouse while over a menu or button, then move your mouse outside that area, and release it - nothing happens! And this behaviour is all right, as the user might change his mind (they do it all the time, that's why we get end-user complains). :)

But just one thing, if you want to have more then 1 button, how do you do then, with your method?

For every button you set up a check function.

The possibility that the mouse cursor is inside a button region is probably less then being somewhere else on the UI - except the case your interface is full with buttons, but this should not be the case :D

It's better to check the way I presented, from performance side and coding as well. Performance is higher, as not all bounds are checked -> when the mouse coord is outside the rectangle the function returns without performing the remaining checks.

Please check my link for a functional example.

Oh, I've just seen your next reply :)
Nevermind, we are ok then, isn't it?

01-30-2003, 10:58 AM
Yea, sure!
Didn't think about that your way is faster, I'm not programming ASM you know! :-)
I will deffinately use your way the next time, I write something like this! ;-)

01-31-2003, 03:26 AM
Didn't think about that your way is faster, I'm not programming ASM you know! :-)

Optimizing for speed is not a matter of programming language, it is "allowed" even in C++ :D.

You would probably be very happy if your OS would load in 2 seconds instead of 20, isn't it?
We make faster and faster hardware, and ... bigger and slower software. Hope this trend will change in the future.

I'd like some projects like this one:

Check it out, it's COOOOOL!!!!!!

01-31-2003, 04:44 AM
Yea, that seams to be a cool thing, I can't say that I fully get how it works etc. But it seams to be cool anyway!
But it seams to be a kind of a dangerous application, I mean in the documentation, every second line, they write something like:

However Menuet CAN access the hard drive (not by default) and can do serious damage if improperly used (and even when properly used)

But it seams to be cool anyway, if I can get my old P120, working, perhaps I should try it!