gilou Modérateur Modzilla | Tiens, voici quelques fonctions de base utiles dans ce contexte:
Code :
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdbool.h>
- #include <windows.h>
- // handle global pour la console
- static HANDLE hConsole = NULL;
- static SHORT ConsoleWidth = 0;
- static SHORT ConsoleLength = 0;
- static SHORT CursorStartX = 0;
- static SHORT CursorStartY = 0;
- bool InitConsole() {
- hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
- if (hConsole != INVALID_HANDLE_VALUE) {
- CONSOLE_SCREEN_BUFFER_INFO cBufferInfo;
- if (GetConsoleScreenBufferInfo(hConsole, &cBufferInfo)) {
- ConsoleWidth = cBufferInfo.dwSize.X;
- ConsoleLength = cBufferInfo.dwSize.Y;
- CursorStartX = cBufferInfo.dwCursorPosition.X;
- CursorStartY = cBufferInfo.dwCursorPosition.Y;
- return true;
- }
- }
- return false;
- }
- bool ClrScrn(void) {
- COORD coord = {0};
- DWORD written;
- FillConsoleOutputCharacter(hConsole, TEXT(' '), ConsoleWidth * ConsoleLength, coord, &written);
- SetConsoleCursorPosition(hConsole, coord);
- CursorStartX = 0;
- CursorStartY = 0;
- return (written == ConsoleWidth * ConsoleLength);
- }
- void GotoXY(int x, int y) {
- COORD coord = {x, y};
- SetConsoleCursorPosition(hConsole, coord);
- }
- void GetXY(SHORT *x, SHORT *y) {
- CONSOLE_SCREEN_BUFFER_INFO csbInfo;
- GetConsoleScreenBufferInfo(hConsole, &csbInfo);
- *x = csbInfo.dwCursorPosition.X;
- *y = csbInfo.dwCursorPosition.Y;
- }
- void ClrEol() {
- COORD curpos;
- DWORD written;
- GetXY(&curpos.X, &curpos.Y);
- FillConsoleOutputCharacter(hConsole, TEXT(' '), ConsoleWidth - curpos.X, curpos, &written);
- GotoXY(curpos.X, curpos.Y);
- }
- int main() {
- if (InitConsole()) {
- //Ton code ici
- return (EXIT_SUCCESS);
- }
- return (EXIT_FAILURE);
- }
|
Ca marche très bien chez moi avec gcc.
A+,
---------------
There's more than what can be linked! -- Iyashikei Anime Forever! -- AngularJS c'est un framework d'engulé! --
|