i have written a console application in c using borland c++. i want to include mouse capabilities in the program ie. run the program using the mouse just like in norton disk doctor(dos-based version). any help? :?:

Dani AI

Generated

Practical, focused summary for a Borland C++ console program (DOS vs. Windows) and a minimal DOS example.

For a DOS-based build the normal approach is to call the mouse services at software interrupt 0x33 (INT 33h). Common services: AX=0 (reset/check driver), AX=1 (show cursor), AX=2 (hide cursor), AX=3 (return button status and X/Y). If the INT 33h driver is not present the init call shows that (AX==0 = not installed, AX==0xFFFF = installed). For modern Windows console programs the Win32 console API must be used instead (ReadConsoleInput / SetConsoleMode with ENABLE_MOUSE_INPUT). was correct that a mouse requires OS/driver-level support rather than plain standard console I/O. (fd.lod.bz)

A concise Borland C (16-bit) wrapper for the common calls — suitable when running under real DOS or DOSBox. The example uses the Borland int86/union REGS interface from <dos.h>.

#include <dos.h>
#include <stdio.h>

#define MOUSE_INT 0x33

int mouse_installed(void)
{
    union REGS regs;
    regs.x.ax = 0;             /* init/reset */
    int86(MOUSE_INT, &regs, &regs);
    return regs.x.ax != 0;    /* AX == 0xFFFF if installed */
}

void show_mouse(void)
{
    union REGS regs;
    regs.x.ax = 1;            /* show pointer */
    int86(MOUSE_INT, &regs, &regs);
}

void get_mouse_pos(int *x, int *y, int *buttons)
{
    union REGS regs;
    regs.x.ax = 3;            /* get position + buttons */
    int86(MOUSE_INT, &regs, &regs);
    *buttons = regs.x.bx;     /* bit0=left, bit1=right, bit2=middle */
    *x = regs.x.cx;
    *y = regs.x.dx;
}

The int86/union REGS calling convention used above is the standard Borland/DOS method for software interrupts. (cosmodoc.org)

Practical notes and pitfalls: the DOS mouse driver must actually be loaded (init will report this); coordinates returned depend on text vs. graphics mode (text coordinates are in character-cell units); some drivers (e.g., CuteMouse variants) return wheel info in BH/BL or different registers — consult INT 33h docs for driver differences. Polling with AX=3 is fine for simple menus; for low-latency event callbacks use the INT 33h “set handler” facility instead. For a console program compiled to run on Windows, switch to the Win32 console event APIs rather than INT 33h. (fd.lod.bz)

For : if the Borland build targets real DOS (or DOSBox) the snippet above is a direct starting point; if the executable is a Win32 console app then the ReadConsoleInput/SetConsoleMode route is required. ’s high-level guidance is consistent with these options.

Recommended Answers

All 2 Replies

There's old DOS mouse libraries. Maybe they still work.
But of course if you have a console application you implicitly never have mouse support.
If you have mouse support you have a textmode fullscreen application or a full graphical user interface.

If you work in DOS mouse support is easy to write yourself using some embedded assembler btw.

hi, can you send me a sample code? i'd really appretiate it

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.