help with input buffer

I was able to use a mouse in my console. When i compile and the first thing i call is the mouse code, it works perfectly; however, when i need to call that function later on the game, it freezes and simply doesn't work. I've been told i could clean the input buffer but i'm not sure that's the problem. Does anyone have an idea?


// LightUp.cpp : implementation of the CLightUp class

#include "LightUp.h"
#include<time.h>
#include <cstdlib>
#include <iostream>
#include <process.h>
#include <windows.h>
#include <stdio.h>

// CLightUp construction
CLightUp::CLightUp()
{
m_nmoves = 0;
}

// CLightUp destruction
CLightUp::~CLightUp()
{
}
void CLightUp::mouse()
{

HANDLE hIn;
bool Continue = TRUE;
INPUT_RECORD InRec;
DWORD NumRead;
HWND window = GetConsoleWindow();
POINT cursorPos;
RECT wpos;
int x = 0;
int y = 0;
hIn = GetStdHandle(STD_INPUT_HANDLE);
cout << hIn << endl;
if (cin.fail()) { cin.clear(); cin.ignore(1000, '\n'); }

while (Continue) {
ReadConsoleInput(hIn, &InRec, 1, &NumRead);
switch (InRec.EventType)
{
case MOUSE_EVENT: if (GetAsyncKeyState(VK_LBUTTON))
{
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;
}
else if (GetAsyncKeyState(VK_RBUTTON)){
GetWindowRect(window, &wpos);
GetCursorPos(&cursorPos);
cursorPos.x -= wpos.left;
cursorPos.y -= wpos.top;
x = (cursorPos.x - 5) / 8;
y = (cursorPos.y - 25) / 12;
cout << x << " " << y << endl;
// row = x; col = y;
cout << hIn << endl;
}
break;
}
}


}

int CLightUp::menu(void)
{

char e[5];
int esc;
int x, y;

cout << "MENU\n" << endl;
cin >> e;
esc = atoi(e);
system("CLS");
switch (esc){

case 1: Game(); break;
case 2: BoardMaker(); Game(); break;
case 3: mouse(); break;
case 4: cout << "TUTORIAL\n" << endl; break;
case 5: break;
case 6: return 0; break;
default: return menu(); break;

}
}
Unfortunately, I don't have a solution to this immediate problem. My response here may be unhelpful.

I just replied to say you really should not be making this kind of program in the console. This is much, much easier to do with an actual graphic lib.

Save yourself some headaches and get this:
http://sfml-dev.org/
Thanks anyway, i've been told that before, but it's for a class, and has to be done in console..
Topic archived. No new replies allowed.