代码如下:
HANDLE hClip;
CString str;
str = "中国";
if(OpenClipboard())
{
EmptyClipboard();
hClip=GlobalAlloc(GMEM_MOVEABLE,str.GetLength()+1);
char *pData=(char*)GlobalLock(hClip);
strcpy(pData,(const char*)str);
GlobalUnlock(hClip);
SetClipboardData(CF_TEXT,hClip);
CloseClipboard();
}
从剪贴板拷贝到记事本,word下中文就乱码,而拷贝
到ultraedit,以及vc下文本编辑环境就不是乱码,看到“中国”,
如何解决亚!!多谢给分!!
HANDLE hClip;
CString str;
str = "中国";
if(OpenClipboard())
{
EmptyClipboard();
hClip=GlobalAlloc(GMEM_MOVEABLE,str.GetLength()+1);
char *pData=(char*)GlobalLock(hClip);
strcpy(pData,(const char*)str);
GlobalUnlock(hClip);
SetClipboardData(CF_TEXT,hClip);
CloseClipboard();
}
从剪贴板拷贝到记事本,word下中文就乱码,而拷贝
到ultraedit,以及vc下文本编辑环境就不是乱码,看到“中国”,
如何解决亚!!多谢给分!!
拷贝到word,记事本都能看见"中国"
CString str;
str =_T("中国");
if(::OpenClipboard(NULL))
{
EmptyClipboard();
hClip=GlobalAlloc(GMEM_MOVEABLE,str.GetLength()+1);
char *pData=(char*)GlobalLock(hClip);
strcpy(pData,(const char*)str);
GlobalUnlock(hClip);
SetClipboardData(CF_TEXT,hClip);
CloseClipboard();
}
str =_T("中国");
str = "中国";
也没问题了
_UNICODE不能编译成功CF_OEMTEXT Text format containing characters in the OEM character set. Each line ends with a carriage return/linefeed (CR-LF) combination. A null character signals the end of the data. CF_UNICODETEXT Windows NT/2000/XP: Unicode text format. Each line ends with a carriage return/linefeed (CR-LF) combination. A null character signals the end of the data. CF_TEXT Text format. Each line ends with a carriage return/linefeed (CR-LF) combination. A null character signals the end of the data. Use this format for ANSI text.
能找到的下面是试验的一些
#include "stdafx.h"
#include "atlstr.h"
int _tmain(int argc, _TCHAR* argv[])
{
HANDLE hClip;
CString str;
str = "\3";
if(::OpenClipboard(NULL))
{
EmptyClipboard();
hClip=GlobalAlloc(GMEM_MOVEABLE,str.GetLength()+1);
char *pData=(char*)GlobalLock(hClip);
//memset(pData,0,str.GetLength()+1);
str.AnsiToOem();
strcpy(pData,(const char*)str);
GlobalUnlock(hClip);
SetClipboardData(CF_TEXT,hClip);
CloseClipboard();
}
printf("%s",str);
return 0;
}就字符集有些差异 原来前几天找心型的在OEM字符集
我只是告诉他是控制符,可以显示,可能是任意的
那位朋友对不住了
有兴趣的
UP
1,你可以把中文输入法设置为默认的输入法,再运行你的代码,肯定不会乱码的,但这种方法太笨了,不可能要求客户这样的嘛,对不对?所以要看方法2,这个方法仅作为测试之用,测试成功,记得给分。
2,根据上面的情况,可以只要是中文输入法环境下复制中文就没有问题,那么我们可以调用API把输入法选择为中文输入法(任一皆可,拼音五笔都没有问题)。复制之后再用API设置为原来的输入法。Copy到某一程序的时候,那个程序可以是任意输入法的。这两三个API为IME开头的什么keyboardlayout的函数,你google一下,找到这样的函数名再去MSDN看看用法,很快就解决了。好了,打得好累,记得给分啊。