在cygwin64做实验呢, 用VSCODE自己加的cygwin64的启动命令行作为控制台.
如果是一个比较长的windows路径, 输入起来真的烦.
做了一个就几句代码的小工具, 让输入路径时, 可以从工具上拷贝到VSCode中的cygwin64命令行.
做完之后, 用了一下, 比纯手工输入方便多了.
void CCygwin64ToolsDlg::OnBnClickedButtonPathnameWinToCygwin64()
{
this->UpdateData(TRUE);
CString csTmp = this->m_csWinPathName;
csTmp.Replace(_T('\\'), _T('/'));
// csTmp.Replace(_T(':'), _T('\\'));
csTmp.Remove(_T(':'));
this->m_csCygwin64PathName = _T("/cygdrive/");
m_csCygwin64PathName += csTmp;
this->UpdateData(FALSE);
}
void CCygwin64ToolsDlg::OnBnClickedButtonPathnameWinToCygwin65Copy()
{
this->UpdateData(TRUE);
CopyTextToClipboard(m_csCygwin64PathName);
}
BOOL CCygwin64ToolsDlg::CopyTextToClipboard(CString cs)
{
BOOL b_rc = FALSE;
LPTSTR lptstrCopy = NULL;
HGLOBAL hglbCopy = NULL;
HANDLE h1 = NULL;
do {
// ::CloseClipboard();
if (!::OpenClipboard(NULL))
{
break;
}
::EmptyClipboard();
hglbCopy = ::GlobalAlloc(GMEM_MOVEABLE, (cs.GetLength() + 1) * sizeof(TCHAR));
if (NULL == hglbCopy)
{
break;
}
// Lock the handle and copy the text to the buffer.
lptstrCopy = (LPTSTR)::GlobalLock(hglbCopy);
memcpy(lptstrCopy, cs.GetBuffer(), cs.GetLength() * sizeof(TCHAR));
lptstrCopy[cs.GetLength() * sizeof(TCHAR)] = (TCHAR)0; // null character
::GlobalUnlock(hglbCopy);
// Place the handle on the clipboard.
// 如果要拷贝的是WCHAR, 却设置为CF_TEXT, 粘贴时, 只能粘贴第1个字符
h1 = ::SetClipboardData(CF_UNICODETEXT /*CF_TEXT*/, hglbCopy);
if (NULL == h1)
{
break;
}
b_rc = TRUE;
} while (false);
if (NULL != hglbCopy)
{
GlobalFree(hglbCopy);
}
::CloseClipboard();
return b_rc;
}