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();
}

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

相关推荐
Johnstons24 分钟前
游戏网络测试怎么做?从延迟到丢包,一套完整的游戏弱网测试方案
网络·游戏·php
C路在脚下1 小时前
HSMS 连接总失败?排查这 5 个配置点
c++·嵌入式硬件
郝学胜_神的一滴1 小时前
Qt 高级编程 034:深耕QWidget底层内核—彻底吃透无边框窗口设计核心原理
c++·qt
QiLinkOS2 小时前
第三视觉理解徐玉生与他的商业活动(26)
大数据·c++·人工智能·算法·开源协议
chase_my_dream2 小时前
FAST-LIO src/IMU_Processing.hpp 完整详细讲解
c++·状态模式·slam
旖-旎3 小时前
《LeetCode 1137 第N个泰波那契数 和 LeetCode 三步问题》
c++·算法·leetcode·动态规划
c++之路3 小时前
C++跨平台(九):跨平台字节序统一处理
开发语言·arm开发·c++
ysa0510303 小时前
【并查集】判环,深搜
数据结构·c++·算法·深度优先
2023自学中5 小时前
imx6ull 开发板, mame 模拟器,运行游戏 测试
linux·游戏·嵌入式·开发板
weixin_423533995 小时前
c++类的继承学习-去中心化交易所(DEX)的“流动性池初始化与交易指令”设计
c++·学习·去中心化