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

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

相关推荐
Hard but lovely5 分钟前
C++---》stl : pair 从使用到模拟实现
c++·后端
林中青木33 分钟前
读写INI文件源码(点击关注)
c++·ini文件读取
running thunderbolt1 小时前
项目---网络通信组件JsonRpc
linux·服务器·c语言·开发语言·网络·c++·性能优化
青岛少儿编程-王老师1 小时前
CCF编程能力等级认证GESP—C++6级—20250927
java·c++·算法
ajassi20002 小时前
开源 C++ QT QML 开发(十)通讯--串口
c++·qt·开源
Janspran2 小时前
监控系统2 - framebuffer
c++
代码AC不AC2 小时前
【C++】AVL树的模拟实现
c++·avl树·底层原理
_w_z_j_3 小时前
C++----bitmap位图的使用
开发语言·c++
BingeBlog3 小时前
[01] Qt的UI框架选择和对比
开发语言·c++·笔记·qt·ui·开源软件
greentea_20133 小时前
Codeforces Round 173 B. Digits(2043)
c++·算法