Solved

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

Posted on 1998-10-28
2
1,106 Views
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;
public:

Mouse()
{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;}
  xm=ym=1;
  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=xm>>3;ym=ym>>3;
                                 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 );
  }

private:
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;  }

public:
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;

#endif

#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;
public:
clock(int xx,int yy){x = xx; y = yy;}
void show()
  {gettime(&t);
   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;
      }
  }
};

main()
 { Mouse m;
   clock kl(1,1);
   clock kl2(40,25);
   char letter;   int oldx, oldy, x, y;
   letter =' ';   m.show();   clrscr();
   while( letter != 'x' )
     {kl.show();kl2.show();
      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;
               kl.show();kl2.show();
              }
         // 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;
               kl.show();kl2.show();
              }
         // right released
         gotoxy(oldx ,oldy);cout<<"right";
       }
      if (kbhit() ) {letter =getch();
                 cout<<letter;    }
     }
   m.hide();
   return 0;
 }
0
Comment
Question by:LucJanssens
  • 2
2 Comments
 
LVL 22

Accepted Solution

by:
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.
0
 
LVL 22

Expert Comment

by:nietod
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.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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 goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

708 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

12 Experts available now in Live!

Get 1:1 Help Now