- 使用Delphi的剪贴板的AsText方法会导致非英语出现乱码,怎么解决?改用Unicode就可以了。
- procedure SetClipboardText(AStr: string);
- var
- Data: THandle;
- DataPtr: Pointer;
- Size: Integer;
- WStr: PWideChar;
- begin
- Size := Length(AStr) * 4;
- WStr := AllocMem(Size);
- try
-
- StringToWideChar(AStr, WStr, Size);
- OpenClipboard(0);
- EmptyClipboard;
- Data := GlobalAlloc(GMEM_MOVEABLE+GMEM_DDESHARE, Size);
- try
- DataPtr := GlobalLock(Data);
- try
- Move(WStr^, DataPtr^, Size);
- SetClipboardData(CF_UNICODETEXT, Data);
- finally
- GlobalUnlock(Data);
- end;
- except
- GlobalFree(Data);
- raise;
- end;
- finally
- CloseClipboard;
- FreeMem(WStr);
- end;
- end;
posted @
2010-04-14 18:54
Max Woods
阅读(
575)
评论()
编辑
收藏
举报