程序在XP SP2系统上运行正常,在sp2以上版本就会出现,新建线程之后,窗口不能动的错误。新建的线程用于com port通讯。可以肯定的是错误与com port通讯无关。因为我是新手,加上是很久以前的程序,没有注释和文档比较少。我也是花了好多天的时间才找到问题。但是不知道怎么修改。我是再XP sp3上做debug,工具vs6.0.我贴上有问题的代码,希望大牛帮忙指点一下:if (m_eContConfig == EContConfCABAlone)
{
m_pMsgLayerThread = new CCAB2MessageLayerThread(m_hWnd);
ASSERT(NULL != m_pMsgLayerThread);// Create the Message Layer thread
bCreateThreadError = m_pMsgLayerThread->CreateThread();
}
else if ( (m_eContConfig == EContConfCAXAlone) ||
(m_eContConfig == EContConfEXCAlone) ||
(m_eContConfig == EContConfAUXAlone) )
{
m_eController = rmdutility.GetControllerFromConfiguration(m_eContConfig);
m_pDash8MsgLayerThread = new CCAXMessageLayerThread(m_hWnd, m_eController);
ASSERT(NULL != m_pDash8MsgLayerThread);// Create the Message Layer thread
  //问题出在这行,注释掉之后可以运行,但是创建线程是必须的
bCreateThreadError = m_pDash8MsgLayerThread->CreateThread();
}
新建线程之后运行到这个函数
BOOL CCAXMessageLayerThread::InitInstance()
{
CWnd* pParent = CWnd::FromHandle(m_hwndParent);
CRect rect;
pParent->GetClientRect(&rect);
BOOL m_bWindowSuccess = m_wndCAXMsgLayerWindow.Create(_T("CMsgLayerWindow"),
WS_CHILD, rect,pParent,m_eController);if (m_bWindowSuccess)
{
  //在保留CreateThread语句,运行到句,在语句前,我还可以通过m_pMainWnd对窗口进行隐藏等操作,赋值之后就没有作用了m_pMainWnd = &m_wndCAXMsgLayerWindow;
pParent->PostMessage(WM_WINDOW_CREATED,(WPARAM)m_wndCAXMsgLayerWindow.m_hWnd);
}return TRUE;
}不知道是什么问题,如果有MFC大牛,帮忙看一下。

解决方案 »

  1.   

    pParent->PostMessage这一句屏蔽了看看,或贴出响应此消息的代码看看
    可以在调试模式下运行 窗口不动的时候暂停下来看程序处在什么运行状态,堆栈 线程 模块都可以看到
      

  2.   


    谢谢你,我注释掉postMessage之后是运行正常的。
    我再调试模式调出堆栈一直都是unavailable。我想问一个小白问题,怎么在debug状态下查看线程状态
    多谢。我注释掉m_pMainWnd = &m_wndCAXMsgLayerWindow;这行之后运行正常了,但是我不知道这个有什么不良影响,我再另外一贴也贴了这个解释:
    // It is important to set CWinThread::m_pMainWnd to the user interface
    // window. This is required so that when the m_pMainWnd is destroyed,
    // the CWinThread is also automatically destroyed. For insight into
    // how the CWinThread is automatically destroyed when the m_pMainWnd
    // window is destroyed, see the implementation of CWnd::OnNcDestroy
    // in wincore.cpp of the MFC sources.但是我还是没有搞明白是哪里的问题所以在这里喊救命