Solved

mouse programming

Posted on 1997-02-22
1
225 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Pointer in one class to member in another 6 131
Windows 2008 standard, Disk Cleanup, and Winsxs 30 52
.NET Core supports which cell phone platforms? 3 34
Windows 10 14 29
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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…
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.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

737 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