www.cppfrance.com…
files.codes-sources.com…
une source crade (23h46 inside :paf: ) :
#include <stdio.h>
#include <CONIO.h>
#include <stdlib.h>
#include <stddef.h>
#include <windows.h>
#include <dos.h>
#define UP 0x48
#define DOWN 50
#define RIGHT 4D
#define LEFT 4B
static SMALL_RECT __WINDBOUND={0,0,79,24}; // Absolute bounds of window
static COORD __SCREENCONS={80,25}; // Columns and rows of the DOS screen
void gotoxy(int x,int y);
int wherex();
int __Inside_Window_Relative (COORD c);
void __To_Absolute (COORD * c);
int main(int argc, char argv[])
{
int x = 5;
int y = 0;
char c;
printf("");
do{
while(!kbhit());
c = getch();
switch©
{
//a finir
case UP : if(x>0)
{
system(“CLS”);
//x–;
//moveTo(5,5);
//Gotoxy(5,5);
gotoxy(5,5);
//printf(GOTOYX,5,5);
printf("*");
}
break;
/case DOWN :;break;
case RIGHT :;break;
case LEFT :;break;/
default : printf("\ncar : %x",c);break;
}
}while(c != ‘F’);
system(“CLS”);
system(“PAUSE”);
return 0;
}
void gotoxy(int x, int y)
/* window_text related :
- Move the cursor to row y, column x. The upper left corner of the
- current window is (1,1).
*/
{
COORD c;
c.X= x;
c.Y= y;
if ( __Inside_Window_Relative© )
{
__To_Absolute(&c);
SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c);
}
}
int wherex ()
/* Window_text related :
- return column position of the cursor in the current window_text
*/
{
CONSOLE_SCREEN_BUFFER_INFO info;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
return info.dwCursorPosition.X - __WINDBOUND.Left + 1 ;
}
int __Inside_Window_Relative (COORD c)
/* true iff c inside current window /
/ left upper coordinate : 1,1 */
{
return ( (0<c.X) && (c.X<=__WINDBOUND.Right-__WINDBOUND.Left+1) &&
(0<c.Y) && (c.Y<=__WINDBOUND.Bottom-__WINDBOUND.Top+1) );
}
void __To_Absolute (COORD * c)
/* convert c from relative to absolute */
{
c->X +=__WINDBOUND.Left-1;
c->Y +=__WINDBOUND.Top-1;
}
voir mes lien au dessus