943,083 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1067
  • C++ RSS
Nov 28th, 2009
-1

I want to convert MFC RichEdit(with bitmaps) to API RichEdit(with bitmaps)

Expand Post »
Hello Everybody,
I m working on a IRC Chat application project. I would like to know how to insert hte bitmap into the chat window. I have got a few code snippets in MFC & its working perfectly in MFC. But i cant convert it into Win32. Can anybody pls help me in this regard.


C++ Syntax (Toggle Plain Text)
  1. // Four variables
  2. IRichEditOle *m_pRichEditOle;
  3. LPOLEOBJECT m_lpObject;
  4. LPSTORAGE m_lpStorage;
  5. LPOLECLIENTSITE m_lpClientSite;
  6.  
  7. void CRichEditDlg::OnButton1()
  8. {
  9. // TODO: Add your control notification handler code here
  10. CreateFromFile("E:\\VC++\\RichEdit\\confused.bmp");
  11. REOBJECT reobject;
  12. ZeroMemory(&reobject, sizeof(REOBJECT));
  13. reobject.cbStruct = sizeof(REOBJECT);
  14.  
  15. CLSID clsid;
  16. SCODE sc = m_lpObject->GetUserClassID(&clsid);
  17. if (sc != S_OK)
  18. AfxThrowOleException(sc);
  19.  
  20. reobject.clsid = clsid;
  21. reobject.cp = REO_CP_SELECTION;
  22. reobject.dvaspect = DVASPECT_CONTENT;
  23. reobject.dwFlags = REO_RESIZABLE | REO_BELOWBASELINE;
  24. reobject.dwUser = 0;
  25. reobject.poleobj = m_lpObject;
  26.  
  27. ASSERT(m_lpClientSite != NULL);
  28. reobject.polesite = m_lpClientSite;
  29.  
  30. ASSERT(m_lpStorage != NULL);
  31. reobject.pstg = m_lpStorage;
  32.  
  33. SIZEL sizel;
  34. sizel.cx = sizel.cy = 0;
  35. reobject.sizel = sizel;
  36.  
  37. HWND hWndRT = (HWND)m_RchEditControl.GetHwnd();
  38. ::SendMessage(hWndRT, EM_SETSEL, 0, -1);
  39. DWORD dwStart, dwEnd;
  40. ::SendMessage(hWndRT, EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd);
  41. ::SendMessage(hWndRT, EM_SETSEL, dwEnd+1, dwEnd+1);
  42. CString strCr = "\r\n";
  43. m_RchEditControl.SetSelText((LPCTSTR)strCr);
  44. m_pRichEditOle->InsertObject(&reobject);
  45. ::SendMessage(hWndRT, EM_SCROLLCARET, (WPARAM)0, (LPARAM)0);
  46. if (m_lpObject)
  47. {
  48. m_lpObject->Release();
  49. m_lpObject = NULL;
  50. }
  51. if (m_lpStorage)
  52. {
  53. m_lpStorage->Release();
  54. m_lpStorage = NULL;
  55. }
  56. if (m_lpClientSite)
  57. {
  58. m_lpClientSite->Release();
  59. m_lpClientSite = NULL;
  60. }
  61. }
  62.  
  63. BOOL CRichEditDlg::CreateFromFile(LPCTSTR lpszFileName)
  64. {
  65. USES_CONVERSION;
  66.  
  67. ASSERT_VALID(this);
  68. ASSERT(m_lpObject == NULL); // one time only
  69.  
  70. ASSERT(m_lpStorage == NULL);
  71. ASSERT(m_lpClientSite == NULL);
  72. LPLOCKBYTES lpLockBytes = NULL;
  73. CLSID clsid = CLSID_NULL;
  74. OLERENDER render = OLERENDER_DRAW;
  75. CLIPFORMAT cfFormat = 0;
  76. LPFORMATETC lpFormatEtc = NULL;
  77.  
  78. SCODE sc;
  79.  
  80. sc = ::CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes);
  81. if (sc != S_OK)
  82. AfxThrowOleException(sc);
  83. ASSERT(lpLockBytes != NULL);
  84.  
  85. sc = ::StgCreateDocfileOnILockBytes(lpLockBytes,
  86. STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &m_lpStorage);
  87. if (sc != S_OK)
  88. {
  89. VERIFY(lpLockBytes->Release() == 0);
  90. lpLockBytes = NULL;
  91. AfxThrowOleException(sc);
  92. }
  93. ASSERT(m_lpStorage != NULL);
  94.  
  95. // fill in FORMATETC struct
  96. FORMATETC formatEtc;
  97. lpFormatEtc = &formatEtc;
  98. lpFormatEtc->cfFormat = cfFormat;
  99. lpFormatEtc->ptd = NULL;
  100. lpFormatEtc->dwAspect = DVASPECT_CONTENT;
  101. lpFormatEtc->lindex = -1;
  102. lpFormatEtc->tymed = TYMED_NULL;
  103.  
  104. // attempt to create the object
  105. m_pRichEditOle->GetClientSite(&m_lpClientSite);
  106.  
  107. sc = ::OleCreateFromFile(clsid, T2COLE(lpszFileName),
  108. IID_IUnknown, OLERENDER_DRAW, lpFormatEtc, m_lpClientSite, m_lpStorage,
  109. (void**)&m_lpObject);
  110. if (sc != S_OK)
  111. AfxThrowOleException(sc);
  112.  
  113. // m_lpObject is currently an IUnknown, convert to IOleObject
  114. if (m_lpObject != NULL)
  115. {
  116. LPUNKNOWN lpUnk = m_lpObject;
  117. lpUnk->QueryInterface(IID_IOleObject, (void**)&m_lpObject);
  118. lpUnk->Release();
  119. if (m_lpObject == NULL)
  120. AfxThrowOleException(E_OUTOFMEMORY);
  121. }
  122.  
  123. // all items are "contained" -- this makes our reference to this object
  124. // weak -- which is needed for links to embedding silent update.
  125. OleSetContainedObject(m_lpObject, TRUE);
  126.  
  127. ASSERT_VALID(this);
  128. return TRUE;
  129. }
  130.  
  131. void CRichEditDlg::OnDestroy()
  132. {
  133. CDialog::OnDestroy();
  134.  
  135. // TODO: Add your message handler code here
  136. if (m_pRichEditOle)
  137. {
  138. m_pRichEditOle->Release();
  139. m_pRichEditOle = NULL;
  140. }
  141.  
  142. }
Similar Threads
Reputation Points: 5
Solved Threads: 0
Light Poster
lashatt2 is offline Offline
36 posts
since Oct 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: factorials
Next Thread in C++ Forum Timeline: Find value from Cell in dataGridView





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC