I am trying to create the main menu of a console application. And I wanted the user to click on a specific place to go to either the login or signup part. I have been trying for it to work but it isn't.
void Menu::Welcome() {
SetConsoleOutputCP(CP_UTF8);
HANDLE consoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD consoleMode;
GetConsoleMode(consoleHandle, &consoleMode);
SetConsoleTextAttribute(consoleHandle, FOREGROUND_BLUE|FOREGROUND_INTENSITY);
cout << "\t\t\t\t\t\tMuSicHub" << endl;
SetConsoleTextAttribute(consoleHandle,FOREGROUND_INTENSITY);
cout << "\t\t\t\tRecommending Songs Through User Behaviour" << endl;
...
cursorpos.X = 45;
cursorpos.Y = 10;
SetConsoleCursorPosition(consoleHandle, cursorpos);
SetConsoleTextAttribute(consoleHandle, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE);
cout << "Click ";
SetConsoleTextAttribute(consoleHandle, FOREGROUND_BLUE);
cout << "Here ";
SetConsoleTextAttribute(consoleHandle, FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE);
cout << "To Login!";
HWND hwnd = GetConsoleWindow();
POINT p;
while (1) {
GetCursorPos(&p);
ScreenToClient(hwnd,&p);
if (p.x > 51 && p.x < 56) {
cout << "Login" << endl;
break;
}
}
}
I added print statements after GetCursorPos and ScreenToClient and the values did not change at all? I was expecting for the value of p.x to be adjusted. But they weren't. Is there something that I am doing wrong? What do I do to correct this code.