C语言控制台程序中如何获取光标位置?就是(x, y)坐标。

2024-12-14 05:57:28
推荐回答(1个)
回答1:

结果:
DeskTopPos:
X: 680 Y: 592
ClientPos:
X: 586 Y: 444
请按任意键如配皮继续. . .

代码:
#include
#include "stdlib.h"
#include

main()
{

HWND hConsole = FindWindow("ConsoleWindowClass", NULL);
POINT pt;
GetCursorPos(&pt);
printf("DeskTopPos:\nX:%4i Y:%4i\n", pt.x, pt.y);
ScreenToClient(hConsole, &pt);
printf("ClientPos:\nX:%4i Y:%4i\n", pt.x, pt.y);
fflush(stdin);
system("pause");
}
函数连接:卖枝
http://baike.baidu.com/view/1080506.htm
http://baike.baidu.com/view/1079910.htm

楼主好运!渣差