سلام دوستان این برنامه را قبلا گذاشته ام اما حالا ان را با استفاده از تابع gotoxy() بازنویسی کردم تا از delay ان کمتر بشه
این یه برنامه است که با استفاده از ان می تونید یک منوی که با جهت های بالا و پایین حساس است بسازید.
توضیحات اضافی را درخود برنامه گذاشتم......
کد:
/* Menu Shower V 1.1
Compile with visual C++‎ 6
Programmer:Milad Kakoli(Kitten)
E-main:hellcrueldictator@yahoo.com
Weblog:kitten
yek code besyar sade baraye nemayesh yek menu sade ke omidvaram
dafa'at bad betonam ziba tar va karamad taresh konam.
in code ghabliat shenakht jahhat haye bala va paiine baraye
moshakhas kardan gozine entekhab shode ra darad va ba zadan enter
halghe payan yafte gozine entekhab shode moshakhas mishavad
baraye etela'at bishtar be weblog moraje'e konid.
*/
#include<iostream.h>
#include<string.h>
#include<stdio.h>
#include<conio.h>
#include <windows.h>
int ch; //braye gereftan jahat
int row=0; //moshakhas kardan satr fa'al
#define MAX 40 // bishtarin tedad char moton
char uptext[1][MAX]; // matne balaye menu
bool chi=true;
struct Student
{
int tedad; // tedad gozinehaye ghabel entekhab
char moton[5][MAX]; // moton gozinehaye ghabel entekhab
};Student s;
/*tabe menu ke moton menu ra print mikonad*/
int menu() {
cout<< uptext[0]<<endl;//print matne balaye menu
for (int i=0 ;i < s.tedad;i++)
{
if (i==row) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HA NDLE), 2);
}//taghiir rang baraye moshakhas kardan gozine fa'al
cout<< i+1 <<"-"<<s.moton[i]<<endl;
if (i==row) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HA NDLE), 7);
}//bargardandan rang be halat aval
}
return 0;//payan tabe
}
int main(){
s.tedad=5; // moshakhas kardan tedad gozineha
strcpy(s.moton[0],"Menu Viewer V 1.0");//kopy gozine aval
strcpy(s.moton[1],"hellcrueldictator@yahoo.com");//kopy gozine 2vom
strcpy(s.moton[2],"www.kitten.mihanblog.com");//kopy gozine 3vom
strcpy(s.moton[3],"Kitten");//kopy gozine 4om
strcpy(s.moton[4],"Movafagh bashid");//kopy gozine 5om
strcpy(uptext[0],"this is my menu");//kopy matn balaye menu
while(chi) {
gotoxy(0,0); // shoro az ebteda
menu(); // >>ejraye tabe menu
ch =getch(); //up=72,down=80, enter=13
switch(ch) {
case 72://up
if (row==0) {
row=s.tedad-1;
}//bargardandan be paiin
else {
row=row-1;
}//bargardandan be bala
break;
case 80://down
if(row==s.tedad-1) {
row=0;
}//bargardandan be bala
else {
row=row+1;
}//bargardandan be paiin
break;
case 13://enter
chi=false;//baraye khoroj az halghe
break;

}
}
/*baraye anjam karhaye badi
gozineye entekhab shode tavasot karbar row+1 ast */
return 0;
}
//shabih saz gotoxy
void gotoxy(int x,int y)
{
COORD pos;
HANDLE hConsole = GetStdHandle ( STD_OUTPUT_HANDLE );
if (INVALID_HANDLE_VALUE != hConsole)
{
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition( hConsole, pos );
}
}

__________________