vc 剪切板 unicode

 1 void FChartControl::CopyGridData()
2
3 {
4
5 if (m_bShowGrid)
6
7 {
8
9 CString csData = m_csHLable + _T("\n");
10
11 int len=m_listCtrl.GetItemCount();//取行数
12
13
14
15 for(int i=0;i<len;i++)
16
17 {
18
19 CString csRow;
20
21 csRow = m_listCtrl.GetItemText(i,0)+_T("\t");
22
23 csRow += m_listCtrl.GetItemText(i,1)+_T("\n");
24
25 csData += csRow;
26
27 }
28
29
30
31 HWND hWnd = GetSafeHwnd(); // 获取安全窗口句柄
32
33 if( ::OpenClipboard(hWnd) )
34
35 {
36
37 HGLOBAL clipbuffer;
38
39 char * buffer;
40
41 EmptyClipboard();
42
43 //strcpy(buffer,LPCSTR(source));//这句注掉
44
45 int len = WideCharToMultiByte(CP_ACP, 0, (LPCTSTR)csData, -1, NULL, 0, NULL, NULL);
46
47 //先得到长度在分配内存
48
49 clipbuffer=GlobalAlloc(GMEM_DDESHARE, len+1);
50
51 buffer=(char*)GlobalLock(clipbuffer);
52
53 WideCharToMultiByte(CP_ACP, 0, (LPCTSTR)csData, -1, buffer, len, NULL, NULL);
54
55
56
57 GlobalUnlock(clipbuffer);
58
59 SetClipboardData(CF_TEXT,clipbuffer);
60
61 CloseClipboard();
62
63
64
65 MessageBox(_T("已将数据存入剪贴板"));
66
67
68
69 }
70
71
72
73 }
74
75 }

将CListCtrl中的内容保存到剪切板。

你可能感兴趣的:(unicode)