大家好:我写了一个窗口程序使用WM_CHAR向DOS窗口程序发送命令,在一部分DOS使用OK.但使用我们客户那DOS程序却不行.进行他的程序后,我发送的字符会丢失一部分,见上图:
请问大家是什么原因!
代码如下:void CSRT6880LockDlg::OnExecute() 
{
// TODO: Add your control notification handler code here CWnd   *pWnd=FindWindow((LPCTSTR)"ConsoleWindowClass",NULL);  //查找窗口是否存在,用SPY++看窗口类 
// ASSERT_VALID(pWnd);
if(pWnd==NULL)
{
AfxMessageBox("没有找到DOS窗口,将退出程序!");
PostMessage(WM_CLOSE,0,0);
} CString strTemp;
int nLineNumber;
UpdateData(1);
pEdit->EnableWindow(0); if(m_Inistr.IsEmpty())
AfxMessageBox("没有命令,请重新编辑命令!");
else
{
for(nLineNumber=0;nLineNumber<5;nLineNumber++)
{
pEdit->GetLine(nLineNumber,strTemp.GetBufferSetLength(pEdit->LineLength(pEdit->LineIndex(nLineNumber+1)-2*(nLineNumber+1)+1)));
strTemp.ReleaseBuffer();
if(!strTemp.IsEmpty())
{
sParameter_1=strTemp;
strTemp.Empty();
for(int b=0;b<sParameter_1.GetLength();b++)
{          
pWnd->ShowWindow(1);   //激活窗口
(),WM_KEYDOWN,sParameter_1.GetAt(b),0);
::SendMessage(pWnd->GetSafeHwnd(),WM_CHAR,sParameter_1.GetAt(b),0);   //发送消息   这里是字符D,要查找对应的virtualkey的值
(),WM_KEYUP,sParameter_1.GetAt(b),0);
}
sParameter_1.Empty();
// ::SendMessage(pWnd->GetSafeHwnd(),WM_KEYDOWN,'\r\n',0);
::SendMessage(pWnd->GetSafeHwnd(),WM_CHAR,'\r\n',0);
// ::SendMessage(pWnd->GetSafeHwnd(),WM_KEYUP,'\r\n',0);
}
}
}
}

解决方案 »

  1.   

    for(int b=0;b<sParameter_1.GetLength();b++)
    {                 
        pWnd->ShowWindow(1);   //激活窗口
        ::SendMessage(pWnd->GetSafeHwnd(),WM_CHAR,sParameter_1.GetAt(b),0);
        b++;   
    }
      

  2.   

    不行呀!这样连基本的DOS程序都能用!
      

  3.   


    CWnd   *pWnd=FindWindow((LPCTSTR)"ConsoleWindowClass",NULL);  //查找窗口是否存在,用SPY++看窗口类 
    //    ASSERT_VALID(pWnd);
        if(pWnd==NULL)
        {
            AfxMessageBox("没有找到DOS窗口,将退出程序!");
            PostMessage(WM_CLOSE,0,0);
        }

        CString strTemp=m_Inistr;
        int nLineNumber;
        UpdateData(1);
    if(m_Inistr.IsEmpty())
            AfxMessageBox("没有命令,请重新编辑命令!");
    pWnd->ShowWindow(1);

    for(int b=0;b<strTemp.GetLength();b++)
    {
    int ret=::SendMessage(pWnd->GetSafeHwnd(),WM_CHAR,strTemp.GetAt(b),0);   //发送消息   这里是字符D,要查找对应的virtualkey的值 }
    ::SendMessage(pWnd->GetSafeHwnd(),WM_CHAR,'\r\n',0);
    我自己写了个,测试成功
      

  4.   

    只是在某些DOS程序不行,象我们客户的这个程序里就不行,上面的代码有一两句不对,因为我不能重新编辑,再重发一次:void CSRT6880LockDlg::OnExecute() 
    {
    // TODO: Add your control notification handler code here CWnd   *pWnd=FindWindow((LPCTSTR)"ConsoleWindowClass",NULL);  //查找窗口是否存在,用SPY++看窗口类 
    // ASSERT_VALID(pWnd);
    if(pWnd==NULL)
    {
    AfxMessageBox("没有找到DOS窗口,将退出程序!");
    PostMessage(WM_CLOSE,0,0);
    } CString strTemp;
    int nLineNumber;
    UpdateData(1);
    pEdit->EnableWindow(0); if(m_Inistr.IsEmpty())
    AfxMessageBox("没有命令,请重新编辑命令!");
    else
    {
    for(nLineNumber=0;nLineNumber<5;nLineNumber++)
    {
    pEdit->GetLine(nLineNumber,strTemp.GetBufferSetLength(pEdit->LineLength(pEdit->LineIndex(nLineNumber+1)-2*(nLineNumber+1)+1)));
    strTemp.ReleaseBuffer();
    if(!strTemp.IsEmpty())
    {
    sParameter_1=strTemp;
    strTemp.Empty();
    for(int b=0;b<sParameter_1.GetLength();b++)
    {          
    pWnd->ShowWindow(1);   //激活窗口
    ::SendMessage(pWnd->GetSafeHwnd(),WM_CHAR,sParameter_1.GetAt(b),0);   //发送消息   这里是字符D,要查找对应的virtualkey的值

    }
    sParameter_1.Empty();
    ::SendMessage(pWnd->GetSafeHwnd(),WM_CHAR,'\r\n',0);
    }
    }
    }
    }
    我觉得是Unicode的问题,但不知怎么修改!
      

  5.   

    你这个工程是Unicode还是ANSI的?