*固定*使用cpp(msfs2020 SimConnect)不断更新控制台
*FIXED *constantly update console using cpp (msfs2020 SimConnect)
示例图片
我试图不断更新与海拔高度相关的控制台号码。目前,这是一个静态数字,在飞机上升或下降高度时不会更新。在文本底部附近有一条评论,引用了我用来将其发送到控制台的prinf(((不确定需要看到什么,所以我发送了所有内容(。
#include <iostream>
#include <Windows.h>
#include "SimConnect.h"
#include <string>
#include <sstream>
using namespace std;
HANDLE hSimConnect = NULL;
enum DATA_DEFINE_ID
{
DEFINITION_ID_AP,
};
enum DATA_REQUEST_ID
{
REQUEST_AP_SETTINGS,
};
enum EVENT_ID
{
EVENT_SET_AP_ALTITUDE,
};
struct DataRefs
{
double altitude;
double knots;
};
int main() {
HRESULT hr;
SIMCONNECT_RECV* pData = NULL;
DWORD cbData = 0;
bool bRequestProcessed = false;
int SelectedAltitude = 0;
SIMCONNECT_RECV_SIMOBJECT_DATA* pObjData = NULL;
DataRefs* pDataRefs = NULL;
if (SUCCEEDED(SimConnect_Open(&hSimConnect, "Client Event", NULL, NULL, NULL, NULL))) {
printf("Connected to MSFS2020!n");
}
else {
/* string str = "42";
int num2 = stoi(str);
cout << num2;
*/
printf("Failed to Connect to MSFS2020n");
}
//simVars
hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ID_AP, "PLANE ALTITUDE", "Feet");
//hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_ID_AP, "AIRSPEED TRUE", "Knots");
// Check simVars
hr = SimConnect_RequestDataOnSimObject(hSimConnect, REQUEST_AP_SETTINGS, DEFINITION_ID_AP, SIMCONNECT_OBJECT_ID_USER, SIMCONNECT_PERIOD_ONCE);
if (FAILED(hr))
{
printf("RequestDataOnSimObject for AutopilotData structure - errorn");
}
bRequestProcessed = false;
while (!bRequestProcessed)
{
hr = SimConnect_GetNextDispatch(hSimConnect, &pData, &cbData);
if (SUCCEEDED(hr))
{
pObjData = (SIMCONNECT_RECV_SIMOBJECT_DATA*)pData;
pDataRefs = (DataRefs*)&pObjData->dwData;
/* int altint;
altint = stoi (pDataRefs->altitude);
string str = "42";
int num2 = stoi(str);
cout << num2;
*/
/*
printf("rCurrent plane altitude: %.f feet", pDataRefs->altitude);
fflush(stdout);
*/
//This line of code is what im referring to
printf("rCurrent altitude: %.f feet", pDataRefs->altitude);
//printf("rCurrent speed: %.f knots", pDataRefs->knots);
}
}
// Close
hr = SimConnect_Close(hSimConnect);
return 0;
}
发现问题。如果您使用CTRL-F";hr=SimConnect_RequestDataOnSimObject(hSimConnect、REQUEST_AP_SETTINGS、DEFINITION _ID_AP、SimConnect_OBJECT_ID_USER、SimConnect _PERIOD_ONCE(&";,您可以看到我使用SIMCONNECT_PERIOD_ONCE。查看文档(https://www.prepar3d.com/SDKv4/sdk/simconnect_api/references/structures_and_enumerations.html),我将SIMCONNECT_PERIOD_ONCE替换为SIMCONNECT_PERIOD_SECOND以每秒更新一次。
相关文章:
- 从C++本机插件更新Vector3数组
- QGraphicsPolygonItem在拖动时未更新QPolygonF坐标
- C++:将控制台输出存储在宏中更好吗
- 在while循环中输入带有std::cin的字符串后,控制台会输出大量胡言乱语
- SSH通过/sbin/SSH无法读取RSA密钥文件(从控制台运行)
- cmake更新缓存的变量
- C++控制台应用程序阻止退出
- 如何修复此iFile以将.txt输出到控制台
- 为什么控制台要求输入,即使代码中没有输入
- 更新到莫哈韦后出现cmath错误
- OpenMP:并行更新数组总是需要减少数组吗
- 为什么我的变量没有更新,我的 LED 没有亮起?
- 指针没有更新它在void函数内部指向的值
- 如何在c++中获取要更新的值
- 已修改的LinkedList未在文本文件本身中更新
- 在Qt Creator中,如何在连接到正在运行的进程后查看控制台输出
- Qt:当QListView获得新条目时,如何更新QStringList
- 更新的矢量元素不打印
- 如何使用按钮更新GTK3图像以使用C++从相机捕获图片
- 更新在控制台 C++ 上打印的值