大家好:我写了一个窗口程序使用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);
}
}
}
}
请问大家是什么原因!
代码如下: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);
}
}
}
}
{
pWnd->ShowWindow(1); //激活窗口
::SendMessage(pWnd->GetSafeHwnd(),WM_CHAR,sParameter_1.GetAt(b),0);
b++;
}
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);
我自己写了个,测试成功
{
// 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的问题,但不知怎么修改!