Solved

mouse under DOS using BC++4.52

Posted on 1998-10-27
4
279 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
[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
  • 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
convert char array to number in c 5 93
Add values of each row in an array 3 81
Precision Problem in C++ 7 67
parameter pack in c++11 2 23
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

738 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