Mouse stops working after changing function
Posted
by
heyohletsgo
on Stack Overflow
See other posts from Stack Overflow
or by heyohletsgo
Published on 2014-05-29T18:41:57Z
Indexed on
2014/06/01
9:26 UTC
Read the original article
Hit count: 206
I'm making a console board game on c++, and i've been able to make the mouse work in the first function, the menu one, however, when i get to the getmove function and need to click on a house, it simply doesn't work.. Can anyone help? This is the class with the mouse.
#include <cstdlib>
#include <iostream>
#include <process.h>
#include <windows.h>
#include <time.h>
#include <stdio.h>
using namespace std;
void Game();
int Chu();
int rato(int &row, int &col)
{
HANDLE hIn;
hIn = GetStdHandle(STD_INPUT_HANDLE);
bool Continue = TRUE;
INPUT_RECORD InRec;
DWORD NumRead;
HWND window = GetConsoleWindow();
POINT cursorPos;
RECT wpos;
int x = 0;
int y = 0;
//cout << hIn << endl;
FlushConsoleInputBuffer(hIn);
while (Continue) {
ReadConsoleInput(hIn, &InRec, 1, &NumRead);
switch (InRec.EventType)
{
case MOUSE_EVENT: if (GetAsyncKeyState(VK_LBUTTON))
{
cout << "RATO"<<endl;
GetWindowRect(window, &wpos);
GetCursorPos(&cursorPos);
cursorPos.x -= wpos.left;
cursorPos.y -= wpos.top;
x = (cursorPos.x - 5) / 16;
y = (cursorPos.y - 25) / 24;
cout << x << " " << y << endl;
row = x; col = y;
return row;
}
else if (GetAsyncKeyState(VK_RBUTTON)){
GetWindowRect(window, &wpos);
GetCursorPos(&cursorPos);
cursorPos.x -= wpos.left;
cursorPos.y -= wpos.top;
x = (cursorPos.x - 5) / 16;
y = (cursorPos.y - 25) / 24;
cout << x << " " << y << endl;
row = x; col = y;
return row;
}
break;
}
}
}
int main()
{
cout << "\n\n\n click on the stars" << endl;
cout << " \n\n\n *******" << endl;
int z = 0;
int x = 0;
int y = 0;
int xo = 0;
switch (rato(x,y))
{
case 1: Game(); break;
case 2: Game(); break;
case 3: Game(); break;
case 4: rato(x, y); break;
case 5: rato(x, y); break;
case 6: Game(); break;
case 7: Game(); break;
case 8: Game(); break;
case 9: Game(); break;
default: cout << "click again"; break;
}
return 0;
}
void Game()
{
int x = 0;
int y = 0;
int i = 0;
cout << "GAME" << endl;
do{
i++;
rato(x, y);
} while (i <= 2);
Chu();
}
int Chu()
{
int x = 0;
int y = 0;
int a = 0;
int b = 0;
int xo = 0;
int yo = 0;
cout << "\ click on the stars" << endl;
HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
do{
xo = rato(x, y);
if (0 <= xo && xo <= 5) { a = 1;}
else cout << "CLICK AGAIN" << endl;
} while (xo!=0);
cout << a;
return a;
system("PAUSE");
}
© Stack Overflow or respective owner