Solved

mouse under DOS using BC++4.52

Posted on 1998-10-27
4
274 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
ID: 1176336
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
ID: 1176337
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
ID: 1176338
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
ID: 1176339
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

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

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

895 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

11 Experts available now in Live!

Get 1:1 Help Now