• C

mouse programming

i am trying to implement a mouse into a dos text mode menu
program. this program has dropdown menus. i have a few
mouse functions but cant understand how to use them properly
any help (or a sample program) would be greatly appreciated
jmellerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rbrCommented:
I have written for my own purpose some mouse functions. Sorry some statements are in german, so if you have further questions send a mail to rbr@physik.kfunigraz.ac.at. I have also written some functions which are able to handle menus with the mouse. Fell free to send mail to me.



#include <stdio.h>
#include <stdlib.h>
#include <dos.h>

#define RR_OK 1
#define RR_NO_MOUSE (-1)
static int mouse_in_use = 0;
/*  0 ... mouse init status = 0 (not initialized) */
/*  1 ... mouse exists */
/* -1 ... no mouse exists */
/*************************************************
 * init_mouse_driver initializes the mouse
 * Returnvalue: RR_OK         mouse exists
 *              RR_NO_MOUSE   no mouse exists
*************************************************/
int init_mouse_driver (void)
{
    register unsigned int erg;

    _asm {
        mov ax,0
        int 33h
        mov erg,ax
    }

    if (erg != 0xffff) {
        mouse_in_use = (-1);
        return (RR_NO_MOUSE);
    }
    mouse_in_use = 1;
    return (RR_OK);
}    
/*************************************************
 * switch_on_mouse mouse-cursor on
 * Returnvalue: RR_OK         mouse exists
 *              RR_NO_MOUSE   no mouse exists
 *
 * mouse_on stores, if the mouse is switched on or not.
*************************************************/
static int mouse_on = 0;
int switch_on_mouse (void)
{
    register int error;
    if (mouse_in_use != 1) {
        if((error = init_mouse_driver()) != RR_OK)
            return(error);
    }
    if (mouse_on == 1)
        return (RR_OK);

    _asm {
         mov ax,0001h
         int 33h
    }      

    mouse_on = 1;
    return (RR_OK);
}
/*************************************************
 * switch_off_mouse mouse cursor off
 * Returnvalue: RR_OK         mouse exists
 *              RR_NO_MOUSE   no mouse exists
*************************************************/
int switch_off_mouse (void)
{
    if (mouse_in_use != 1) {
        return (RR_NO_MOUSE);
    }
    if (mouse_on == 0)
        return (RR_OK);

    _asm {
         mov ax,0002h
         int 33h
    }      

    mouse_on = 0;
    return (RR_OK);
}
/*************************************************
 * get_mouse_status position and status of the mouse
 * Übergabewerte:
 * unsigned *px               X-Position
 * unsigned *py               Y-Position
 * unsigned *pstatus          status of the mouse buttons
 *
 * Returnvalue: RR_OK         mouse exists
 *              RR_NO_MOUSE   no mouse exists  *************************************************/
int get_mouse_status (unsigned *px,unsigned *py,unsigned *pstatus)
{
    unsigned int b_x,c_x,d_x;
   
    if (mouse_in_use != 1) {
        *px=0;
        *py=0;
        *pstatus=0;
        return (RR_NO_MOUSE);
    }
    _asm {
         mov ax,0003h
         int 33h
         mov b_x,bx
         mov c_x,cx
         mov d_x,dx
    }      
    *px      = c_x;
    *py      = d_x;
    *pstatus = b_x;
    return (RR_OK);
}
/*************************************************
 * set_mouse_position set mouse to a position
 * Übergabewerte:
 * unsigned x                 X-Position
 * unsigned y                 Y-Position
 *
 * Returnvalue: RR_OK         mouse exists
 *              RR_NO_MOUSE   no mouse exists
*************************************************/
int set_mouse_position (unsigned x,unsigned y)
{
    if (mouse_in_use != 1) {
        return (RR_NO_MOUSE);
    }
    _asm {
         mov cx,x
         mov dx,y
         mov ax,0004h
         int 33h
    }      
    return (RR_OK);
}
/*************************************************
 * set_mouse_bereich sets the array in which the mouse can move
 * Übergabewerte:
 * unsigned x_start,x_ende    X-Bereich
 * unsigned y_start,x_ende    Y-Bereich
 *
 * Returnvalue: RR_OK         mouse exists
 *              RR_NO_MOUSE   no mouse exists *************************************************/
int set_mouse_bereich  (unsigned x_start,unsigned x_ende,
                        unsigned y_start,unsigned y_ende)
{
    if (mouse_in_use != 1) {
        return (RR_NO_MOUSE);
    }
    _asm {
         mov cx,x_start
         mov dx,x_ende
         mov ax,0007h
         int 33h
         mov cx,y_start
         mov dx,y_ende
         mov ax,0008h
         int 33h
    }
   return (RR_OK);
}

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.