Bilder in RichEdit per Copy & Paste einfügen.
-
Hallo,
grundsätzlich ist es ja kein Problem Bilder in ein RTF-Ctrl einzufügen. Man lädt ein beliebiges Bild und fügt mit Hilfe eines HBITMAP dieses ein. Das funktioniert auch problemlos.
Bsp:
STGMEDIUM stgm; ::ZeroMemory(&stgm, sizeof(STGMEDIUM)); stgm.tymed = TYMED_GDI; stgm.hBitmap = hBitmap; stgm.pUnkForRelease = NULL; COleDataSource *pDataSource = new COleDataSource; pDataSource->CacheData(CF_BITMAP, &stgm, &fmt); IDataObject* pDataObject = (IDataObject*)pDataSource->GetInterface(&IID_IDataObject); pRichEditCtrl->GetIRichEditOle()->ImportDataObject(pDataObject, CF_BITMAP, 0);
Damit das nun aber immer (Copy & Paste / Drag 'n Drop) funktioniert, macht man eine Implementation von IRichEditOleCallback::QueryAcceptData. Nur wenn man obigen Code darin ausführt, funktioniert es nicht mehr. Evtl. hängt das mit dem Rückgabewert zusammen
Lt. MSDN:
On failure, the rich edit control refuses the data and terminates the operation. Otherwise, the control checks the data itself for acceptable formats. A success code other than S_OK means that the callback either checked the data itself (if fReally is FALSE) or imported the data itself (if fReally is TRUE). If the application returns a success code other than S_OK, the control does not check the read-only state of the edit control.Was ist ein "success code other than S_OK"? Oder ist der Weg über IRichEditOleCallback::QueryAcceptData falsch?
Danke und Grüße
Karl
-
Gärtner schrieb:
Was ist ein "success code other than S_OK"? Oder ist der Weg über IRichEditOleCallback::QueryAcceptData falsch?
ImportDataObject liefert einen HRESULT Code. Der ist eben S_OK, wenn alles klar ist oder eben en Fehlercode.
-
Hallo,
Martin Richter schrieb:
ImportDataObject liefert einen HRESULT Code. Der ist eben S_OK, wenn alles klar ist oder eben en Fehlercode.
Irgendwie stehe ich auf dem Schlauch. Ich übersetze das so, dass es noch mehrere Erfolgsmeldungen außer S_OK gibt, also S_OK_1, S_OK_2 usw..
Bei IRichEditOle::ImportDataObject ist das eindeutig entweder S_OK oder halt Fehler, bei IRichEditOleCallback::QueryAcceptData steht das anders.
IRichEditOleCallback::QueryAcceptData verhält sich so:
S_OK:
RTF-Control übernimmt die Arbeit, das Bild ist als Datei mit Icon importiert.
S_FALSE:
Es passiert nichts. Es ist ein Fehler aufgetreten
S_???:
Ich habe das selbst gemacht..
Danke und Grüße
-
Bei einem HRESULT ist nur das ein Fehler was das höchste Bit an hat, also S_OK ist erfolg, S_FALSE ist Erfolg, End fo Record set und alles mögliche andere ist ein Wert bei dem SUCCEEDED true liefert!