WEB开发网
开发学院软件开发VC 类似 MSN 信息发送框的制作(上) 阅读

类似 MSN 信息发送框的制作(上)

 2006-07-23 11:24:52 来源:WEB开发网   
核心提示: void CRichEditCtrlEx::InsertBitmap(HBITMAP hBitmap){STGMEDIUM stgm;stgm.tymed = TYMED_GDI;// Storage medium = HBITMAP handlestgm.hBitmap = hBitma

void CRichEditCtrlEx::InsertBitmap(HBITMAP hBitmap)
{
  STGMEDIUM stgm;
  stgm.tymed = TYMED_GDI;  // Storage medium = HBITMAP handle
  stgm.hBitmap = hBitmap;
  stgm.pUnkForRelease = NULL; // Use ReleaseStgMedium
  
  FORMATETC fm;
  fm.cfFormat = CF_BITMAP;  // Clipboard format = CF_BITMAP
  fm.ptd = NULL;    // Target Device = Screen
  fm.dwAspect = DVASPECT_CONTENT;  // Level of detail = Full content
  fm.lindex = -1;    // Index = Not applicaple
  fm.tymed = TYMED_GDI; 
  
  ////创建输入数据源
  IStorage *pStorage;
  
  ///分配内存
  LPLOCKBYTES lpLockBytes = NULL;
  SCODE sc = ::CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes);
  if (sc != S_OK)
    AfxThrowOleException(sc);
  ASSERT(lpLockBytes != NULL);
  
  sc = ::StgCreateDocfileOnILockBytes(lpLockBytes,
    STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &pStorage);
  if (sc != S_OK)
  {
    VERIFY(lpLockBytes->Release() == 0);
    lpLockBytes = NULL;
    AfxThrowOleException(sc);
  }
  ASSERT(pStorage != NULL);
  
  COleDataSource *pDataSource = new COleDataSource;
  pDataSource->CacheData(CF_BITMAP, &stgm);
  LPDATAOBJECT lpDataObject =
    (LPDATAOBJECT)pDataSource->GetInterface(&IID_IDataObject);
  
  ///获取RichEdit的OLEClientSite
  LPOLECLIENTSITE lpClientSite;
  this->GetIRichEditOle()->GetClientSite( &lpClientSite );
  
  
  ///创建OLE对象
  IOleObject *pOleObject;
  sc = OleCreateStaticFromData(lpDataObject,IID_IOleObject,OLERENDER_FORMAT,
    &fm,lpClientSite,pStorage,(void **)&pOleObject);
  if(sc!=S_OK)
    AfxThrowOleException(sc);
  
  ///插入OLE对象
  
  REOBJECT reobject;
  ZeroMemory(&reobject, sizeof(REOBJECT));
  reobject.cbStruct = sizeof(REOBJECT);
  
  CLSID clsid;
  sc = pOleObject->GetUserClassID(&clsid);
  if (sc != S_OK)
    AfxThrowOleException(sc);
  
  reobject.clsid = clsid;
  reobject.cp = REO_CP_SELECTION;
  reobject.dvaspect = DVASPECT_CONTENT;
  reobject.poleobj = pOleObject;
  reobject.polesite = lpClientSite;
  reobject.pstg = pStorage;
  
  HRESULT hr = this->GetIRichEditOle()->InsertObject( &reobject );
  
}

4、读取/写入RTF格式字符串

CRichEditCtrl 提供了两个函数StreamIn()和StreamOut()来实现这个功能,输出的内容包含文本信息和字体信息。我把这两个函数重新包装了一下 ,用GetRTF()把格式文本返回到一个CString变量中SetRTF(CString )实现逆过程。具体代码参看本文附带的工程文件。

三、到此,这个多功能文本框就已经基本能满足我的要求了。但是如何选择表情符号? 如何自动替换? 还是个问题。(待续)

上一页  1 2 3 

Tags:类似 MSN 信息

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接