+ 3

Which library should i use to integrate mouse pointer in my c++ program

29th Sep 2017, 12:30 PM
Mukul
Mukul - avatar
5 Réponses
+ 5
/*you must include dos.h*/ #include<dos.h> /*you must include stdlib.h for exit function*/ #include<stdlib.h> /*----------------------------------*/ struct mouse{int x,y,b;}; void mouse_ini(); int mouse_show(); int mouse_hide(); void mouse_get(mouse *); void mouse_set(int x,int y); void mouse_restrict(int x_left,int y_top,int x_right,int y_bottom); /*-----------------------------------*/ /*to initialize the mouse when program starts*/ int mouse_ini() { if(!mouse_show()) { printf("error in inializing mouse"); printf("Press any key to halt:"); getch(); exit(1); } else mouse_restrict(0,0,getmaxx(),getmaxy()); /*note:-getmaxx() and getmaxy() are functions of graphics.h*/ } /*to enable cursor or show cursor to user*/ int mouse_show() { in.x.ax=1; return int86(51,&in,&out); } /*to disable cursor or hide cursor to user*/ int mouse_hide() { in.x.ax=2; return int86(51,&in,&out); } /*get current mouse information b for button x for x-axis u for y-axis */ void mouse_get(mouse *mus) { in.x.ax=3; int86(51,&in,&out); mus->b=out.x.bx; mus->x=out.x.cx; mus->y=out.x.dx; } /*when you want to get the mouse position and button use this method mouse mus; mouse_get(&mus); */ /*set new position for the cursor*/ void mouse_set(int x,int y) { in.x.ax=4; in.x.cx=x; in.x.dx=y; int86(51,&in,&out); } /*restrict the mouse pointer between the specific positions*/ void mouse_restrict(int x_left,int y_top,int x_right,int y_bottom) { in.x.ax=7; in.x.cx=x_left; in.x.dx=x_right; int86(51,&in,&out); in.x.ax=8; in.x.cx=y_top; in.x.dx=y_bottom; int86(51,&in,&out); } /*include this code just after graphics initialization*/ void main() { mouse_ini(); }
29th Sep 2017, 12:40 PM
Kartikey Sahu
Kartikey Sahu - avatar
+ 3
Maybe Win32 or MFC. Or if you need a cross - platform alternative, nCurses will be a good choice.
30th Sep 2017, 6:57 AM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
0
thank you
29th Sep 2017, 2:40 PM
Mukul
Mukul - avatar