如何使用SetConsoleorPosition函数

如何使用SetConsoleorPosition函数,c,winapi,graphic,C,Winapi,Graphic,我刚刚用c编写了河内塔的代码,我想用字符以图形方式显示解决方案 我想使用windows.h和SetConsoleCursorPosition函数在控制台中移动光标 你能告诉我这个函数是否工作以及如何使用吗?请给出一些例子。下面是一个如何调用setConsoleorPosition函数的例子,摘自: 您还可以通过查看SDK文档了解如何使用Win32函数。谷歌搜索函数名称通常会在第一次点击时打开相应的文档页面。 对于SetConsoleCursorPosition,页面是,而对于GetStdHand

我刚刚用c编写了河内塔的代码,我想用字符以图形方式显示解决方案

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


你能告诉我这个函数是否工作以及如何使用吗?请给出一些例子。

下面是一个如何调用
setConsoleorPosition
函数的例子,摘自:

您还可以通过查看SDK文档了解如何使用Win32函数。谷歌搜索函数名称通常会在第一次点击时打开相应的文档页面。

对于
SetConsoleCursorPosition
,页面是,而对于
GetStdHandle
,页面是。

次要提示:但是谷歌搜索结果的排序对于每个人来说都是不同的,取决于他们的搜索历史。我几乎每天都会删除我的cookie。cplusplus?寻找Win32函数信息的地方真奇怪。这会有什么问题?没有例子,这对初学者来说并不简单。但总的来说,你是对的,API文档始终是一个很好的起点。谢谢。我如何以图形化的方式使用它?我的意思是展示一些东西?在这里,我们应该为河内塔采取行动。
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.
        // ...
    }
}