PumpMessage在VS2005中不起作用,找到下面的代码并给出你的建议 [英] PumpMessage is not working in VS2005 , Find the code below and give ur suggestion

查看:119
本文介绍了PumpMessage在VS2005中不起作用,找到下面的代码并给出你的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我开发了一个通过COM端口发送数据的应用程序(UART通信),所以为了输入数据我做了一个编辑框,当按下按钮时它会得到文本。



所以里面会有定时器,每25ms会更新一次,所以我的应用程序页面每25ms也刷新一次因此我只能在COM端口打开时才能删除编辑框中的字符...,不打开COM端口,如果我运行我的应用程序它正常工作并删除字符。



以下是在Visual Studio V6.0中适用于此问题的PumpMessage代码

但在VS 2005中,它无效。



Hi,

I have developed a application for sending a data through COM port(UART Communication), So for entering the data I have made one edit box ,It will get the text when the buttons are pressed.

So inside there will be timer which will be updating for every 25ms , so my application page also refreshing for every 25ms due to this I can't able to delete the characters in the edit box only when the COM port is open..., Without opening the COM port, If I run my application It is working fine and deleting characters.

The following is the PumpMessage code which is working fine for this issue in Visual Studio V6.0
But in VS 2005 , its not working.

void CUARTDlg::PumpMessages()
{
    ASSERT(m_hWnd != NULL);

    MSG msg;

    while(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
    {
        if(!IsDialogMessage(&msg))
        {
            TranslateMessage(&msg);

            DispatchMessage(&msg);
        }
    }
}







COM port .........






COM port.........

void CKB600LRUpreDlg::ClickDasSmartbutton64()
{
	/****************** DCB Settings *****************/
	DCB dcb;
	dcb.BaudRate = 115200;
	dcb.ByteSize = 8;
	dcb.StopBits = 1;
	dcb.Parity = 0;
	dcb.fParity         = 0;
	dcb.fOutxCtsFlow    = 0;
	dcb.fOutxDsrFlow    = 0;
	dcb.fDsrSensitivity = 0;
	dcb.fTXContinueOnXoff = FALSE;
	dcb.fOutX           = 0;
	dcb.fInX            = 0;
	dcb.fNull           = 0;
	dcb.fErrorChar      = 0;
	dcb.fAbortOnError   = 0;
	dcb.fRtsControl     = RTS_CONTROL_DISABLE;
	dcb.fDtrControl     = DTR_CONTROL_DISABLE;
	/****************** DCB Settings *****************/
	openPort(dcb,_T("COM2"));	//calling open port function.
	AfxMessageBox(_T("Port Opened Successfully "));
	tmr = SetTimer(ID_CLOCK_TIMER,20,NULL);
}
/************************************ End of CONNECT BUTTON ****************************/

/************************* OPEN PORT FUNCTION **********************/
BOOL CKB600LRUpreDlg::openPort(DCB dcb, CString portName)
{	
	hPort = CreateFile(_T("\\\\.\\COM2")/*portName*/,GENERIC_WRITE|GENERIC_READ,0,NULL,OPEN_EXISTING,0,NULL);
	if (GetCommState(hPort,&dcb) == 0)
	{
		AfxMessageBox(_T("Get configuration port has problem."));
		return FALSE;
	}
	if (SetCommState(hPort,&dcb) == 0)
	{
		AfxMessageBox(_T("Set configuration port has problem."));
		return FALSE;
	}

	/********Clear the port*****************/
	FlushFileBuffers( hPort );
	PurgeComm (hPort, PURGE_TXABORT | PURGE_RXABORT | PURGE_TXCLEAR | PURGE_RXCLEAR);
	COMSTAT     comStat;
	DWORD       dwErrorFlags;
	ClearCommError ( hPort, &dwErrorFlags, &comStat );
	/********Clear the port*****************/
	return FALSE;
}









清除。 .....







For Clear ......

void CKB600LRUpreDlg::ClickDasSmartbutton7()
{
    // TODO: Add your message handler code here


if(Shift == 0)
{


    int usCurPosS=0;

    int pos = 0;
    int istart = 0;
    int iend = 0;
    int &start = istart;
    int &end = iend;
    UpdateData(true);
    m_edit.GetSel(istart,iend);

    m_edit.GetSel(usCurPos,usCurPosS);
    if(istart == iend)
    {
        if (usCurPos==0)
        {

            AfxMessageBox(_T("No Text Has Selected , Please Select The Text "));
            m_edit.SetFocus();
            return;

        }
        UpdateData(true);
        m_edit.SetFocus();

        m_edit.GetSel(usCurPos,usCurPosS);

        m_edit.SetSel(usCurPos,usCurPos-1);

        UpdateData(false);

    }

    else
    {
        m_edit.SetSel(istart,iend);

    }



    UpdateData(false);


    m_edit.Clear();

    m_edit.SetFocus();


}

else
{
    int istart = 0;
    int iend = 0;
    int &start = istart;
    int &end = iend;
    UpdateData(true);
    m_edit.GetSel(istart,iend);
    m_edit.SetSel(0,iend);
    UpdateData(false);
    m_edit.Clear();
    m_edit.SetFocus();
    Shift=0;

}


}





For Key (按钮)A





For Key (Button) A

void CKB600LRUpreDlg::ClickDasSmartbutton2()
{
    // TODO: Add your message handler code here
    variable = 'B';
    function();
}










void CKB600LRUpreDlg::function()
{
    int length;
    m_edit.GetWindowText(m_TxtSamplingFrequency);
    // Check position; append if beyond the end
    if (usCurPos > m_edit.GetSel())
        usCurPos = m_edit.GetSel();
    // Insert character
    m_TxtSamplingFrequency.Insert(usCurPos, variable);
    // Set text
    m_edit.SetWindowText(m_TxtSamplingFrequency);
    // Set selection behind inserted char
    usCurPos++;
    m_edit.SetSel(usCurPos,usCurPos);
    length=m_TxtSamplingFrequency.GetLength();
    if(length>32)
    {
        AfxMessageBox(_T("Maximum Text Limit Reached "));

        m_edit.SetFocus();
        return;
    }


    m_edit.SetFocus();

}

推荐答案

这个概念被设计破坏:每25毫秒轮询并运行消息队列是更糟糕的是死锁而不是糟糕的设计(对不起:垃圾)



COM操作应该在没有GUI交互的自己的线程中运行。如果您有新数据通过用户消息与GUI通信并且函数



PostThreadMessage http://msdn.microsoft.com/en-us/library/windows/desktop/ms644946(v = vs.85)的.aspx [ ^ ]



更新GUI。
this concept is broken by design: polling every 25 ms and running the message queue is more a dead lock than bad design (Sorry: crap)

The COM operations should run in a own thread WITHOUT GUI interaction. If you have new data communicate with the GUI via user message and the function

PostThreadMessage http://msdn.microsoft.com/en-us/library/windows/desktop/ms644946(v=vs.85).aspx[^]

to update the GUI.


这篇关于PumpMessage在VS2005中不起作用,找到下面的代码并给出你的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆