问题描述
我在无模型弹出对话框树控件中有此事件处理程序:
void CAssignHistoryDlg::OnTvnSelchangedTreeHistory(NMHDR *pNMHDR,LRESULT *pResult)
{
LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
if (!m_bBuildTreeMode)
{
if ((pNMTreeView->itemOld.hItem == nullptr && !m_bFirstSelChangeEvent) ||
pNMTreeView->itemOld.hItem != nullptr)
{
m_bFirstSelChangeEvent = true;
if (m_treeHistory.GetParentItem(pNMTreeView->itemNew.hItem) == nullptr)
{
// We must update the correct combo
// and associated string (in the SERVMEET_S structure)
if (m_pCombo != nullptr && m_pStrText != nullptr)
{
CString strExtractedName = ExtractName(pNMTreeView->itemNew.hItem);
m_pCombo->SetWindowText(strExtractedName);
*m_pStrText = strExtractedName;
}
GetParent()->PostMessage(UM_SM_EDITOR_SET_MODIFIED,(WPARAM)TRUE);
}
}
}
*pResult = 0;
}
我不明白的是,为什么一旦触发此事件,它就会连续发生。
有什么事冒犯你吗?
解决方法
我不知道为什么消息似乎是连续不断的。可能是因为我要插入断点或添加临时弹出消息框进行调试。无论哪种方式,我都会做出我需要的细微调整:
void CAssignHistoryDlg::OnTvnSelchangedTreeHistory(NMHDR *pNMHDR,LRESULT *pResult)
{
LPNMTREEVIEW pNMTreeView = reinterpret_cast<LPNMTREEVIEW>(pNMHDR);
if (!m_bBuildTreeMode)
{
if ((pNMTreeView->itemOld.hItem == nullptr && !m_bFirstSelChangeEvent) ||
pNMTreeView->itemOld.hItem != nullptr)
{
m_bFirstSelChangeEvent = true;
if (m_treeHistory.GetParentItem(pNMTreeView->itemNew.hItem) == nullptr)
{
// We must update the correct combo
// and associated string (in the SERVMEET_S structure)
if (m_pCombo != nullptr && m_pStrText != nullptr)
{
CString strExtractedName = ExtractName(pNMTreeView->itemNew.hItem);
m_pCombo->SetWindowText(strExtractedName);
// Bug fix - Only set as modified if the name is different
if(*m_pStrText != strExtractedName)
GetParent()->PostMessage(UM_SM_EDITOR_SET_MODIFIED,(WPARAM)TRUE);
*m_pStrText = strExtractedName;
}
}
}
}
*pResult = 0;
}
如您所见,我已经更改了发布UM_SM_EDITOR_SET_MODIFIED
消息的方式和位置。这导致我的应用程序正常工作。以前,它总是将其设置为已修改(多次)。因此,即使您刚刚保存了文件,该文件也会被再次标记为已修改。此问题不再发生。