获取剪切板有格式的数组


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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值