Thread: Mouse

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    24

    Mouse

    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

  2. #2
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    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.
    PHP and XML
    Let's talk about SAX

  3. #3
    Registered User
    Join Date
    Sep 2002
    Posts
    24
    It is Dos 0x0013

  4. #4
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    so im assuming the hex is an address of the hardware int for the mouse? so, basically work with something like this:
    Code:
    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
    PHP and XML
    Let's talk about SAX

  5. #5
    Registered User FearOfTheDark's Avatar
    Join Date
    Jan 2003
    Posts
    31

    exit(1)

    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!
    -We're living in a illusion!
    -Ok, if that's what you think!

  6. #6
    Registered User
    Join Date
    Sep 2002
    Posts
    24
    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

  7. #7
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    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;
    else
    if mouse_x > x1 return;
    else
    if mouse_y < y0 return;
    else
    if mouse_y > y1 return;
    else
    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!
    Last edited by Carlos; 01-30-2003 at 07:52 AM.

  8. #8
    Registered User
    Join Date
    Sep 2002
    Posts
    24
    I rewrite it so that I understand it.

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

  9. #9
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    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

  10. #10
    Registered User FearOfTheDark's Avatar
    Join Date
    Jan 2003
    Posts
    31

    Rather check a click then a "noclick"

    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:
    if(x>x0
    &&x<x1
    &&y>y0
    &&y<y1)
    exit(0);
    (Or terminate the program in some way)
    -We're living in a illusion!
    -Ok, if that's what you think!

  11. #11
    Registered User FearOfTheDark's Avatar
    Join Date
    Jan 2003
    Posts
    31

    Red face Sorry!

    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!
    -We're living in a illusion!
    -Ok, if that's what you think!

  12. #12
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    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

    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?
    Last edited by Carlos; 01-30-2003 at 10:27 AM.

  13. #13
    Registered User FearOfTheDark's Avatar
    Join Date
    Jan 2003
    Posts
    31
    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! ;-)
    -We're living in a illusion!
    -Ok, if that's what you think!

  14. #14
    Normal vector Carlos's Avatar
    Join Date
    Sep 2001
    Location
    Budapest
    Posts
    463
    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++ .

    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:
    http://www.menuetos.org/

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

  15. #15
    Registered User FearOfTheDark's Avatar
    Join Date
    Jan 2003
    Posts
    31

    Menuet

    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!
    -We're living in a illusion!
    -Ok, if that's what you think!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. need Help in Mouse Pointer
    By obaid in forum C++ Programming
    Replies: 3
    Last Post: 12-07-2006, 03:33 AM
  2. Problem in mouse position
    By Arangol in forum Game Programming
    Replies: 6
    Last Post: 08-08-2006, 07:07 AM
  3. Problem with Mouse Over Menu!!! HELP!!!
    By SweeLeen in forum C++ Programming
    Replies: 3
    Last Post: 02-09-2006, 02:10 AM
  4. Making a mouse hover button, API style
    By hanhao in forum C++ Programming
    Replies: 1
    Last Post: 05-27-2004, 06:17 AM
  5. Game Design Topic #2 - Keyboard or Mouse?
    By TechWins in forum Game Programming
    Replies: 4
    Last Post: 10-08-2002, 03:34 PM