上一个内容:30.保存游戏配置到文件
以 30.保存游戏配置到文件 它的代码为基础进行修改
效果图:
加载配置文件到列表的函数:
void CWndINJ::LoadGame()
{int count = GetPrivateProfileInt(L"main", L"count", 0, GameIni);for (int i = 0; i < count; i++) {CString GameName, GameExe, GamePath, GameCmds, GameDlls, _AppName;_AppName.Format(L"count_%d", i+1);wchar_t wRead[0xFF];GetPrivateProfileString(_AppName, L"GameName", L"", wRead, 0xFF, GameIni);GameName.Format(L"%s", wRead);GetPrivateProfileString(_AppName, L"GamePath", L"", wRead, 0xFF, GameIni);GameExe.Format(L"%s", wRead);GetPrivateProfileString(_AppName, L"GameFullPath", L"", wRead, 0xFF, GameIni);GamePath.Format(L"%s", wRead);GetPrivateProfileString(_AppName, L"GameCmds", L"", wRead, 0xFF, GameIni);GameCmds.Format(L"%s", wRead);GetPrivateProfileString(_AppName, L"GameDlls", L"", wRead, 0xFF, GameIni);GameDlls.Format(L"%s", wRead);ExeLst.InsertItem(i, GameName);ExeLst.SetItemText(i, 1, GameExe);ExeLst.SetItemText(i, 2, GamePath);ExeLst.SetItemText(i, 3, GameCmds);ExeLst.SetItemText(i, 4, GameCmds);}
}
确定添加按钮点击事件函数修改:
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);int iCount = ExeLst.GetItemCount();ExeLst.InsertItem(iCount, GameName);ExeLst.SetItemText(iCount, 1, GamePath);ExeLst.SetItemText(iCount, 2, GameFullPath);ExeLst.SetItemText(iCount, 3, GameCmds);ExeLst.SetItemText(iCount, 4, DllPath);}
列表自适应大小:
首先设置主窗口可变大小
添加WM_SIZE事件
代码实现:
if (nType == 1 || !mTab)return;CRect rect;GetClientRect(&rect);rect.top += 50;rect.left += 50;rect.bottom += 10;rect.right += 10;for (int i = 0; i < CurPage; i++) {if (Pages[i]) {Pages[i]->MoveWindow(&rect);}}
如果到这列表还没实现自适应大小:看一下列表的调整大小类型属性是不是两者