用剪贴板进行粘贴和复制unicode 字符串
包括汉字.
HLOCAL LocalAlloc(
UINT uFlags,
UINT uBytes
);
This function allocates the specified number of bytes from the heap. In the linear Microsoft® Windows® CE application
programming interface (API) environment, there is no difference between the local heap and the global heap.
#include <wceatl.h>
#define GlobalAlloc LocalAlloc
LPVOID GlobalLock(
HGLOBAL hMem // handle to global memory object
);
The GlobalLock function locks a global memory object and returns a pointer to the first byte of the object's memory
block.
Note The global functions are slower than other memory management functions and do not provide as many features.
Therefore, new applications should use the heap functions. However, the global functions are still used with DDE and the
clipboard functions.
BOOL GlobalUnlock(
HGLOBAL hMem // handle to global memory object
);
The GlobalUnlock function decrements the lock count associated with a memory object that was allocated with
GMEM_MOVEABLE. This function has no effect on memory objects allocated with GMEM_FIXED.
Note The global functions are slower than other memory management functions and do not provide as many features.
Therefore, new applications should use the heap functions. However, the global functions are still used with DDE and the
clipboard functions.
//wxg add 2007 -8-30
BOOL CopyAndPaste( LPTSTR pstr)
{
HGLOBAL hglbCopy;
LPTSTR lpstrCopy= NULL;
if (!OpenClipboard(g_hwndTran))
return 0L ;
EmptyClipboard();
// Allocate a global memory object for the text.
hglbCopy = GlobalAlloc(GMEM_MOVEABLE, wcslen(pstr)*2+2);
if (hglbCopy == NULL)
{
CloseClipboard();
return 0L ;
}
lpstrCopy = (LPTSTR)GlobalLock(hglbCopy);
memset(lpstrCopy,0,wcslen(pstr)*2+2);
memcpy(lpstrCopy, pstr, wcslen(pstr)*2);
*(lpstrCopy+wcslen(pstr)*2)=_T('/0');
*(lpstrCopy+wcslen(pstr)*2+1)=_T('/0');
GlobalUnlock(hglbCopy);
// Place the handle on the clipboard.
SetClipboardData(CF_UNICODETEXT, hglbCopy);
CloseClipboard();
//SetFocus(g_hwndTran);
::SendMessage(g_hwndTran, WM_PASTE, 0, 0);
GlobalFree(hglbCopy);
memset(lpstrCopy,0,wcslen(pstr)*2+2);
return TRUE;
}
Best Regards To All!