框架字自动生成的mdi程序。在属性窗口ComboBox选这一个下拉项目时,下面函数收到消息。在这个函数里面调用AfxMessageBox(_T("test"))出错。
如果只是改变TextBox的数据,不会出错,MessageBox正常显示。LRESULT CPropertiesWnd::OnPropertyChanged (WPARAM wpAram,LPARAM lParam)
{
UINT uID = (UINT)wpAram;
AfxMessageBox(_T("test")); //调用这个函数出错。
return 0;
}试来试去,发现和编译环境有关。1, 在共享DLL中使用MFC,使用unicode字符集//这个库文件afxtls.cpp
// special version of CThreadSlotData::GetData that only works with
// thread local storage (and not process local storage)
// this version is inlined and simplified for speed
inline void* CThreadSlotData::GetThreadValue(int nSlot)
{
EnterCriticalSection(&m_sect);
ASSERT(nSlot != 0 && nSlot < m_nMax);
ASSERT(m_pSlotData != NULL);
ASSERT(m_pSlotData[nSlot].dwFlags & SLOT_USED);
ASSERT(m_tlsIndex != (DWORD)-1);
if( nSlot <= 0 || nSlot >= m_nMax ) // check for retail builds.
{
LeaveCriticalSection(&m_sect);
return NULL;
} CThreadData* pData = (CThreadData*)TlsGetValue(m_tlsIndex);
if (pData == NULL || nSlot >= pData->nCount)
{
LeaveCriticalSection(&m_sect);
return NULL;
}
void* pRetVal = pData->pData[nSlot];
LeaveCriticalSection(&m_sect);
return pRetVal; //vs在这里断下。
}
2, 字符集:未设置; 不管是共享DLL使用MFC还是静态库MFC。 都在同一个地方报错。
//这个库文件wincore.cpp
/////////////////////////////////////////////////////////////////////////////
// Default CWnd implementationLRESULT CWnd::DefWindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam)
{
if (m_pfnSuper != NULL)
return ::CallWindowProc(m_pfnSuper, m_hWnd, nMsg, wParam, lParam); //vs在这里断下。 WNDPROC pfnWndProc;
if ((pfnWndProc = *GetSuperWndProcAddr()) == NULL)
return ::DefWindowProc(m_hWnd, nMsg, wParam, lParam);
else
return ::CallWindowProc(pfnWndProc, m_hWnd, nMsg, wParam, lParam);
}
3, 静态库中使用MFC,使用unicode字符集。这个正常。
如果非用unicode每碰到一个字符串就要输入 _T(...) ,好烦琐啊。
如果只是改变TextBox的数据,不会出错,MessageBox正常显示。LRESULT CPropertiesWnd::OnPropertyChanged (WPARAM wpAram,LPARAM lParam)
{
UINT uID = (UINT)wpAram;
AfxMessageBox(_T("test")); //调用这个函数出错。
return 0;
}试来试去,发现和编译环境有关。1, 在共享DLL中使用MFC,使用unicode字符集//这个库文件afxtls.cpp
// special version of CThreadSlotData::GetData that only works with
// thread local storage (and not process local storage)
// this version is inlined and simplified for speed
inline void* CThreadSlotData::GetThreadValue(int nSlot)
{
EnterCriticalSection(&m_sect);
ASSERT(nSlot != 0 && nSlot < m_nMax);
ASSERT(m_pSlotData != NULL);
ASSERT(m_pSlotData[nSlot].dwFlags & SLOT_USED);
ASSERT(m_tlsIndex != (DWORD)-1);
if( nSlot <= 0 || nSlot >= m_nMax ) // check for retail builds.
{
LeaveCriticalSection(&m_sect);
return NULL;
} CThreadData* pData = (CThreadData*)TlsGetValue(m_tlsIndex);
if (pData == NULL || nSlot >= pData->nCount)
{
LeaveCriticalSection(&m_sect);
return NULL;
}
void* pRetVal = pData->pData[nSlot];
LeaveCriticalSection(&m_sect);
return pRetVal; //vs在这里断下。
}
2, 字符集:未设置; 不管是共享DLL使用MFC还是静态库MFC。 都在同一个地方报错。
//这个库文件wincore.cpp
/////////////////////////////////////////////////////////////////////////////
// Default CWnd implementationLRESULT CWnd::DefWindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam)
{
if (m_pfnSuper != NULL)
return ::CallWindowProc(m_pfnSuper, m_hWnd, nMsg, wParam, lParam); //vs在这里断下。 WNDPROC pfnWndProc;
if ((pfnWndProc = *GetSuperWndProcAddr()) == NULL)
return ::DefWindowProc(m_hWnd, nMsg, wParam, lParam);
else
return ::CallWindowProc(pfnWndProc, m_hWnd, nMsg, wParam, lParam);
}
3, 静态库中使用MFC,使用unicode字符集。这个正常。
如果非用unicode每碰到一个字符串就要输入 _T(...) ,好烦琐啊。
解决方案 »
- vs2005在调试MFC的程序时,经常会莫名无法响应,任务管理器也打不开,只能注销或重启,vc6.0在我机子上也这样,请教原因
- CTree控件的使用问题
- 续 不知道为什么怎么定义了这么多的记录集?----亟待回音
- 请问在简单文档中,哪里调用销毁窗口?
- 为何给About对话框添加OnCreate函数后,打开About对话框就异常?我并未添加代
- 相做一个这样的界面[附图],初学,不太知道怎么下手。
- 如何编程判断字符串A是否是字符串B的一部分
- 请教:在创建DLL工程中,.odl中的东东是什么意思,有什么作用!
- 谁知道在ISAPI中是否支持UNICODE?
- 低手高分求教,TC++3.0如何安装?
- CListView显示为什么不正常?
- _set_invalid_parameter_handler没有起作用,为什么?
1,重载CMFCPropertyGridProperty::OnUpdateValue(),避免调用CMFCPropertyGridCtrl::OnPropertyChanged发送AFX_WM_PROPERTY_CHANGED给主窗口,通过其他方式交给主窗口。2,OnPropertyChanged收到消息之后,不要处理,用PostMessage转发给其他窗口处理。
除非另有线程偷偷改变属性窗口的项,否则PosMessage接收到的CMFCPropertyGridProperty指针还是有效的。