如何使用SetConsoleCursorPosition Func

我刚刚在c中编写了hanoi塔的代码,我想用图形模式显示解决方案。

我想使用windows.h和SetConsoleCursorPosition函数在控制台中移动光标。

你能帮我告诉我这个function是否有效以及如何使用它?请举几个例子。

这是一个如何调用从cplusplus获取的SetConsoleCursorPosition函数的示例 :

 void GoToXY(int column, int line) { // Create a COORD structure and fill in its members. // This specifies the new position of the cursor that we will set. COORD coord; coord.X = column; coord.Y = line; // Obtain a handle to the console screen buffer. // (You're just using the standard console, so you can use STD_OUTPUT_HANDLE // in conjunction with the GetStdHandle() to retrieve the handle.) // Note that because it is a standard handle, we don't need to close it. HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); // Finally, call the SetConsoleCursorPosition function. if (!SetConsoleCursorPosition(hConsole, coord)) { // Uh-oh! The function call failed, so you need to handle the error. // You can call GetLastError() to get a more specific error code. // ... } } 

您还可以通过查看SDK文档了解如何使用Win32函数。 谷歌搜索function的名称通常会打开相应的文档页面作为第一个命中。
对于SetConsoleCursorPosition ,页面在此处 ,对于GetStdHandle ,页面在此处 。