void GetClipboardStr(BSTR *o_pbsText)
{
CString strText;
if (IsClipboardFormatAvailable(CF_UNICODETEXT))
{
OpenClipboard(NULL);
if (IsClipboardFormatAvailable(CF_UNICODETEXT))
{
HANDLE hGlobal = GetClipboardData(CF_UNICODETEXT);
strText = (LPCTSTR)GlobalLock(hGlobal);
GlobalUnlock(hGlobal);
}
CloseClipboard();
}
*o_pbsText = strText.AllocSysString();;
}
void GetFormatData(BSTR i_bsText, vector<double> &o_vFormatData)
{
o_vFormatData.clear();
CString sText((LPCTSTR)i_bsText);
int i(0);
while (!sText.IsEmpty())
{
// 数据分隔符
CString sDiv;
if (i % 2 == 0)
{
int iDot(0), iTab(0);
iDot = sText.Find(_T(","));
iTab = sText.Find(_T("\t"));
if (-1 != iDot && -1 != iTab)
{
if (iDot < iTab)
sDiv.Format(_T(","));
else
sDiv.Format(_T("\t"));
}
else if (-1 != sText.Find(_T(",")))
sDiv.Format(_T(","));
else
sDiv.Format(_T("\t"));
}
else
sDiv.Format(_T("\r\n"));
// 获取当前数据
CString sCurData;
int iPos = sText.Find(sDiv);
if (-1 == iPos)
{
if (sText.SpanIncluding(_T("+-.0123456789")) != sText) // 有时候最后一个数据不包含分隔符
{
o_vFormatData.clear();
return;
}
o_vFormatData.push_back(_ttof(sText));
return;
}
else
sCurData = sText.Left(iPos);
// 判断当前数据是否正确
if (sCurData.SpanIncluding(_T("+-.0123456789")) != sCurData)
{
o_vFormatData.clear();
return;
}
o_vFormatData.push_back(_ttof(sCurData));
int nCount = sText.GetLength() - iPos - (i % 2 ? 2 : 1);
sText = sText.Right(nCount);
i++;
}
if (o_vFormatData.size() % 2)
o_vFormatData.clear();
return;
}
获取剪切板有格式的数组
最新推荐文章于 2023-08-28 14:48:38 发布