In eine RichEditBox ohne MFC ein Icon ?



  • Bei dem ES_READONLY Problem hilft CoInitialize auch. *lol*



  • ASSERT / AfxThrowOleException kann ich nicht benutzen, da es kein MFC ist 😞



  • Jo, dann benutzt du eben überall das assert aus der Standard-Library (assert.h) oder du schreibst dir kurz eine eigene assert-Funktion die dir dann auch den Fehlerstring von FormatMessage ausgibt.



  • Also die InsertBitmap sieht nun so aus:

    static void InsertBitmap(IRichEditOle* pRichEditOle, HBITMAP hBitmap) 
        { 
            SCODE sc; 
    
            // Get the image data object 
            // 
            CImageDataObject *pods = new CImageDataObject; 
            LPDATAOBJECT lpDataObject; 
            pods->QueryInterface(IID_IDataObject, (void **)&lpDataObject); 
    
            pods->SetBitmap(hBitmap); 
    
            // Get the RichEdit container site 
            // 
            IOleClientSite *pOleClientSite;    
            pRichEditOle->GetClientSite(&pOleClientSite); 
    
            // Initialize a Storage Object 
            // 
            IStorage *pStorage;    
    
            LPLOCKBYTES lpLockBytes = NULL; 
            sc = ::CreateILockBytesOnHGlobal(NULL, TRUE, &lpLockBytes); 
    
    		assert(lpLockBytes != NULL);
    
            sc = ::StgCreateDocfileOnILockBytes(lpLockBytes, 
                STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &pStorage); 
            if (sc != S_OK) 
            { 
                lpLockBytes = NULL; 
            } 
    		assert(pStorage != NULL);
    
            // The final ole object which will be inserted in the richedit control 
            // 
            IOleObject *pOleObject; 
            pOleObject = pods->GetOleObject(pOleClientSite, pStorage); 
    
            // all items are "contained" -- this makes our reference to this object 
            //  weak -- which is needed for links to embedding silent update. 
            OleSetContainedObject(pOleObject, TRUE); 
    
            // Now Add the object to the RichEdit 
            // 
            REOBJECT reobject; 
            ZeroMemory(&reobject, sizeof(REOBJECT)); 
            reobject.cbStruct = sizeof(REOBJECT); 
    
            CLSID clsid; 
            sc = pOleObject->GetUserClassID(&clsid); 
    
            reobject.clsid = clsid; 
            reobject.cp = REO_CP_SELECTION; 
            reobject.dvaspect = DVASPECT_CONTENT; 
            reobject.poleobj = pOleObject; 
            reobject.polesite = pOleClientSite; 
            reobject.pstg = pStorage; 
    
            // Insert the bitmap at the current location in the richedit control 
            // 
            pRichEditOle->InsertObject(&reobject); 
    
            // Release all unnecessary interfaces 
            // 
            pOleObject->Release(); 
            pOleClientSite->Release(); 
            pStorage->Release(); 
            lpDataObject->Release(); 
        }
    

    Aber der Fehler erscheint immer noch ganz genau so 😞



  • Keiner eine Idee was ich machen kann, damit es funktioniert ?



  • Wenn ich das richtig sehe liegt es daran, dass m_fromat beim Aufruf von OleCreateStaticFromData NULL ist, dies aber nicht sein darf.

    The client will pull one format from the object using IDataObject::GetData(). The format of the data to be cached is passed in pFormatEtc, which may not in this case be NULL.

    Allerdings habe ich leider auch keine Ahnung, wie man das genau anstellen muss, damit es klappt 😞 - gibt es hier niemanden, der da Erfahrung hat? -King-?



  • Also es geht bis:

    sc = pOleObject->GetUserClassID(&clsid);

    Dort wird das pOleObject erst auf 0x000000
    gesetzt (hoffe irre mich jetz nicht)



  • lol...ich hatte doch jetzt in 3 Beiträgen erwähnt wie du *diesen* Fehler beheben kannst. Allerdings ergibt sich als nächstes Problem das nur ein leeres Bitmap (aber in der richtigen Größe) eingefügt wird.



  • Da hab ich ja gefragt, wie das verwendet wird 😞



  • OLE doesn't work with multiple threads. As far as I know, you have to
    do all OLE-related stuff from the same thread.



  • Hi there,

    i have defined my AddIcon Sub Routine, so that i can Add Icons from all Routines...

    This Sub Gets the Ole Handle and Calls then the InsertBitmap Class.

    But then i become an error.

    When i call the AddIcon from the WndProc than all right.

    Now i have done it.

    I Send an Userdefined UserMessage ( SendMessage( hWndMain, WM_INSERTSMILIE, NULL, NULL ); )

    And this WM_INSERTSMILIE i check in my WndProc.

    So its all Right now.


Anmelden zum Antworten