Solved

mouse programming

Posted on 1997-02-22
1
220 Views
Last Modified: 2012-08-30
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
0
Comment
Question by:jmeller
1 Comment
 
LVL 10

Accepted Solution

by:
rbr earned 50 total points
ID: 1249507
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now