0
我有一個MFC應用程序,其中有兩個菜單選項對應於兩個工具欄 - 菜單選項可以切換工具欄的可見性。如果工具欄當前可見,我需要檢查菜單選項。這是我到目前爲止:MFC - 檢查/取消選中菜單項
BEGIN_MESSAGE_MAP(CLevelPackEditApp, CWinAppEx)
// Standard file based document commands
ON_UPDATE_COMMAND_UI(ID_LEVEL_PROPERTIES, &CLevelPackEditApp::OnViewLevelProperties)
END_MESSAGE_MAP()
void CLevelPackEditApp::OnViewLevelProperties(CCmdUI* pCmdUI)
{
// Get a handle to the main window
CMainFrame* main = ((CMainFrame*)m_pMainWnd);
// Get a handle to the level properties toolbar for the main window
CLevelProperties* obj = main->GetLevelProperties();
if (obj->IsWindowVisible())
{
pCmdUI->SetCheck(0);
obj->ShowPane(false, false, false);
} else {
pCmdUI->SetCheck();
obj->ShowPane(true, false, true);
}
}
它的工作....有點。它在選中狀態和未選中狀態之間切換,但是它每秒執行多次 - 我懷疑檢查菜單項會導致菜單更新,所以它沒有被選中,所以它會更新,所以它會被檢查,aaaannnd和重複。我怎樣才能解決這個問題?
我把這個放在我的代碼中,但是由於某種原因,OnUpdateLevelProperties從來沒有被調用過。 –
Nvm,我犯了一個愚蠢的錯誤。 –