0

I can't use my PC these days so I use what I can to code, and it's TurboC++ 3 in Android device with dosbox. (If you are going to suggest another compiler, suggest one that works in Android and can make .exe files. Else please don't suggest Windows/Mac compilers).

I found a code for mouse usage in Electrosoft's site and added a call to put a pixel where the mouse is clicked. After adding it, the program exits saying I should use initgraph. But as you can see it's there, without the call to putpixel the code works fine.

I'm not experienced with interruptions or asm code so I can't touch the mouse parts. My idea is to use the mouse code as a starting step. Could you please tell me why it's not working?

#include<graphics.h>
#include<stdio.h>
#include<conio.h>
#include<dos.h>
union REGS in,out;

int callmouse()
{
    in.x.ax=1;
    int86(51,&in,&out);
    return 1;
}

void mouseposi(int &xpos,int &ypos,int &click)
{
    in.x.ax=3;
    int86(51,&in,&out);
    click=out.x.bx;
    xpos=out.x.cx;
    ypos=out.x.dx;
}

int mousehide()
{
    in.x.ax=2;
    int86(51,&in,&out);
    return 1;
}

void setposi(int &xpos,int &ypos)
{
    in.x.ax=4;
    in.x.cx=xpos;
    in.x.dx=ypos;
    int86(51,&in,&out);
}

int main()
{
    int x,y,cl,a,b;
    clrscr();
    int g=DETECT,m;
    initgraph(&g,&m,"c:\tc\bgi");
    a=100;
    b=400;
    setposi(a,b);
    callmouse();
    do
    {
        mouseposi(x,y,cl);
        gotoxy(10,9);
        printf("\n\tMouse Position is: %d,%d",x,y);
        printf("\n\tClick: %d",cl);
        printf("\n\tPress any key to hide the mouse");
        //this if block breaks the code
        if(cl==1)
        {
            putpixel(x,y,WHITE);
        }
    }while(!kbhit());
    getch();
    mousehide();
    printf("\n\n\tPress any key to Exit");
    getch();
    return 0;
}

http://electrosofts.com/cgraphics/mouse.html

genpfault
  • 51,148
  • 11
  • 85
  • 139
asdronin
  • 92
  • 1
  • 9
  • Cannot reproduce -- Turbo C++ is too old for me to get a copy. Please upgrade your tools to something within the last 10 years. – Thomas Matthews Aug 27 '19 at 22:58
  • 2
    `"c:\tc\bgi"` -- This is not the string you think it is. This contains escape sequences such as tab (`\t`) and backspace (`\b`). Shouldn't this be: `"c:\\tc\\bgi"`? – PaulMcKenzie Aug 27 '19 at 23:46
  • @PaulMcKenzie you are totally right, thanks a lot! =), after making the change you suggested it works perfectly, i looked at this code for some time and couldnt notice about this, i know i need to improve my skills, good luck with your projects =) – asdronin Aug 28 '19 at 02:34
  • @ThomasMatthews, thanks for trying, yes i know i should use a more recent tool but as said im limited to use an android device then yes there are some nice android tools that are more recent but i need to make an exe so after trying several tools TurboC++ 3 seems to be the more recent tool i can use to make an exe in the end, as said thanks for trying and good luck =) – asdronin Aug 28 '19 at 02:40
  • 1
    Possible duplicate of [Rules for C++ string literals escape character](https://stackoverflow.com/questions/10220401/rules-for-c-string-literals-escape-character) – L. F. Aug 28 '19 at 04:38

0 Answers0