关闭

向窗口句柄发送字符串

标签: objectfunctionapplicationinterfacenullbyte
850人阅读 评论(0) 收藏 举报
分类:

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

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:16754次
    • 积分:345
    • 等级:
    • 排名:千里之外
    • 原创:17篇
    • 转载:4篇
    • 译文:0篇
    • 评论:4条
    最新评论