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

Posted on 1998-10-28
Last Modified: 2008-03-03
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; = 0;        int86(0x33,&r,&r);
 status =;   aantalknoppen = r.x.bx;
int allgood(){return status=-1 || status== 65535;}
void show(){ = 1; int86(0x33,&r,&r); }
void hide()  { = 2; int86(0x33,&r,&r); }

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

void position(int &xm,int &ym)
{ if(!allgood()){xm=0;ym=0;return;}
  xm=ym=1; = 3;     int86(0x33,&r,&r);   xm =;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 )
  { = 7; = minX;r.x.dx = maxX;   int86( 0x33, &r, &r ); = 8; = minY; r.x.dx = maxY;  int86( 0x33, &r, &r );

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

int released( int knop=1/*left*/ )
  { = 6;    r.x.bx = knop;   int86( 0x33, &r, &r );
      return & 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 =' ';;   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;
Question by:LucJanssens
  • 2
LVL 22

Accepted Solution

nietod earned 200 total points
ID: 1176386
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.
LVL 22

Expert Comment

ID: 1176387
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.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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
Unresolved External Symbols 3 101
I could not build boost code, 10 94
Issues with C++ Class 19 100
Outlook 13 39
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…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
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 be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

807 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