PDA

View Full Version : using of left_right arrow button



acer ng
11-23-2001, 09:19 AM
i would like to ask upon how to make the 4th and 5th menu of the command button to be highlighted after the left_right arrow button is been pressed.

i hereby sincerly thanks everyone that would guide me along...
thanks...

this is some part of the program...

void AddProfile (void)
{ char *menu[] = {"Sec 1 Combine", "Sec 2 Combine",
"Sec 3 Combine", "Sec 4 Combine",
"Sec 5 Combine"};
char ch;
int hpos, prehpos;

DatabaseGraphics();

Draw5CmdButtons(133, menu);

setcolor(LIGHTBLUE);
outtextxy(200, 202, "Select a Database to be loaded");
setcolor(LIGHTBLUE);
settextstyle(TRIPLEX_FONT, HORIZ_DIR, 2);
outtextxy(195, 310, "Press ESC key to return");

GraphicsPageInit();

setcolor(YELLOW);
outtextxy(141, 242, menu[0]);

hpos = 0;
do
{ prehpos = hpos;
hpos = ArrowKeySelect(LEFT_RIGHT, hpos, 4, &ch);

if(ch==L_ARROW || ch==R_ARROW)
{ setcolor(YELLOW);
outtextxy(141+128*hpos, 242, menu[hpos]);

setcolor(WHITE);
outtextxy(141+128*prehpos, 242, menu[prehpos]);
}
}while(ch!=ESC);
getch();
}//end AddProfile

void Draw5CmdButtons (int left, char *menu[])
{ int i;

//draw Command Button for Sec 1, 2 and 3 Combine
for(i=0; i<3; i++)
{ rectangle(left, 230, left+118, 260);
rectangle(left+3, 233, left+115, 257);
line(left, 230, left+3, 233);
line(left+115, 257, left+118, 260);

outtextxy(left+8, 242, menu[i]);

setfillstyle(SOLID_FILL, RED);
floodfill(left+10, 231, WHITE);
setfillstyle(SOLID_FILL, LIGHTRED);
floodfill(left+10, 258, WHITE);

left+=128;
}

//draw the Command Button for Sec 4 Combine
rectangle(193, 267, 311, 297);
rectangle(196, 270, 308, 294);
line(193, 267, 196, 270);
line(308, 294, 311, 297);

outtextxy(201, 279, menu[3]);

setfillstyle(SOLID_FILL, RED);
floodfill(203, 268, WHITE);
setfillstyle(SOLID_FILL, LIGHTRED);
floodfill(203, 295, WHITE);

//draw the Command Button for Sec 5 Combine
rectangle(321, 267, 439, 297);
rectangle(324, 270, 436, 294);
line(321, 267, 324, 270);
line(436, 294, 439, 297);

outtextxy(329, 279, menu[4]);

setfillstyle(SOLID_FILL, RED);
floodfill(331, 268, WHITE);
setfillstyle(SOLID_FILL, LIGHTRED);
floodfill(331, 295, WHITE);
}//end Draw5CmdButtons

int ArrowKeySelect (int type, int curpos, int maxpos, char *ch)
{ char key1, key2;

key1 = type ? L_ARROW : U_ARROW;
key2 = type ? R_ARROW : D_ARROW;

*ch = GetKey();

if(*ch == key1)
curpos = (curpos>0) ? curpos-1 : maxpos;
else if(*ch == key2)
curpos = (curpos<maxpos) ? curpos+1 : 0;

return curpos;
}//end ArrowKeySelect

Salem
11-23-2001, 09:51 AM
Do you know that cursor keys (and function keys) are reported in TWO bytes?



ch = getch();
if ( ch == '\0' ) {
// extended key - such as arrow
ch = 256 + getch();
}
// 0..255 are normal keys
// 256..511 are extended keys