Solved

mouse programming

Posted on 1997-02-22
1
224 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
undefined reference to `bswap_128' 9 186
Adjust Mfcapp 29 177
Assignment from incompatible pointer type? 2 34
Crashing when deleting value with no child in Binary Tree 4 23
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…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

679 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