向窗口句柄发送字符串

用剪贴板进行粘贴和复制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! 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值