C++ setConsoleUrsOrposition()函数有问题
我需要一个人帮忙,因为我无法让setConsoleUrsOrposition()函数工作,我做了一个dll项目,然后我分配了控制台及其主要函数(cout和cin),但我不知道如何使该函数也工作,因为我没有转到我设置的行,因为代码忽略了该指令C++ setConsoleUrsOrposition()函数有问题,c++,winapi,dll,C++,Winapi,Dll,我需要一个人帮忙,因为我无法让setConsoleUrsOrposition()函数工作,我做了一个dll项目,然后我分配了控制台及其主要函数(cout和cin),但我不知道如何使该函数也工作,因为我没有转到我设置的行,因为代码忽略了该指令 void consolerefresh() { static const HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); COORD coord = { (SHORT)0, (SHORT)
void consolerefresh()
{
static const HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coord = { (SHORT)0, (SHORT)10 };
SetConsoleCursorPosition(hConsole, coord);
for (int i = 0; i < (sizeof(last) / sizeof(last[0])); i++)
{
if (last[i] != 2) {
cout << last[i] << endl;
}
}
}
编辑:我修复了代码中的错误,但仍然不起作用。根据,第一个参数必须是“控制台屏幕的句柄缓冲区”。根据,活动控制台屏幕缓冲区的句柄由STD\u输出\u句柄
返回,而不是STD\u输入\u句柄
,后者是控制台输入缓冲区的句柄
使用正确的句柄将使设置控制台或位置
按预期工作
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); // instead of STD_INPUT_HANDLE
[编辑]使用默认向导生成的Win应用程序,在
wWinMain
周围添加以下代码,验证以下内容在VS 2019中有效
//... wizard generated code
#include <stdio.h>
#include <iostream>
void consolerefresh()
{
static const HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coord = { 5, 5 };
SetConsoleCursorPosition(hConsole, coord);
std::cout << "at (5, 5)" << std::endl;
}
void createconsole()
{
AllocConsole();
FILE* fDummy;
freopen_s(&fDummy, "CONOUT$", "w", stdout);
}
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{
createconsole();
consolerefresh();
UNREFERENCED_PARAMETER(hPrevInstance);
//... rest of wizard generated code
/。。。向导生成的代码
#包括
#包括
void consolerefresh()
{
静态常量句柄hConsole=GetStdHandle(标准输出句柄);
COORD COORD={5,5};
设置控制台位置(hConsole、coord);
std::难道它不起作用吗anyway@Im_Not_Mine33我对答案进行了编辑,并添加了一个最小的示例,说明它是有效的。
//... wizard generated code
#include <stdio.h>
#include <iostream>
void consolerefresh()
{
static const HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD coord = { 5, 5 };
SetConsoleCursorPosition(hConsole, coord);
std::cout << "at (5, 5)" << std::endl;
}
void createconsole()
{
AllocConsole();
FILE* fDummy;
freopen_s(&fDummy, "CONOUT$", "w", stdout);
}
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{
createconsole();
consolerefresh();
UNREFERENCED_PARAMETER(hPrevInstance);
//... rest of wizard generated code