30.保存游戏配置到文件

上一个内容:29.添加录入注入信息界面

29.添加录入注入信息界面 它的代码为基础进行修改

效果图:

首先在我们辅助程序所在目录下创建一个ini文件

文件内容

然后首先编写一个获取辅助程序路径的代码

cpp 复制代码
TCHAR FileModule[0x100]{};
    GetModuleFileName(NULL, FileModule, 0x100);
    int i;
    for (i = 0x100 - 1; FileModule[i] != '\\'; i--)
        FileModule[i] = 0;
    wAppPath.Format(L"%s", FileModule);

然后在需要路径的子页面写一个接收路径的函数

函数具体实现:

cpp 复制代码
void CWndINJ::Init(CString& _AppPath)
{
    AppPath = _AppPath;
    GameIni.Format(L"%s\\config\\Games.ini", AppPath);
}

要保存的游戏信息在CWndAddGame类里,所以要在CWndAddGame类中创建一个可以给父窗口返回值的函数,也就是利用父窗口对象的this调用父窗口的函数

cpp 复制代码
void CWndAddGame::Init(void* _father)
{
    father = _father;
}

父窗口用来保存游戏数据的地方

cpp 复制代码
void CWndINJ::AddGame(CString& GameName, CString& GamePath, CString& GameFullPath, CString& GameCmds, CString& DllPath)
{
    int count = GetPrivateProfileInt(L"main", L"count", 0, GameIni);
    count++;
    CString key;
    key.Format(L"count_%d", count);
    WritePrivateProfileString(key, L"GameName", GameName, GameIni);
    WritePrivateProfileString(key, L"GamePath", GamePath, GameIni);
    WritePrivateProfileString(key, L"GameFullPath", GameFullPath, GameIni);
    WritePrivateProfileString(key, L"GameCmds", GameCmds, GameIni);
    WritePrivateProfileString(key, L"DllPath", DllPath, GameIni);

    CString wCount;
    wCount.Format(L"%d", count);
    WritePrivateProfileString(L"main", L"count", wCount, GameIni);
}

给调用给父窗口传值的函数的地方

cpp 复制代码
void CWndAddGame::OnBnClickedButton3()
{
    CWndINJ* p = (CWndINJ*)father;
    UpdateData(TRUE);
    p->AddGame(GameName, GamePath, GameFullPath, GameCmds, DllPath);
    CDialog::OnCancel();
}

主窗口给子窗口传递路径的地方

相关推荐
杜子不疼.5 小时前
【C++ AI 大模型接入 SDK】 - DeepSeek 模型接入(上)
开发语言·c++·chatgpt
石山代码6 小时前
C++ 内存分区 堆区
java·开发语言·c++
richard_yuu8 小时前
鸿蒙治愈游戏模块实战|四大轻量解压游戏、ArkTS动画交互与低功耗落地
游戏·交互·harmonyos
魔法阵维护师8 小时前
从零开发游戏需要学习的c#模块,第十四章(保存和加载)
学习·游戏·c#
张小姐的猫8 小时前
【Linux】多线程 —— 线程互斥
linux·运维·服务器·c++
做人求其滴11 小时前
面试经典 150 题 380 274
c++·算法·面试·职场和发展·力扣
见叶之秋11 小时前
C++基础入门指南
开发语言·c++
计算机安禾11 小时前
【c++面向对象编程】第42篇:模板特化与偏特化:为特定类型定制实现
开发语言·c++·算法
玖釉-11 小时前
C++ 中的循环语句详解:while、do...while、for、嵌套循环与循环控制
开发语言·c++·算法
2301_7807896612 小时前
手游遇到攻击为什么要用SDK游戏盾手游遇到攻击为什么要用 SDK 游戏盾?
安全·web安全·游戏·架构·kubernetes·ddos