콘솔 창에서 마음대로 커서좌표를 바꾸어 해당 위치에 문자출력 가능합니다.

 

 

소스 

 #include <stdio.h>
#include <windows.h>

 

int gotoxy(int x, int y);//커서 위치 옮기기
int wherex();//x축 커서 위치
int wherey();//y축 커서 위치
HANDLE consoleHandler = GetStdHandle(STD_OUTPUT_HANDLE);
 

int main()

{
 gotoxy(10,10);  
 printf("현재 커서 위치 x=%d y=%d", wherex(), wherey());
 return 0;
}

int gotoxy(int x, int y)
{
   if (consoleHandler == INVALID_HANDLE_VALUE)
      return 0;
   COORD coords = {static_cast<short>(x - 1), static_cast<short>(y - 1)};
   SetConsoleCursorPosition(consoleHandler, coords);
   return 1;
}
int wherex()
{
   if (consoleHandler == INVALID_HANDLE_VALUE)
      return 0;
   CONSOLE_SCREEN_BUFFER_INFO screenInfo;
   GetConsoleScreenBufferInfo(consoleHandler, &screenInfo);
   return screenInfo.dwCursorPosition.X + 1;
}
int wherey()
{
   if (consoleHandler == INVALID_HANDLE_VALUE)
      return 0;
 CONSOLE_SCREEN_BUFFER_INFO screenInfo;
 GetConsoleScreenBufferInfo(consoleHandler, &screenInfo);
   return screenInfo.dwCursorPosition.Y + 1;
}

 


 

 

+ Recent posts