Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6ee0043

Browse files
authoredJan 10, 2025··
Merge pull request #318 from Dn-Programming-Core-Management/fix-recent-files-nullptr
Match submenu item in Files menu instead of hardcoding indices
2 parents 95bdd63 + 4de0240 commit 6ee0043

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed
 

‎Source/FamiTracker.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,10 +451,24 @@ void CFamiTrackerApp::OnRecentFilesClear() // // //
451451
SAFE_RELEASE(m_pRecentFileList);
452452
m_pRecentFileList = new CRecentFileList(0, _T("Recent File List"), _T("File%d"), MAX_RECENT_FILES);
453453

454-
auto pMenu = m_pMainWnd->GetMenu()->GetSubMenu(0)->GetSubMenu(14);
455-
for (int i = 0; i < MAX_RECENT_FILES; ++i)
456-
pMenu->RemoveMenu(ID_FILE_MRU_FILE1 + i, MF_BYCOMMAND);
457-
pMenu->AppendMenu(MF_STRING, ID_FILE_MRU_FILE1, _T("(File)"));
454+
// Files menu
455+
auto pFilesMenu = m_pMainWnd->GetMenu()->GetSubMenu(0);
456+
457+
// Try and find Recent Files submenu
458+
for (int nPos = 0; nPos < pFilesMenu->GetMenuItemCount(); nPos++)
459+
// check if valid menu state
460+
if (pFilesMenu->GetMenuState(nPos, MF_BYPOSITION) != UINT(-1)) {
461+
// check if it has a submenu and the first item is ID_RECENTFILES_CLEAR
462+
auto pSubMenu = pFilesMenu->GetSubMenu(nPos);
463+
if (pSubMenu != nullptr && pSubMenu->GetMenuItemID(0) == ID_RECENTFILES_CLEAR) {
464+
for (int i = 0; i < MAX_RECENT_FILES; ++i)
465+
pSubMenu->RemoveMenu(ID_FILE_MRU_FILE1 + i, MF_BYCOMMAND);
466+
pSubMenu->AppendMenu(MF_STRING, ID_FILE_MRU_FILE1, _T("(File)"));
467+
return;
468+
}
469+
}
470+
471+
throw std::runtime_error("Could not find \"ID_RECENTFILES_CLEAR\"");
458472
}
459473

460474
void CFamiTrackerApp::OnUpdateRecentFiles(CCmdUI *pCmdUI) // // //

0 commit comments

Comments
 (0)
Please sign in to comment.