向窗口句柄发送字符串

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

阅读更多
个人分类: VC/Evc
想对作者说点什么? 我来说一句

发送字符到指定的IP和端口

2010年03月25日 342KB 下载

没有更多推荐了,返回首页

不良信息举报

向窗口句柄发送字符串

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭