Menu problem

The following code is a menu program in Borland c++ 3.1

I want to prevent the blinking of the text when cursor is overhead the respective button
[BLUE]
#include
#include
#include
#include
#ifndef __DOS_H
#include
#endif

int mouse_status;
int mouse_x;
int mouse_y;


int mouse_reset(void);
void mouse_enable(void);
void mouse_disable(void);
void mouse_read_cursor(void);
void mouse_horizontal_range(int xmin, int xmax);
void mouse_vertical_range(int ymin, int ymax);


/* names of the various cards supported */

void main(void)
{
/* returns detected hardware info. */
int gdriver, gmode, errorcode;

/* detect graphics hardware available */
initgraph(&gdriver, &gmode,"\bc\bgi");

/* read result of detectgraph call */
errorcode = graphresult();
if (errorcode != grOk) /* an error
occurred */
{

printf("Graphics error: %s
", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* terminate with an error code */
}


//coordinates for button
int leftlen=40, rightlen=100, toplen=50, downlen=70;
/* display the information detected */
mouse_enable();
mouse_enable();
int len=100;
for(int i=1;i<6;i++)
{
setfillstyle(SOLID_FILL, RED);
bar(leftlen, toplen, rightlen, downlen);
setcolor(WHITE);
line(leftlen,toplen,leftlen,downlen-1);
line(leftlen,toplen,rightlen-1,toplen);
setcolor(DARKGRAY);
line(rightlen,downlen,leftlen,downlen);
line(rightlen,downlen,rightlen,toplen);
setcolor(YELLOW);
switch(i)
{
case 1:outtextxy(leftlen+5,toplen+4,"FILE");
break;
case 2 : outtextxy(leftlen+5,toplen+4,"EDIT");
break;
case 3 : outtextxy(leftlen+5,toplen+4,"VIEW");
break;
case 4 : outtextxy(leftlen+5,toplen+4,"SEARCH");
break;
case 5 : outtextxy(leftlen+5,toplen+4,"TOOLS");
break;
}
toplen+=20;
downlen+=20;


} outtextxy(500,410,"EXIT");
do{
setfillstyle(SOLID_FILL,BLACK);
bar(len,90,200,200);
mouse_read_cursor();
setcolor(RED);
if((mouse_x>40&&mouse_x<100)&&mouse_y>49&&mouse_y<70)
outtextxy(len+10,170,"FILE ");
if((mouse_x>40&&mouse_x<100)&&mouse_y>69&&mouse_y<90)
outtextxy(len+10,170,"EDIT ");
if((mouse_x>40&&mouse_x89&&mouse_y<110)
outtextxy(len+10,170,"VIEW ");
if((mouse_x>40&&mouse_x109&&mouse_y<130)
outtextxy(len+10,170," Search");
if((mouse_x>40&&mouse_x129&&mouse_y<150)
outtextxy(len+10,170,"TOOLS ");


}
while(mouse_x!=500&&mouse_y!=410);
getchar();
mouse_disable();

}

/*************************************************************************
* *
* F U N C T I O N S *
* *
*************************************************************************/

/*----------------------------------------------------------------------*/

int mouse_reset(void)
{
_AX=0;
geninterrupt(0x33);
return(_AX);
} /* mouse_reset */

/*----------------------------------------------------------------------*/

void mouse_enable(void)
{
_AX=1;
geninterrupt(0x33);
} /* mouse_enable */


/*----------------------------------------------------------------------*/

void mouse_disable(void)
{
_AX=2;
geninterrupt(0x33);
} /* mouse_disable */

/*----------------------------------------------------------------------*/

void mouse_read_cursor(void)
{
_AX=3;
geninterrupt(0x33);
mouse_status=_BX;
mouse_x=_CX;
mouse_y=_DX;
} /* mouse_read_cursor */

/*----------------------------------------------------------------------*/

void mouse_horizontal_range(int xmin, int xmax)
{
_AX=7;
_CX=xmin;
_DX=xmax;
geninterrupt(0x33);
} /* mouse_vertical_range */

/*----------------------------------------------------------------------*/

void mouse_vertical_range(int ymin, int ymax)
{
_AX=8;
_CX=ymin;
_DX=ymax;
geninterrupt(0x33);
} /* mouse_vertical_range */

//end of code[/BLUE]

[RED] PLEASE CHECK THE CODE[/RED]

Comments

  • : The following code is a menu program in Borland c++ 3.1
    :
    : I want to prevent the blinking of the text when cursor is overhead the respective button

    Too many errors in your code to patch it all here. Email me and I'll attach a corrected file. Basically, you want to output the text only when the mouse changes position over a new item. Some errors are indicated below.


    : [BLUE]
    : #include
    : #include
    : #include
    : #include
    : #ifndef __DOS_H
    : #include
    : #endif
    :
    : int mouse_status;
    : int mouse_x;
    : int mouse_y;
    :
    :
    : int mouse_reset(void);
    : void mouse_enable(void);
    : void mouse_disable(void);
    : void mouse_read_cursor(void);
    : void mouse_horizontal_range(int xmin, int xmax);
    : void mouse_vertical_range(int ymin, int ymax);
    :
    :
    : /* names of the various cards supported */
    :
    :int main(void) // void main(void)
    : {
    : /* returns detected hardware info. */
    : int gdriver, gmode, errorcode;
    :
    : /* detect graphics hardware available */
    : initgraph(&gdriver, &gmode,"\bc\bgi");
    :
    : /* read result of detectgraph call */
    : errorcode = graphresult();
    : if (errorcode != grOk) /* an error
    : occurred */
    : {
    :
    : printf("Graphics error: %s
    ", grapherrormsg(errorcode));
    : printf("Press any key to halt:");
    : getch();
    : exit(1); /* terminate with an error code */
    : }
    :
    :
    : //coordinates for button
    : int leftlen=40, rightlen=100, toplen=50, downlen=70; // ERROR!
    : /* display the information detected */
    : mouse_enable();
    : mouse_enable();
    : int len=100; // ERROR!
    : for(int i=1;i<6;i++) // ERROR!
    : {
    : setfillstyle(SOLID_FILL, RED);
    : bar(leftlen, toplen, rightlen, downlen);
    : setcolor(WHITE);
    : line(leftlen,toplen,leftlen,downlen-1);
    : line(leftlen,toplen,rightlen-1,toplen);
    : setcolor(DARKGRAY);
    : line(rightlen,downlen,leftlen,downlen);
    : line(rightlen,downlen,rightlen,toplen);
    : setcolor(YELLOW);
    : switch(i)
    : {
    : case 1:outtextxy(leftlen+5,toplen+4,"FILE");
    : break;
    : case 2 : outtextxy(leftlen+5,toplen+4,"EDIT");
    : break;
    : case 3 : outtextxy(leftlen+5,toplen+4,"VIEW");
    : break;
    : case 4 : outtextxy(leftlen+5,toplen+4,"SEARCH");
    : break;
    : case 5 : outtextxy(leftlen+5,toplen+4,"TOOLS");
    : break;
    : }
    : toplen+=20;
    : downlen+=20;
    :
    :
    : } outtextxy(500,410,"EXIT");
    : do{
    : setfillstyle(SOLID_FILL,BLACK); // this is the cause of the blinking
    : bar(len,90,200,200); // only do this when the menu item changes
    : mouse_read_cursor();
    : setcolor(RED);
    : if((mouse_x>40&&mouse_x<100)&&mouse_y>49&&mouse_y<70)
    : outtextxy(len+10,170,"FILE ");
    : if((mouse_x>40&&mouse_x<100)&&mouse_y>69&&mouse_y<90)
    : outtextxy(len+10,170,"EDIT ");
    : if((mouse_x>40&&mouse_x89&&mouse_y<110)
    : outtextxy(len+10,170,"VIEW ");
    : if((mouse_x>40&&mouse_x109&&mouse_y<130)
    : outtextxy(len+10,170," Search");
    : if((mouse_x>40&&mouse_x129&&mouse_y<150)
    : outtextxy(len+10,170,"TOOLS ");
    :
    :
    : }
    : while(mouse_x!=500&&mouse_y!=410);
    : getchar();
    : mouse_disable();
    :
    : }
    :
    : /*************************************************************************
    : * *
    : * F U N C T I O N S *
    : * *
    : *************************************************************************/
    :
    : /*----------------------------------------------------------------------*/
    :
    : int mouse_reset(void)
    : {
    : _AX=0;
    : geninterrupt(0x33);
    : return(_AX);
    : } /* mouse_reset */
    :
    : /*----------------------------------------------------------------------*/
    :
    : void mouse_enable(void)
    : {
    : _AX=1;
    : geninterrupt(0x33);
    : } /* mouse_enable */
    :
    :
    : /*----------------------------------------------------------------------*/
    :
    : void mouse_disable(void)
    : {
    : _AX=2;
    : geninterrupt(0x33);
    : } /* mouse_disable */
    :
    : /*----------------------------------------------------------------------*/
    :
    : void mouse_read_cursor(void)
    : {
    : _AX=3;
    : geninterrupt(0x33);
    : mouse_status=_BX;
    : mouse_x=_CX;
    : mouse_y=_DX;
    : } /* mouse_read_cursor */
    :
    : /*----------------------------------------------------------------------*/
    :
    : void mouse_horizontal_range(int xmin, int xmax)
    : {
    : _AX=7;
    : _CX=xmin;
    : _DX=xmax;
    : geninterrupt(0x33);
    : } /* mouse_vertical_range */
    :
    : /*----------------------------------------------------------------------*/
    :
    : void mouse_vertical_range(int ymin, int ymax)
    : {
    : _AX=8;
    : _CX=ymin;
    : _DX=ymax;
    : geninterrupt(0x33);
    : } /* mouse_vertical_range */
    :
    : //end of code[/BLUE]
    :
    : [RED] PLEASE CHECK THE CODE[/RED]
    :
    :
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion