Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. inserting bmp in file

inserting bmp in file

Scheduled Pinned Locked Moved C / C++ / MFC
announcementcomsysadminworkspace
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    verma rahul
    wrote on last edited by
    #1

    I am using folowing code to insert BMP in RichEdit. InsertPlotBitmap(CString szFileName) { USES_CONVERSION; SCODE sc = ::CreateILockBytesOnHGlobal(NULL, TRUE, &m_lpLockBytes); if (sc != S_OK) AfxThrowOleException(sc); ASSERT(m_lpLockBytes != NULL); sc = ::StgCreateDocfileOnILockBytes(m_lpLockBytes, STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &m_lpStorage); if (sc != S_OK) { VERIFY(m_lpLockBytes->Release() == 0); m_lpLockBytes = NULL; AfxThrowOleException(sc); } // CString szFileName=strSmile; // attempt to create the object sc = ::OleCreateFromFile(CLSID_NULL, T2COLE(szFileName), IID_IUnknown, OLERENDER_DRAW, NULL, NULL, m_lpStorage, (void **) &m_lpObject); if ( sc != S_OK ) { TCHAR * lpMsgBuf; ::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, ::GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL ); CString msg( lpMsgBuf ); msg += _T("\n\n\n" ); msg += szFileName; AfxMessageBox( msg, MB_OK ); ::LocalFree( lpMsgBuf ); return; } // m_lpObject is currently an IUnknown, convert to IOleObject if (m_lpObject != NULL) { LPUNKNOWN lpUnk = m_lpObject; m_lpObject = QUERYINTERFACE(lpUnk, IOleObject); lpUnk->Release(); if (m_lpObject == NULL) AfxThrowOleException(E_OUTOFMEMORY); } // cache the IViewObject interface m_lpViewObject = QUERYINTERFACE(m_lpObject, IViewObject2); if (m_lpViewObject == NULL) return; // setup for advises; we assume that OLE cleans them up properly LPADVISESINK lpAdviseSink = (LPADVISESINK)GetInterface(&IID_IAdviseSink); // set up view advise VERIFY(m_lpViewObject->SetAdvise(DVASPECT_CONTENT, 0, lpAdviseSink) == S_OK); // the server shows these in its user-interface // (as document title and in File Exit menu) m_lpObject->SetHostNames(T2COLE(AfxGetAppName()), T2COLE(_T("Test"))); // all items are "contained" -- this makes our reference to this object // weak -- which is needed for links to embedding silent update. OleSetContainedObject(m_lpObject, TRUE); // CHARRANGE cr; //m_Ctrl_RichEdit.GetSel( cr ); //cr.cpMin = cr.cpMax -1; //m_Ctrl_RichEdit.SetSel( cr ); REOBJECT reo; memset( &reo, 0, sizeof( reo ) ); reo.cbStruct = sizeof( reo ); CLSID classID; if ( m_lpObject->GetUserClassID( &classID ) != S_OK) classID = CLSID_NULL; reo.clsid = classID; reo.cp = REO_CP_SELECTION; reo.poleobj = m_lpObject; reo.pstg =

    D 1 Reply Last reply
    0
    • V verma rahul

      I am using folowing code to insert BMP in RichEdit. InsertPlotBitmap(CString szFileName) { USES_CONVERSION; SCODE sc = ::CreateILockBytesOnHGlobal(NULL, TRUE, &m_lpLockBytes); if (sc != S_OK) AfxThrowOleException(sc); ASSERT(m_lpLockBytes != NULL); sc = ::StgCreateDocfileOnILockBytes(m_lpLockBytes, STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &m_lpStorage); if (sc != S_OK) { VERIFY(m_lpLockBytes->Release() == 0); m_lpLockBytes = NULL; AfxThrowOleException(sc); } // CString szFileName=strSmile; // attempt to create the object sc = ::OleCreateFromFile(CLSID_NULL, T2COLE(szFileName), IID_IUnknown, OLERENDER_DRAW, NULL, NULL, m_lpStorage, (void **) &m_lpObject); if ( sc != S_OK ) { TCHAR * lpMsgBuf; ::FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM, NULL, ::GetLastError(), MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR) &lpMsgBuf, 0, NULL ); CString msg( lpMsgBuf ); msg += _T("\n\n\n" ); msg += szFileName; AfxMessageBox( msg, MB_OK ); ::LocalFree( lpMsgBuf ); return; } // m_lpObject is currently an IUnknown, convert to IOleObject if (m_lpObject != NULL) { LPUNKNOWN lpUnk = m_lpObject; m_lpObject = QUERYINTERFACE(lpUnk, IOleObject); lpUnk->Release(); if (m_lpObject == NULL) AfxThrowOleException(E_OUTOFMEMORY); } // cache the IViewObject interface m_lpViewObject = QUERYINTERFACE(m_lpObject, IViewObject2); if (m_lpViewObject == NULL) return; // setup for advises; we assume that OLE cleans them up properly LPADVISESINK lpAdviseSink = (LPADVISESINK)GetInterface(&IID_IAdviseSink); // set up view advise VERIFY(m_lpViewObject->SetAdvise(DVASPECT_CONTENT, 0, lpAdviseSink) == S_OK); // the server shows these in its user-interface // (as document title and in File Exit menu) m_lpObject->SetHostNames(T2COLE(AfxGetAppName()), T2COLE(_T("Test"))); // all items are "contained" -- this makes our reference to this object // weak -- which is needed for links to embedding silent update. OleSetContainedObject(m_lpObject, TRUE); // CHARRANGE cr; //m_Ctrl_RichEdit.GetSel( cr ); //cr.cpMin = cr.cpMax -1; //m_Ctrl_RichEdit.SetSel( cr ); REOBJECT reo; memset( &reo, 0, sizeof( reo ) ); reo.cbStruct = sizeof( reo ); CLSID classID; if ( m_lpObject->GetUserClassID( &classID ) != S_OK) classID = CLSID_NULL; reo.clsid = classID; reo.cp = REO_CP_SELECTION; reo.poleobj = m_lpObject; reo.pstg =

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      rver wrote: But it gives error... And what would that error be?


      "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

      V 1 Reply Last reply
      0
      • D David Crow

        rver wrote: But it gives error... And what would that error be?


        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

        V Offline
        V Offline
        verma rahul
        wrote on last edited by
        #3

        It Gives "Assertion Failed" in following function IRichEditOle* CRichEditCtrl::GetIRichEditOle() const { ASSERT(::IsWindow(m_hWnd)); ... } As in this it cannt get m_hWnd is 0x00000000. Learner always

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups