在下面的代码中,我想要获取鼠标光标在屏幕上的位置,但无论我将光标移动到哪里,我都会从下面第二个加粗的部分得到相同的输出(无论光标在哪里):-1957298293 343277548。如果有人有更好的获取光标位置的方法或修复我的代码,请帮忙。(顺便说一句,“HANDLE csbiHandle; CONSOLE_SCREEN_BUFFER_INFO csbi;”不是必需的,它们用于我之前失败的方法中)。
#include <iostream>
#include <windows.h>
#include <cstdlib>
#include <cstdio>
#include <stdio.h>
#ifndef MOUSE_HWHEELED
#define MOUSE_HWHEELED 0x0008
#endif
using namespace std;
int main()
{
LPPOINT point;
HANDLE csbiHandle;
CONSOLE_SCREEN_BUFFER_INFO csbi;
int counter = 0;
DWORD cNumRead, i,fdwMode, fdwSaveOldMode;
INPUT_RECORD irInputBuffer[128];
HANDLE stdHandle;
stdHandle = GetStdHandle(STD_INPUT_HANDLE);
MOUSE_EVENT_RECORD mer;
cout << "|-------------|" << endl
<< "| A |" << endl
<< "|-------------|" << endl;
while(counter++<1000)
{
buttonpress:
ReadConsoleInput(stdHandle, irInputBuffer,128, &cNumRead);
**GetCursorPos(point);**
for(i=0; i<cNumRead; i++)
{
switch(irInputBuffer[i].EventType)
{
case MOUSE_EVENT:
{
mer = irInputBuffer[i].Event.MouseEvent;
if(mer.dwButtonState == FROM_LEFT_1ST_BUTTON_PRESSED)
{
cout << "left button press" << endl;
**cout << point->x << " " << point->y << endl;**
}
else
{
goto buttonpress;
}
break;
}
default:{
printf("unknown\n");
break;}
}
}
}
return 0;
}