Just trying to handle a simple left-click. Code doesn't work. Tried everything.
Code:
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<windows.h>
using namespace std;
#define WHITE BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE|BACKGROUND_INTENSITY
#define RED FOREGROUND_RED|FOREGROUND_INTENSITY
#define BLACK 0
typedef struct card
{
unsigned int face_value;
char suit;
card *next;
card(){next=NULL;}
}*mycard;
void gotoxy(int x, int y);
void paint_cards(HANDLE, card*);
int main()
{
system("cls");
HANDLE hIn;
HANDLE hOut;
int LoopCount = 0;
int KeyEvents = 0;
INPUT_RECORD InRec;
DWORD NumRead;
hIn = GetStdHandle(STD_INPUT_HANDLE );
hOut = GetStdHandle(STD_OUTPUT_HANDLE);
mycard new_card = new card;
srand(GetTickCount());
system("color 20");
paint_cards(hOut, new_card);
for(;;)
{
ReadConsoleInput(hIn, &InRec, 1, &NumRead);
if (InRec.EventType == MOUSE_EVENT)
if (InRec.Event.MouseEvent.dwEventFlags == 0)
if (InRec.Event.MouseEvent.dwButtonState & 0x01)
{
system("color 70");
system("cls");
cout << "\a\tIt works!!";
}
}
return 0;
}
void paint_cards(HANDLE hOut, card* new_card)
{
int cx=5, cy=5;
for(;cx<46;cx+=10)
{
new_card->face_value = static_cast<unsigned>(rand()%8+2);
new_card->suit = static_cast<char>(rand()%4+3);
SetConsoleTextAttribute(hOut, new_card->suit<5?WHITE|RED:WHITE|BLACK);
gotoxy(cx, cy+0); cout << endl << endl << endl;
gotoxy(cx, cy+1); cout << new_card->face_value << new_card->suit << " \n";
gotoxy(cx, cy+2); cout << " \n";
gotoxy(cx, cy+3); cout << " " << new_card->suit << " \n";
gotoxy(cx, cy+4); cout << " \n";
gotoxy(cx, cy+5); cout << " " << new_card->suit << new_card->face_value;
gotoxy(cx, cy+6); cout << endl << endl << endl << endl;
new_card = new card;
}
SetConsoleTextAttribute(hOut, WHITE|BLACK);
gotoxy(10, 16); cout << " ";
gotoxy(10, 17); cout << " Hit Me! ";
gotoxy(10, 18); cout << " ";
cout << endl << endl << endl;
}
void gotoxy(int x, int y)
{
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}