mfc剪切板总结

 

HANDLE SetClipboardData(

UINT uFormat,

HANDLE hMem);

Parameters

格式:

[in] Unsigned integer that specifies a clipboard format. This parameter can be a registered format or any of the standard clipboard formats. Windows CE supports the following standard clipboard:

Value

Description

CF_BITMAP

A handle to a bitmap (HBITMAP).

CF_DIB

A memory object containing a BITMAPINFO structure followed by the bitmap bits.

CF_DIF

Software Arts' Data Interchange Format.

CF_PALETTE

[参见MSDN]

CF_PENDATA

Data for the pen extensions to the Microsoft® Windows® for Pen Computing.

CF_RIFF

Represents audio data more complex than can be represented in a CF_WAVE standard wave format.

CF_SYLK

Microsoft Symbolic Link (SYLK) format.

CF_TEXT

Tex

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
可能是因为剪切板中的数据以不同的编码格式存储而导致乱码。为了解决这个问题,可以尝试以下方法: 1. 获取剪切板数据时指定编码格式 在获取剪切板数据时,可以指定编码格式,例如: ```c++ if (IsClipboardFormatAvailable(CF_TEXT)) { if (OpenClipboard()) { HGLOBAL hglb = GetClipboardData(CF_TEXT); if (hglb != NULL) { LPSTR lpstr = (LPSTR)GlobalLock(hglb); if (lpstr != NULL) { // 指定编码格式 std::string str = (const char*)lpstr; std::wstring wstr = utf8_to_wstring(str); // 使用 wstr GlobalUnlock(hglb); } } CloseClipboard(); } } ``` 这里使用了一个 `utf8_to_wstring` 函数将 UTF-8 编码的字符串转换为宽字符字符串,可以根据实际情况选择其他编码格式。 2. 统一编码格式 另一种方法是在程序内部将所有剪切板数据都统一转换为相同的编码格式。例如,可以将所有数据都转换成 UTF-8 编码,然后在程序中使用 UTF-8 编码的字符串。 ```c++ if (OpenClipboard()) { std::string strData; HANDLE hData = NULL; char* pBuf = NULL; // 获取 CF_UNICODETEXT 格式的数据 hData = GetClipboardData(CF_UNICODETEXT); if (hData) { // 转换为 UTF-8 编码的字符串 pBuf = (char*)GlobalLock(hData); if (pBuf) { std::wstring wstr = (const wchar_t*)pBuf; strData = wstring_to_utf8(wstr); GlobalUnlock(hData); } } // 处理 strData // ... CloseClipboard(); } ``` 这里使用了一个 `wstring_to_utf8` 函数将宽字符字符串转换为 UTF-8 编码的字符串,也可以根据实际情况选择其他编码格式。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值