• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1201
  • Last Modified:

int86 0x33 (mouse) Borland C++ 3.0 Console app

Borland C++ 3.0 allows me to create a console application (exe) with the Console Wizard(new project).  In the help of the compiler I find documentation of the int86 routine (normally found in dos.h).  (Unfortunaly no int86 in dos.h)

I try to run all my old dos examples (mouse driven) with Borland C++ 3.0.

Because int86 doesn't work.  I tried to place directly
asm mov ax,...; asm int 33h; in the C++ code, but my
assemble knowledge is poor.   I even tried the smallest possible mouse int 33h (just initialize the mouse), but the program crashes.

I am looking for an easy way to check the mouse position, state of the buttons,... in the old way.  Perhaps it is no longer possible. (Nevertheless it is still documented in the help file).

If I want to run the old dos programs under windows I have to simulate all: getch, kbhit, cin, cout, delay (not easy).
I am working on this possibility, but this is an hard way (I have to use a separated thread ).  I still hope that someone will be able to help me to check the mouse position, mouse buttons in the old way (int86) with Borland C++ Builder.  

(Also C++ Builder 1.0 has the same problem).

I include here the code of a small example under dos in the hope that someone will be able to run it under Borland C++ 3.0.

///////////good luck
#include <stdio.h>
#include <conio.h>
#include <iostream.h>

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

#if !defined MOUSE_H
#define MOUSE_H

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

{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 allgood(){return status=-1 || status== 65535;}
void show(){ r.x.ax = 1; int86(0x33,&r,&r); }
void hide()  { r.x.ax = 2; int86(0x33,&r,&r); }

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

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

void textposition(int &xm,int &ym){ position(xm,ym);
                                 xm++;ym++;// nodig omdat Mouse anders linker

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 );

int pressed( int knop=1/*left*/ )
  {   r.x.ax = 5;  r.x.bx = knop; int86(0x33,&r,&r);
      return r.x.ax & knop;  }

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

int left()       { return pressed( 1 ); }
//int midden()    { return pressed( 4 ); }
int right()      { return pressed( 2 ); }
int leftreleased()    { return released( 1 ); }
//int middenreleased() { return released( 4 ); }
int rightreleased()   { return released( 2 ); }
int Mouse::status=0;
union REGS Mouse::r;
int Mouse::aantalknoppen;


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

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

class clock
{ struct  time t;
  int x, y;
  int hour, minute, second;
clock(int xx,int yy){x = xx; y = yy;}
void show()
   if ( (int)t.ti_hour != hour || (int)t.ti_min != minute
                        || (int)t.ti_sec != second)
      {  gotoxy(x, y);
       cout<< (int)t.ti_hour<<":"  << (int)t.ti_min<<":"
           << (int)t.ti_sec<<"    ";
       hour= (int)t.ti_hour; minute = (int)t.ti_min ;
       second = (int)t.ti_sec;

 { Mouse m;
   clock kl(1,1);
   clock kl2(40,25);
   char letter;   int oldx, oldy, x, y;
   letter =' ';   m.show();   clrscr();
   while( letter != 'x' )
      if (m.left() )
       { // left clicked
         m.textposition(oldx, oldy);
          gotoxy(oldx, oldy); cout<<"L";
         while (m.left() )
              {m.textposition(x, y);
               if ( oldx != x || oldy != y )
                   { // left pressed en moving
                     gotoxy(x, y);   cout<<"*"; }
               oldx = x; oldy  = y;
         // left released
         gotoxy(oldx ,oldy);cout<<"released";
      if (m.right() )
       { // right clicked
         m.textposition(oldx, oldy);
          gotoxy(oldx, oldy); cout<<"R";
         while (m.right() )
              {m.textposition(x, y);
               if ( oldx != x || oldy != y )
                   { // right pressed en moving
                     gotoxy(x, y);   cout<<"."; }
               oldx = x; oldy = y;
         // right released
         gotoxy(oldx ,oldy);cout<<"right";
      if (kbhit() ) {letter =getch();
                 cout<<letter;    }
   return 0;
  • 2
1 Solution
A win32 console application (like you are writting) is a 32 bit window program, it is not a DOS program.  You cannot call the 16 bit DOS interrupts from a 32 bit application.  Thus this whole approach is out.  But there is hope.  details follow.
You can use the window API functions to access the mouse.  I'll list the functions that will be of most value to you.  Why don't you then read up on them in the windows documentation and if you have questions you can ask me about them.  Then we can discuss actually changing your code to use them (there will be one difficulty).

Use GetCursorPos() to get the current mouse position (for position()).
Use the SetCursorPos() to move the mouse (for changeposition()).
Use GetKeyState() with keys of VK_LBUTTON, VK_MBUTTON, and VK_RBUTTON to get the state of the mouse buttons.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now