Solved

mouse under DOS using BC++4.52

Posted on 1998-10-27
4
271 Views
Last Modified: 2010-08-05
I'm trying to figure out how to use a mouse under DOS when programming in BC4.52
The help files are pretty quite about this topic, so I was hoping to find someone who could give me the basic code to query the mouse for x & y coordinates and the buttonstate.
Tnx in advance.
PS
1. I need it both in console and graphical environment.
2. I used to use the INT68 way of doing this, but it seems when switching to a 32bit environment it doesn't work anymore (working in dosboxes under NT)
0
Comment
Question by:tofke
  • 2
4 Comments
 
LVL 22

Expert Comment

by:nietod
Comment Utility
Are you programming in DOS?  You say you've switched to a 32 bit environment.  What do you mean by that?  

Note that a win 32 console is not a DOS program.  It is a windows program.  You can use the regular windows API from a win32 console.  Thus you can use GetCursorPosition() to find the mouse cursor position.
0
 
LVL 22

Expert Comment

by:nietod
Comment Utility
Sorry, that should be GetCursorPos()

Also you can use GetKeyState() with VK_LBUTTON, VKMBUTTON, and VK_RBUTTON to get the state of the mouse buttons.  

All this applies only if you are in a win32 console application.  From a DOS application you can use the mouse interrupts.services.
0
 

Accepted Solution

by:
LucJanssens earned 200 total points
Comment Utility
It is very easy to use the mouse under Borland C++ 4.52.
You must open a new project, than select as platform : DOS (standard).  (Don't change the other options).  A new project is
created.

You can use the following code: (normally I place the Muis class
in a seperated header file):

You can cut/paste the following code right into you cpp file (generated for your new project), press ctrl f9.  I tested this.
It works.

Good luck

Luc Janssens
#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#define _NAIVE_DOS_REGS  // nodig voor DJGPP compiler (voor int86)

// Mouse.h
#include <dos.h>

#if !defined MOUSE_H
#define MOUSE_H


class Muis
{static union REGS r;
static int aantalknoppen;
// status van een Mouse-object
static int status;
public:

Muis()
{setbuf(stdout,NULL);  // nodig voor DJGPP compiler (geen schermbuffering)
 // cout is met stdout verbonden
// status=0;
 r.x.ax = 0;        int86(0x33,&r,&r);
 status = r.x.ax;   aantalknoppen = r.x.bx;
}
int allesgoed(){return status=-1 || status== 65535;}
void toon(){ r.x.ax = 1; int86(0x33,&r,&r); }
void verberg()  { r.x.ax = 2; int86(0x33,&r,&r); }

void veranderpositie(int xm,int ym )
  {   r.x.ax = 4;  r.x.cx = xm; r.x.dx = ym; int86(0x33,&r,&r);  }

void positie(int &xm,int &ym)
{ if(!allesgoed()){xm=0;ym=0;return;}
  xm=ym=1;
  r.x.ax = 3;     int86(0x33,&r,&r);   xm = r.x.cx;ym= r.x.dx ;
}

void textpositie(int &xm,int &ym){ positie(xm,ym);
                           xm=xm>>3;ym=ym>>3;
                                 xm++;ym++;// nodig omdat muis anders linker
//bovenhoek van rechthoekige muis aanduidt
                               }

void setArea( int minX, int maxX, int minY, int maxY )
  {   r.x.ax = 7; r.x.cx = minX;r.x.dx = maxX;   int86( 0x33, &r, &r );
      r.x.ax = 8; r.x.cx = minY; r.x.dx = maxY;  int86( 0x33, &r, &r );
  }

private:
int ingedrukt( int knop=1/*links*/ )
  {   r.x.ax = 5;  r.x.bx = knop; int86(0x33,&r,&r);
      return r.x.ax & knop;  }

int losgelaten( int knop=1/*links*/ )
  {   r.x.ax = 6;    r.x.bx = knop;   int86( 0x33, &r, &r );
      return r.x.ax & knop;  }

public:
int links()       { return ingedrukt( 1 ); }
//int midden()    { return ingedrukt( 4 ); }
int rechts()      { return ingedrukt( 2 ); }
int linkslos()    { return losgelaten( 1 ); }
//int middenlos() { return losgelaten( 4 ); }
int rechtslos()   { return losgelaten( 2 ); }
};
int Muis::status=0;
union REGS Muis::r;
int Muis::aantalknoppen;

#endif

#include <iostream.h>                   // nodig voor cout
#include <conio.h>               // nodig voor clrscr,gotoxy,...
#include   <dos.h>

///////////////
// now an example of use of this class in C++
// links means left, rechts means right,
// textpositie means textposition
//////////////

#include <iostream.h>                   // nodig voor cout
#include <conio.h>                      // nodig voor clrscr,gotoxy,...
#include   <dos.h>

class klok
{ struct  time t;
  int x, y;
  int uur, minuut, second;
public:
klok(int xx,int yy){x = xx; y = yy;}
void toon()
  {gettime(&t);
   // de klok wordt alleen getoond als er iets veranderd, anders
   // flikkert het beeld.
   if ( (int)t.ti_hour != uur || (int)t.ti_min != minuut
                        || (int)t.ti_sec != second)
      {  gotoxy(x, y);
       cout<< (int)t.ti_hour<<":"  << (int)t.ti_min<<":"
           << (int)t.ti_sec<<"    ";
       uur= (int)t.ti_hour; minuut = (int)t.ti_min ;
       second = (int)t.ti_sec;
      }
  }
};

main()
 { Muis m;
   klok kl(1,1);
   klok kl2(40,25);
   char letter;   int oldx, oldy, x, y;
   letter =' ';   m.toon();   clrscr();
   while( letter != 'x' )
     {kl.toon();kl2.toon();
      if (m.links() )
       { // links geklikt
         m.textpositie(oldx, oldy);
          gotoxy(oldx, oldy); cout<<"L";
         while (m.links() )
              {m.textpositie(x, y);
               if ( oldx != x || oldy != y )
                   { // links ingedrukt en beweegt
                     gotoxy(x, y);   cout<<"*"; }
               oldx = x; oldy  = y;
               kl.toon();kl2.toon();
              }
         // links losgelaten
         gotoxy(oldx ,oldy);cout<<"los";
       }
      if (m.rechts() )
       { // rechts geklikt
         m.textpositie(oldx, oldy);
          gotoxy(oldx, oldy); cout<<"R";
         while (m.rechts() )
              {m.textpositie(x, y);
               if ( oldx != x || oldy != y )
                   { // rechts ingedrukt en beweegt
                     gotoxy(x, y);   cout<<"."; }
               oldx = x; oldy = y;
               kl.toon();kl2.toon();
              }
         // rechts losgelaten
         gotoxy(oldx ,oldy);cout<<"rechts";
       }
      if (kbhit() ) {letter =getch();
                 cout<<letter;    }
     }
   m.verberg();
   return 0;
 }
0
 

Author Comment

by:tofke
Comment Utility
I tested the code both under 95 and NT4 ...
There are still some differences :
In dos-box there is no difference at first sight, but when switching to console-view (Alt+Enter) the stars aren't drawn by the NT version and the 95 version draws the stars inverted, so on a white backround ...
But it works , so now YOUR own problems must be solved TOO :)
greetz,
one of your students :)
PS Where did you find your solution ? PC Intern 4 ??? :)
PPS What was still wrong before ?
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

763 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

10 Experts available now in Live!

Get 1:1 Help Now