mirror of
https://github.com/yuanyuanxiang/SimpleRemoter.git
synced 2026-01-21 15:03:09 +08:00
fix: #288 Command line issues
This commit is contained in:
@@ -124,8 +124,10 @@ DWORD WINAPI CShellManager::ReadPipeThread(LPVOID lParam)
|
||||
#ifdef _DEBUG
|
||||
Mprintf("===> Input length= %d \n", This->m_nCmdLength);
|
||||
#endif
|
||||
const char *pStart = (char*)szTotalBuffer + This->m_nCmdLength;
|
||||
int length = int(dwReturn) - This->m_nCmdLength;
|
||||
int skipBytes = min(This->m_nCmdLength, (int)dwReturn);
|
||||
const char *pStart = (char*)szTotalBuffer + skipBytes;
|
||||
int length = (int)dwReturn - skipBytes;
|
||||
This->m_nCmdLength -= skipBytes;
|
||||
if (length > 0)
|
||||
This->m_ClientObject->Send2Server(pStart, length);
|
||||
|
||||
|
||||
@@ -14,9 +14,15 @@ END_MESSAGE_MAP()
|
||||
|
||||
void CAutoEndEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
|
||||
{
|
||||
// 将光标移动到文本末尾
|
||||
int nLength = GetWindowTextLength();
|
||||
SetSel(nLength, nLength);
|
||||
// 获取当前光标位置
|
||||
int nStart, nEnd;
|
||||
GetSel(nStart, nEnd);
|
||||
|
||||
// 如果光标在最小可编辑位置之前,移动到末尾
|
||||
if (nStart < (int)m_nMinEditPos) {
|
||||
int nLength = GetWindowTextLength();
|
||||
SetSel(nLength, nLength);
|
||||
}
|
||||
|
||||
// 调用父类处理输入字符
|
||||
CEdit::OnChar(nChar, nRepCnt, nFlags);
|
||||
@@ -70,6 +76,7 @@ BOOL CShellDlg::OnInitDialog()
|
||||
m_Edit.SetWindowTextA(">>");
|
||||
m_nCurSel = m_Edit.GetWindowTextLengthA();
|
||||
m_nReceiveLength = m_nCurSel;
|
||||
m_Edit.m_nMinEditPos = m_nReceiveLength; // 设置最小可编辑位置
|
||||
m_Edit.SetSel((int)m_nCurSel, (int)m_nCurSel);
|
||||
m_Edit.PostMessage(EM_SETSEL, m_nCurSel, m_nCurSel);
|
||||
m_Edit.SetLimitText(EDIT_MAXLENGTH);
|
||||
@@ -87,6 +94,7 @@ VOID CShellDlg::OnReceiveComplete()
|
||||
|
||||
AddKeyBoardData();
|
||||
m_nReceiveLength = m_Edit.GetWindowTextLength();
|
||||
m_Edit.m_nMinEditPos = m_nReceiveLength; // 更新最小可编辑位置
|
||||
}
|
||||
|
||||
|
||||
@@ -197,6 +205,7 @@ BOOL CShellDlg::PreTranslateMessage(MSG* pMsg)
|
||||
m_Edit.SetWindowTextA(str);
|
||||
m_nCurSel = m_Edit.GetWindowTextLength();
|
||||
m_nReceiveLength = m_nCurSel;
|
||||
m_Edit.m_nMinEditPos = m_nReceiveLength; // 更新最小可编辑位置
|
||||
m_Edit.SetSel(m_nCurSel, m_nCurSel);
|
||||
return TRUE;
|
||||
}
|
||||
@@ -209,8 +218,22 @@ BOOL CShellDlg::PreTranslateMessage(MSG* pMsg)
|
||||
if (m_Edit.GetWindowTextLength() <= m_nReceiveLength)
|
||||
return true;
|
||||
}
|
||||
// 示例:
|
||||
//dir\r\n 5
|
||||
// 限制VK_LEFT - 不能移动到历史输出区域
|
||||
if (pMsg->wParam == VK_LEFT && pMsg->hwnd == m_Edit.m_hWnd) {
|
||||
int nStart, nEnd;
|
||||
m_Edit.GetSel(nStart, nEnd);
|
||||
if (nStart <= (int)m_nReceiveLength)
|
||||
return true;
|
||||
}
|
||||
// 限制VK_UP - 禁止向上移动到历史输出
|
||||
if (pMsg->wParam == VK_UP && pMsg->hwnd == m_Edit.m_hWnd) {
|
||||
return true;
|
||||
}
|
||||
// 限制VK_HOME - 移动到当前命令行开始位置而不是文本开头
|
||||
if (pMsg->wParam == VK_HOME && pMsg->hwnd == m_Edit.m_hWnd) {
|
||||
m_Edit.SetSel((int)m_nReceiveLength, (int)m_nReceiveLength);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return CDialog::PreTranslateMessage(pMsg);
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
#include "IOCPServer.h"
|
||||
#include "afxwin.h"
|
||||
|
||||
// 无论光标位置在哪,新输入的文字总是出现在文本末尾
|
||||
// 限制光标不能移动到历史输出区域,只能在当前命令行内编辑
|
||||
class CAutoEndEdit : public CEdit
|
||||
{
|
||||
public:
|
||||
CAutoEndEdit() : m_nMinEditPos(0) {}
|
||||
UINT m_nMinEditPos; // 最小可编辑位置(历史输出的末尾)
|
||||
afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);
|
||||
DECLARE_MESSAGE_MAP()
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user