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

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

相关推荐
simple_whu9 分钟前
解决编译pcl时报错‘chrono_literals‘: is not a member of ‘std‘
c++·windows·visual studio
二狗哈12 分钟前
制作一款打飞机游戏20:敌人被击中时的视觉效果
游戏
二狗哈28 分钟前
制作一款打飞机游戏19:碰撞检测
数码相机·游戏
吴_知遇2 小时前
【华为OD机试真题】428、连续字母长度 | 机试真题+思路参考+代码解析(E卷)(C++)
开发语言·c++·华为od
LaoWaiHang3 小时前
MFC案例:使用键盘按键放大、缩小窗口图像的实验
c++·mfc
到底怎么取名字不会重复3 小时前
Day10——LeetCode15&560
c++·算法·leetcode·哈希算法·散列表
陈大大陈4 小时前
基于 C++ 的用户认证系统开发:从注册登录到Redis 缓存优化
java·linux·开发语言·数据结构·c++·算法·缓存
纪元A梦4 小时前
华为OD机试真题——通过软盘拷贝文件(2025A卷:200分)Java/python/JavaScript/C++/C语言/GO六种最佳实现
java·javascript·c++·python·华为od·go·华为od机试题
刚入坑的新人编程4 小时前
C++多态
开发语言·c++
QUST-Learn3D5 小时前
高精度并行2D圆弧拟合(C++)
开发语言·c++