How to make :
interface IRichEditOle: IUnknown
{
declare virtual GetClientSite(IOleClientSite* lplpolesite),HRESULT;
declare virtual GetObjectCount(),LONG;
declare virtual GetLinkCount(),LONG;
declare virtual GetObject(LONG iob, REOBJECT *lpreobject,DWORD dwFlags),HRESULT;
declare virtual InsertObject(REOBJECT* lpreobject),HRESULT;
declare virtual ConvertObject(LONG iob, REFCLSID *rclsidNew,LPCSTR *lpstrUserTypeNew),HRESULT;
declare virtual ActivateAs(REFCLSID *rclsid, REFCLSID *rclsidAs),HRESULT;
declare virtual SetHostNames(LPCSTR *lpstrContainerApp,LPCSTR *lpstrContainerObj),HRESULT;
declare virtual SetLinkAvailable(LONG iob, BOOL fAvailable),HRESULT;
declare virtual SetDvaspect(LONG iob, DWORD dvaspect),HRESULT;
declare virtual HandsOffStorage(LONG iob),HRESULT;
declare virtual SaveCompleted(LONG iob, IStorage* lpstg),HRESULT;
declare virtual InPlaceDeactivate(),HRESULT;
declare virtual ContextSensitiveHelp(BOOL fEnterMode),HRESULT;
declare virtual GetClipboardData(CHARRANGE* lpchrg, DWORD reco,IDataObject* lplpdataobj),HRESULT;
declare virtual ImportDataObject(IDataObject* lpdataobj,CLIPFORMAT cf, HGLOBAL hMetaPict),HRESULT;
}
IRichEditOle *RichEditOleObject;
*RichEditOleObject = new(IRichEditOle,sizeof(IRichEditOle));
SendMessage(hWnd, EM_GETOLEINTERFACE, 0, &*RichEditOleObject);
Just request the pointer, use it, and finally release
IRichEditOle *pReOle;
if (!SendMessage(hWnd, EM_GETOLEINTERFACE, 0, &pReOle))
{
// use it
int count = pReOle->GetObjectCount();
// release (here, or later)
pReOle->Release();
}
I try to convert a code c++ to Aurora but it's very difficult for me; Nevertheless I always convert this in PureBasic.
I think however that with aurora, it should be easier but I not mastery not.
http://www.codeguru.com/cpp/controls/richedit/article.php/c5383/ (http://www.codeguru.com/cpp/controls/richedit/article.php/c5383/)
The code works but there are several problems.
1) GetControl does not work, problem of the compiler
2) I don't release lpDataObject, window crash ??
3) I use a variable Window, if I declare it that does not work any more
4) I cannot move the image inside RichEdit
5) Border of RichEdit not visible except when window refresh
For the test, change patch image!
#define IDC_RICHEDIT 1000
#define STGM_SHARE_EXCLUSIVE 0x00000010;
#define STGM_READWRITE 0x00000002;
#define STGM_CREATE 0x00001000;
#define REO_CP_SELECTION 0xFFFFFFFF;
#define REO_RESIZABLE 1;
#define REO_BELOWBASELINE 2;
#define OLERENDER_FORMAT 2;
#define E_NOTIMPL 0x80004001u
#define E_NOINTERFACE 0x80004002u
#define S_OK 0
#define IMAGE_BITMAP 0
#define LR_COPYRETURNORG 4
#define EM_GETOLEINTERFACE 1084
#define TYMED_GDI 16
#define DVASPECT_CONTENT 1
#define CF_BITMAP 2
#define STGM_READ 0x00000000u
#define STGM_WRITE 0x00000001u
#define STGM_READWRITE 0x00000002u
#define STGM_SHARE_EXCLUSIVE 0x00000010u
#define OLERENDER_DRAW 1
#define REO_CP_SELECTION 0xFFFFFFFF
#define REO_RESIZABLE 1
unsigned int window;
EXTERN _IID_IUnknown as GUID;
EXTERN _IID_IDataObject as GUID;
EXTERN _IID_IOleObject as GUID;
declare import, IsEqualGUID(GUID *riid1, GUID *riid2),BOOL;
declare import, OleDuplicateData( int hSrc, //Handle of the source data
UNSIGNED word cfFormat, //Clipboard format of the source data
UNSIGNED INT uiFlags),int;
declare import, CopyMemory alias RtlMoveMemory(pointer *Destination,pointer *Source,unsigned int Length);
declare import, CopyImage( Unsigned int hImage,
Unsigned INT uType,
int cxDesired,
int cyDesired,
Unsigned INT fuFlags),int;
declare import, GetDlgItem(unsigned int hdlg, int nIDDlgItem), unsigned int;
declare import, CreateILockBytesOnHGlobal ( unsigned int hGlobal, int fDeleteOnRelease,
pointer *pplkbyt),int;
declare import, StgCreateDocfileOnILockBytes( pointer plkbyt,
int grfMode,
int reserved,
pointer *ppstgOpen),int;
declare import, OleCreateStaticFromData(pointer * pSrcDataObj, pointer * iid,
DWORD renderopt, pointer * pFormatEtc,
pointer * pClientSite, pointer * pStg,
pointer * ppvObj),int;
declare import, OleSetContainedObject(pointer* pUnknown, int fContained),int;
declare import, DeleteObject(int hObject),int;
declare import, LoadImageA( int hinst,
string lpszName,
Unsigned INT uType,
int cxDesired,
int cyDesired,
Unsigned INT fuLoad),int;
Struct DVTARGETDEVICE
{
int tdSize;
word tdDriverNameOffset;
word tdDeviceNameOffset;
word tdPortNameOffset;
word tdExtDevmodeOffset;
byte tdData[1];
}
struct FORMATETC
{
unsigned word cfFormat;
DVTARGETDEVICE *ptd;
DWORD dwAspect;
unsigned int lindex;
DWORD tymed;
}
struct SIZEL
{
int cx;
int cy;
}
struct REOBJECT
{
DWORD cbStruct; // Size of structure
LONG cp; // Character position of object
GUID clsid; // Class ID of object
pointer *poleobj; // OLE object interface
pointer *pstg; // Associated storage interface
pointer *polesite; // Associated client site interface
SIZEL sizel; // Size of object (may be 0,0)
DWORD dvaspect; // Display aspect to use
DWORD dwFlags; // Object status flags
DWORD dwUser; // Dword for user's use
}
interface IUnknown
{
/*** IUnknown methods ***/
declare virtual QueryInterface(riid as POINTER, ppvObj as POINTER),int;
declare virtual AddRef(),int;
declare virtual Release(),int;
}
struct uSTGMEDIUM {
DWORD tymed;
union {
int hbitmap;
int hMetaFilePict;
int hEnhMetaFile;
int hGlobal;
pointer *lpszFileName;
pointer *pstm;
pointer *pstg;
}
IUnknown *pUnkForRelease;
}
interface IStorage : IUnknown
{
declare virtual CreateStream(
/* [string] */ OLECHAR *pwcsName,
DWORD grfMode,
DWORD reserved1,
DWORD reserved2,
/*out*/IStream *ppstm),HRESULT;
declare virtual OpenStream(
/* [string] */ OLECHAR *pwcsName,
void *reserved1,
DWORD grfMode,
DWORD reserved2,
/*out*/IStream *ppstm),HRESULT;
declare virtual CreateStorage(
/* [string] */ OLECHAR *pwcsName,
DWORD grfMode,
DWORD reserved1,
DWORD reserved2,
/*out*/IStorage *ppstg),HRESULT;
declare virtual OpenStorage(
/* [string] */ OLECHAR *pwcsName,
IStorage *pstgPriority,
DWORD grfMode,
SNB snbExclude,
DWORD reserved,
/*out*/IStorage *ppstg),HRESULT;
declare virtual CopyTo(
DWORD ciidExclude,
IID *rgiidExclude,
SNB snbExclude,
IStorage *pstgDest),HRESULT;
declare virtual MoveElementTo(
/* [string] */ OLECHAR *pwcsName,
IStorage *pstgDest,
/* [string] */ OLECHAR *pwcsNewName,
DWORD grfFlags),HRESULT;
declare virtual Commit(
DWORD grfCommitFlags),HRESULT;
declare virtual Revert(),HRESULT;
declare virtual EnumElements(
DWORD reserved1,
void *reserved2,
DWORD reserved3,
/*out*/IEnumSTATSTG *ppenum),HRESULT;
declare virtual DestroyElement(
/* [string] */ OLECHAR *pwcsName),HRESULT;
declare virtual RenameElement(
/* [string] */ OLECHAR *pwcsOldName,
/* [string] */ OLECHAR *pwcsNewName),HRESULT;
declare virtual SetElementTimes(
/* [string] */ OLECHAR *pwcsName,
FILETIME *pctime,
FILETIME *patime,
FILETIME *pmtime),HRESULT;
declare virtual SetClass(
REFCLSID *clsid),HRESULT;
declare virtual SetStateBits(
DWORD grfStateBits,
DWORD grfMask),HRESULT;
declare virtual Stat(
/*out*/STATSTG *pstatstg,
DWORD grfStatFlag),HRESULT;
}
interface IOleClientSite : IUnknown
{
//no need for the rest of the interface.
}
interface IOleObject : IUnknown
{
declare virtual SetClientSite(
IOleClientSite *pClientSite),HRESULT;
declare virtual GetClientSite(
/*out*/IOleClientSite *ppClientSite),HRESULT;
declare virtual SetHostNames(
LPCOLESTR szContainerApp,
LPCOLESTR szContainerObj),HRESULT;
declare virtual Close(
DWORD dwSaveOption),HRESULT;
declare virtual SetMoniker(
DWORD dwWhichMoniker,
IMoniker *pmk),HRESULT;
declare virtual GetMoniker(
DWORD dwAssign,
DWORD dwWhichMoniker,
/*out*/IMoniker *ppmk),HRESULT;
declare virtual InitFromData(
IDataObject *pDataObject,
BOOL fCreation,
DWORD dwReserved),HRESULT;
declare virtual GetClipboardData(
DWORD dwReserved,
/*out*/IDataObject *ppDataObject),HRESULT;
declare virtual DoVerb(
LONG iVerb,
MSG *lpmsg,
IOleClientSite *pActiveSite,
LONG lindex,
HWND hwndParent,
RECT *lprcPosRect),HRESULT;
declare virtual EnumVerbs(
/*out*/IEnumOLEVERB *ppEnumOleVerb),HRESULT;
declare virtual Update(),HRESULT;
declare virtual IsUpToDate(),HRESULT;
declare virtual GetUserClassID(
/*out*/CLSID *pClsid),HRESULT;
declare virtual GetUserType(
DWORD dwFormOfType,
/*out*/LPOLESTR *pszUserType),HRESULT;
declare virtual SetExtent(
DWORD dwDrawAspect,
SIZEL *psizel),HRESULT;
declare virtual GetExtent(
DWORD dwDrawAspect,
/*out*/SIZEL *psizel),HRESULT;
declare virtual Advise(
IAdviseSink *pAdvSink,
/*out*/DWORD *pdwConnection),HRESULT;
declare virtual Unadvise(
DWORD dwConnection),HRESULT;
declare virtual EnumAdvise(
/*out*/IEnumSTATDATA *ppenumAdvise),HRESULT;
declare virtual GetMiscStatus(
DWORD dwAspect,
/*out*/DWORD *pdwStatus),HRESULT;
declare virtual SetColorScheme(
LOGPALETTE *pLogpal),HRESULT;
}
interface ILockBytes : IUnknown
{
//no need for the rest of the interface.
}
interface IRichEditOle: IUnknown
{
declare virtual GetClientSite(IOleClientSite* lplpolesite),HRESULT;
declare virtual GetObjectCount(),LONG;
declare virtual GetLinkCount(),LONG;
declare virtual GetObject(LONG iob, REOBJECT *lpreobject,DWORD dwFlags),HRESULT;
declare virtual InsertObject(REOBJECT* lpreobject),HRESULT;
declare virtual ConvertObject(LONG iob, REFCLSID *rclsidNew,LPCSTR *lpstrUserTypeNew),HRESULT;
declare virtual ActivateAs(REFCLSID *rclsid, REFCLSID *rclsidAs),HRESULT;
declare virtual SetHostNames(LPCSTR *lpstrContainerApp,LPCSTR *lpstrContainerObj),HRESULT;
declare virtual SetLinkAvailable(LONG iob, BOOL fAvailable),HRESULT;
declare virtual SetDvaspect(LONG iob, DWORD dvaspect),HRESULT;
declare virtual HandsOffStorage(LONG iob),HRESULT;
declare virtual SaveCompleted(LONG iob, IStorage* lpstg),HRESULT;
declare virtual InPlaceDeactivate(),HRESULT;
declare virtual ContextSensitiveHelp(BOOL fEnterMode),HRESULT;
declare virtual GetClipboardData(CHARRANGE* lpchrg, DWORD reco,IDataObject* lplpdataobj),HRESULT;
declare virtual ImportDataObject(IDataObject* lpdataobj,CLIPFORMAT cf, HGLOBAL hMetaPict),HRESULT;
}
declare import,SendMessageA( int hWnd,
Unsigned INT Msg,
void wParam,
void lParam),int;
class object
{
declare virtual QueryInterface(riid as POINTER, ppvObj as POINTER),int;
declare virtual AddRef(),int;
declare virtual Release(),int;
declare virtual GetData( FORMATETC *pformatetcIn, uSTGMEDIUM *pmedium),int;
declare virtual GetDataHere( pointer *pformatetcIn, pointer *pmedium ),int;
declare virtual QueryGetData( pointer *pformatetc),int;
declare virtual GetCanonicalFormatEtc( pointer *pformatectIn ,pointer *pformatetcOut),int;
declare virtual SetData( pointer *pformatetc , uSTGMEDIUM *pmedium , int fRelease),int;
declare virtual EnumFormatEtc(int dwDirection , pointer *ppenumFormatEtc ),int;
declare virtual DAdvise(pointer *pformatetc, int advf, pointer *pAdvSink, pointer *pdwConnection),int;
declare virtual DUnadvise(int dwConnection),int;
declare virtual EnumDAdvise(pointer*ppenumAdvise),int;
int m_RefCounter;
uSTGMEDIUM m_stgmed;
FORMATETC m_fromat;
}
class DataObject
{
declare DataObject();
declare _DataObject();
object *MyObject;
}
DataObject::DataObject
{
}
DataObject::_DataObject
{
}
Object::QueryInterface(riid as GUID, ppvObj as pointer),int
{
if IsEqualGUID(riid, _IID_IUnknown)=1 or IsEqualGUID(riid, _IID_IDataObject)=1
{
AddRef();
*(pointer)ppvObj=this;
return S_OK;
}
else
{
return E_NOINTERFACE;
}
}
Object::AddRef(),int
{
m_RefCounter=m_RefCounter+1;
return m_RefCounter;
}
Object::Release(),int
{
m_RefCounter=m_RefCounter-1;
if m_RefCounter=0
{
delete(this);
this=0;
}
return m_RefCounter;
}
Object::GetData( FORMATETC *pformatetcIn, uSTGMEDIUM *pmedium),int
{
If pformatetcIn->tymed=m_fromat.tymed
{
If pformatetcIn->cfFormat=m_fromat.cfFormat
{
hbitmap = OleDuplicateData(m_stgmed.hBitmap, 2, Null);
if hbitmap
{
pmedium->tymed = m_stgmed.tymed;
pmedium->hBitmap = hbitmap;
pmedium->pUnkForRelease = Null;
}
}
}
Return S_OK;
}
Object::GetDataHere( pointer *pformatetcIn, pointer *pmedium ),int
{
Return E_NOTIMPL;
}
Object::QueryGetData( pointer *pformatetc),int
{
Return E_NOTIMPL;
}
Object::GetCanonicalFormatEtc( pointer *pformatectIn ,pointer *pformatetcOut),int
{
Return E_NOTIMPL;
}
Object::SetData( pointer *pformatetc , pointer *pmedium , int fRelease),int
{
CopyMemory(&m_fromat,pformatetc,SizeOf(FORMATETC));
CopyMemory(&m_stgmed,pmedium,SizeOf(uSTGMEDIUM));
Return S_OK;
}
Object::EnumFormatEtc(int dwDirection , pointer *ppenumFormatEtc ),int
{
Return E_NOTIMPL;
}
Object::DAdvise(pointer *pformatetc, int advf, pointer *pAdvSink, pointer *pdwConnection),int
{
Return E_NOTIMPL;
}
Object::DUnadvise(int dwConnection),int
{
Return E_NOTIMPL;
}
Object::EnumDAdvise(pointer*ppenumAdvise),int
{
Return E_NOTIMPL;
}
sub Paste_Image(unsigned int hBitmap,int RICHEDIT )
{
int Ret;
int sc;
Dataobject *pods;
IRichEditOle *RichEditOleObject=null;
pods=new(Dataobject,1);
If (hBitmap >0)
{
//CRichEdit *c1 ;
//c1= GetControl(RICHEDIT); I have an error of compiler
SendMessageA(GetDlgItem(Window,RICHEDIT), EM_GETOLEINTERFACE, 0, &RichEditOleObject);
If RichEditOleObject>0
{
pods->MyObject=new(object,1);
object *lpDataObject;
sc=pods->MyObject->QueryInterface(_IID_IUnknown, &lpDataObject);
uSTGMEDIUM stgmed;
FORMATETC fromat;
stgmed.tymed = TYMED_GDI ; // Storage medium = HBITMAP handle
stgmed.hBitmap = hBitmap ; // HBITMAP handle
stgmed.pUnkForRelease = Null ; // Use ReleaseStgMedium
fromat.cfFormat = CF_BITMAP ; // Clipboard format = CF_BITMAP
fromat.ptd = Null ; // Target Device = Screen
fromat.dwAspect = DVASPECT_CONTENT ; // Level of detail = Full content
fromat.lindex = -1 ; // Index = Not applicaple
fromat.tymed = TYMED_GDI ; // Storage medium = HBITMAP handle
lpDataObject->SetData(fromat, stgmed, True);
ILockBytes *lpLockBytes = NULL;
sc = CreateILockBytesOnHGlobal(Null, True, &lpLockBytes);
If sc = S_OK
{
IStorage *lpStorage = NULL;
StgCreateDocfileOnILockBytes(lpLockBytes, STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &lpStorage);
IOleClientSite *lpClientSite = NULL;
sc =RichEditOleObject->GetClientSite(&lpClientSite);
If sc = S_OK
{
IOleObject *lpOleObject;
sc = OleCreateStaticFromData(lpDataObject, _IID_IOleObject, OLERENDER_FORMAT, pods->MyObject->m_fromat, lpClientSite, lpStorage, &lpOleObject);
If sc = S_OK
{
OleSetContainedObject(lpOleObject, True);
REOBJECT reobject;
//ZeroMemory_(@reobject, SizeOf(REOBJECT));
reobject.cbStruct = SizeOf(REOBJECT);
GUID clsid;
sc = lpOleObject->GetUserClassID(clsid);
reobject.cp = REO_CP_SELECTION;
reobject.clsid=clsid;
reobject.dvaspect = DVASPECT_CONTENT;
reobject.dwFlags = REO_RESIZABLE;
reobject.dwUser = 0;
reobject.poleobj = lpOleObject;
reobject.polesite = lpClientSite;
reobject.pstg = lpStorage;
reobject.sizel.cx=0;
reobject.sizel.cy=0;
Ret= RichEditOleObject->InsertObject(reobject);
}
}
}
If lpLockBytes
{
lpLockBytes->Release();
lpLockBytes=0;
}
If lpOleObject
{
lpOleObject->Release();
lpOleObject = Null;
}
If lpStorage
{
lpStorage->Release();
lpStorage = Null;
}
If lpClientSite
{
lpClientSite->Release();
lpClientSite = Null;
}
If RichEditOleObject
{
RichEditOleObject->Release();
RichEditOleObject = Null;
}
If lpDataObject
{
//lpDataObject->Release();Crash if release ???
// or delete(pods->MyObject);Error of compiler ???
lpDataObject= Null;
}
}
DeleteObject(hBitmap);
}
Return Ret;
}
class MyWindow : CWindow
{
declare MyWindow();
declare _MyWindow();
declare virtual OnCreate(),int;
declare virtual OnClose(),int;
declare virtual OnControl(int nID, int nNotifyCode, unsigned int hControl),int;
int run;
}
//MyWindow Implementation
MyWindow::MyWindow()
{
}
MyWindow::_MyWindow()
{
}
global sub main()
{
//unsigned int Window;
MyWindow win;
win.Create(0,0,300,340,AWS_CAPTION | AWS_SYSMENU | AWS_AUTODRAW | AWS_VISIBLE | AWS_BORDER,0,"Demo",0);
Window=win.m_hWnd ;
win.AddControl(CTBUTTON,"Paste Image",10,260,100,20,AWS_VISIBLE|ABS_DEFAULT,0,10);
win.AddControl(CTRICHEDIT,"",10,10,280,200,AES_MULTILINE|AES_AUTOVSCROLL|AES_AUTOHSCROLL|AWS_VISIBLE|AWS_BORDER ,0,IDC_RICHEDIT);
win.run = 1;
do
{
wait();
} until win.run = 0;
return;
}
MyWindow::OnCreate(),int
{
CenterWindow();
}
MyWindow::OnClose(),int
{
run = 0;
return true;
}
MyWindow::OnControl(int nID, int nNotifyCode, unsigned int hControl),int
{
select (nid)
{
case 10:
if(nNotifyCode = 0)
{
int Himage;
// Change patch
Himage=LoadImageA(null, "c:\carre_rouge.bmp", 0, 0, 0, 80);
Paste_Image(Himage,IDC_RICHEDIT);
}
}
return 0;
}
Nico,
GetControl is a method of the window class, it is not a function. So if you are not within a method you have to access it with a pointer to the container window, just like C++.
So either make paste_image a method of your MyWindow class, or use a global pointer to your main window.
Paul.
Ok Paul, I understand better my errors now. :)
Just a thing, the code does not work with Cbitmap class and I do not know why.
#define IDC_RICHEDIT 1000
#define STGM_SHARE_EXCLUSIVE 0x00000010;
#define STGM_READWRITE 0x00000002;
#define STGM_CREATE 0x00001000;
#define REO_CP_SELECTION 0xFFFFFFFF;
#define REO_RESIZABLE 1;
#define REO_BELOWBASELINE 2;
#define OLERENDER_FORMAT 2;
#define E_NOTIMPL 0x80004001u
#define E_NOINTERFACE 0x80004002u
#define S_OK 0
#define IMAGE_BITMAP 0
#define LR_COPYRETURNORG 4
#define EM_GETOLEINTERFACE 1084
#define TYMED_GDI 16
#define DVASPECT_CONTENT 1
#define CF_BITMAP 2
#define STGM_READ 0x00000000u
#define STGM_WRITE 0x00000001u
#define STGM_READWRITE 0x00000002u
#define STGM_SHARE_EXCLUSIVE 0x00000010u
#define OLERENDER_DRAW 1
#define REO_CP_SELECTION 0xFFFFFFFF
#define REO_RESIZABLE 1
EXTERN _IID_IUnknown as GUID;
EXTERN _IID_IDataObject as GUID;
EXTERN _IID_IOleObject as GUID;
declare import, IsEqualGUID(GUID *riid1, GUID *riid2),BOOL;
declare import, OleDuplicateData( int hSrc, //Handle of the source data
UNSIGNED word cfFormat, //Clipboard format of the source data
UNSIGNED INT uiFlags),int;
declare import, CopyMemory alias RtlMoveMemory(pointer *Destination,pointer *Source,unsigned int Length);
declare import, CopyImage( Unsigned int hImage,
Unsigned INT uType,
int cxDesired,
int cyDesired,
Unsigned INT fuFlags),int;
declare import, GetDlgItem(unsigned int hdlg, int nIDDlgItem), unsigned int;
declare import, CreateILockBytesOnHGlobal ( unsigned int hGlobal, int fDeleteOnRelease,
pointer *pplkbyt),int;
declare import, StgCreateDocfileOnILockBytes( pointer plkbyt,
int grfMode,
int reserved,
pointer *ppstgOpen),int;
declare import, OleCreateStaticFromData(pointer * pSrcDataObj, pointer * iid,
DWORD renderopt, pointer * pFormatEtc,
pointer * pClientSite, pointer * pStg,
pointer * ppvObj),int;
declare import, OleSetContainedObject(pointer* pUnknown, int fContained),int;
declare import, DeleteObject(int hObject),int;
declare import, LoadImageA( int hinst,
string lpszName,
Unsigned INT uType,
int cxDesired,
int cyDesired,
Unsigned INT fuLoad),int;
declare import,SendMessageA( int hWnd,
Unsigned INT Msg,
void wParam,
void lParam),int;
Struct DVTARGETDEVICE
{
int tdSize;
word tdDriverNameOffset;
word tdDeviceNameOffset;
word tdPortNameOffset;
word tdExtDevmodeOffset;
byte tdData[1];
}
struct FORMATETC
{
unsigned word cfFormat;
DVTARGETDEVICE *ptd;
DWORD dwAspect;
unsigned int lindex;
DWORD tymed;
}
struct SIZEL
{
int cx;
int cy;
}
struct REOBJECT
{
DWORD cbStruct; // Size of structure
LONG cp; // Character position of object
GUID clsid; // Class ID of object
pointer *poleobj; // OLE object interface
pointer *pstg; // Associated storage interface
pointer *polesite; // Associated client site interface
SIZEL sizel; // Size of object (may be 0,0)
DWORD dvaspect; // Display aspect to use
DWORD dwFlags; // Object status flags
DWORD dwUser; // Dword for user's use
}
interface IUnknown
{
/*** IUnknown methods ***/
declare virtual QueryInterface(riid as POINTER, ppvObj as POINTER),int;
declare virtual AddRef(),int;
declare virtual Release(),int;
}
struct uSTGMEDIUM {
DWORD tymed;
union {
int hbitmap;
int hMetaFilePict;
int hEnhMetaFile;
int hGlobal;
pointer *lpszFileName;
pointer *pstm;
pointer *pstg;
}
IUnknown *pUnkForRelease;
}
interface IStorage : IUnknown
{
declare virtual CreateStream(
/* [string] */ OLECHAR *pwcsName,
DWORD grfMode,
DWORD reserved1,
DWORD reserved2,
/*out*/IStream *ppstm),HRESULT;
declare virtual OpenStream(
/* [string] */ OLECHAR *pwcsName,
void *reserved1,
DWORD grfMode,
DWORD reserved2,
/*out*/IStream *ppstm),HRESULT;
declare virtual CreateStorage(
/* [string] */ OLECHAR *pwcsName,
DWORD grfMode,
DWORD reserved1,
DWORD reserved2,
/*out*/IStorage *ppstg),HRESULT;
declare virtual OpenStorage(
/* [string] */ OLECHAR *pwcsName,
IStorage *pstgPriority,
DWORD grfMode,
SNB snbExclude,
DWORD reserved,
/*out*/IStorage *ppstg),HRESULT;
declare virtual CopyTo(
DWORD ciidExclude,
IID *rgiidExclude,
SNB snbExclude,
IStorage *pstgDest),HRESULT;
declare virtual MoveElementTo(
/* [string] */ OLECHAR *pwcsName,
IStorage *pstgDest,
/* [string] */ OLECHAR *pwcsNewName,
DWORD grfFlags),HRESULT;
declare virtual Commit(
DWORD grfCommitFlags),HRESULT;
declare virtual Revert(),HRESULT;
declare virtual EnumElements(
DWORD reserved1,
void *reserved2,
DWORD reserved3,
/*out*/IEnumSTATSTG *ppenum),HRESULT;
declare virtual DestroyElement(
/* [string] */ OLECHAR *pwcsName),HRESULT;
declare virtual RenameElement(
/* [string] */ OLECHAR *pwcsOldName,
/* [string] */ OLECHAR *pwcsNewName),HRESULT;
declare virtual SetElementTimes(
/* [string] */ OLECHAR *pwcsName,
FILETIME *pctime,
FILETIME *patime,
FILETIME *pmtime),HRESULT;
declare virtual SetClass(
REFCLSID *clsid),HRESULT;
declare virtual SetStateBits(
DWORD grfStateBits,
DWORD grfMask),HRESULT;
declare virtual Stat(
/*out*/STATSTG *pstatstg,
DWORD grfStatFlag),HRESULT;
}
interface IOleClientSite : IUnknown
{
//no need for the rest of the interface.
}
interface IOleObject : IUnknown
{
declare virtual SetClientSite(
IOleClientSite *pClientSite),HRESULT;
declare virtual GetClientSite(
/*out*/IOleClientSite *ppClientSite),HRESULT;
declare virtual SetHostNames(
LPCOLESTR szContainerApp,
LPCOLESTR szContainerObj),HRESULT;
declare virtual Close(
DWORD dwSaveOption),HRESULT;
declare virtual SetMoniker(
DWORD dwWhichMoniker,
IMoniker *pmk),HRESULT;
declare virtual GetMoniker(
DWORD dwAssign,
DWORD dwWhichMoniker,
/*out*/IMoniker *ppmk),HRESULT;
declare virtual InitFromData(
IDataObject *pDataObject,
BOOL fCreation,
DWORD dwReserved),HRESULT;
declare virtual GetClipboardData(
DWORD dwReserved,
/*out*/IDataObject *ppDataObject),HRESULT;
declare virtual DoVerb(
LONG iVerb,
MSG *lpmsg,
IOleClientSite *pActiveSite,
LONG lindex,
HWND hwndParent,
RECT *lprcPosRect),HRESULT;
declare virtual EnumVerbs(
/*out*/IEnumOLEVERB *ppEnumOleVerb),HRESULT;
declare virtual Update(),HRESULT;
declare virtual IsUpToDate(),HRESULT;
declare virtual GetUserClassID(
/*out*/CLSID *pClsid),HRESULT;
declare virtual GetUserType(
DWORD dwFormOfType,
/*out*/LPOLESTR *pszUserType),HRESULT;
declare virtual SetExtent(
DWORD dwDrawAspect,
SIZEL *psizel),HRESULT;
declare virtual GetExtent(
DWORD dwDrawAspect,
/*out*/SIZEL *psizel),HRESULT;
declare virtual Advise(
IAdviseSink *pAdvSink,
/*out*/DWORD *pdwConnection),HRESULT;
declare virtual Unadvise(
DWORD dwConnection),HRESULT;
declare virtual EnumAdvise(
/*out*/IEnumSTATDATA *ppenumAdvise),HRESULT;
declare virtual GetMiscStatus(
DWORD dwAspect,
/*out*/DWORD *pdwStatus),HRESULT;
declare virtual SetColorScheme(
LOGPALETTE *pLogpal),HRESULT;
}
interface ILockBytes : IUnknown
{
//no need for the rest of the interface.
}
interface IRichEditOle: IUnknown
{
declare virtual GetClientSite(IOleClientSite* lplpolesite),HRESULT;
declare virtual GetObjectCount(),LONG;
declare virtual GetLinkCount(),LONG;
declare virtual GetObject(LONG iob, REOBJECT *lpreobject,DWORD dwFlags),HRESULT;
declare virtual InsertObject(REOBJECT* lpreobject),HRESULT;
declare virtual ConvertObject(LONG iob, REFCLSID *rclsidNew,LPCSTR *lpstrUserTypeNew),HRESULT;
declare virtual ActivateAs(REFCLSID *rclsid, REFCLSID *rclsidAs),HRESULT;
declare virtual SetHostNames(LPCSTR *lpstrContainerApp,LPCSTR *lpstrContainerObj),HRESULT;
declare virtual SetLinkAvailable(LONG iob, BOOL fAvailable),HRESULT;
declare virtual SetDvaspect(LONG iob, DWORD dvaspect),HRESULT;
declare virtual HandsOffStorage(LONG iob),HRESULT;
declare virtual SaveCompleted(LONG iob, IStorage* lpstg),HRESULT;
declare virtual InPlaceDeactivate(),HRESULT;
declare virtual ContextSensitiveHelp(BOOL fEnterMode),HRESULT;
declare virtual GetClipboardData(CHARRANGE* lpchrg, DWORD reco,IDataObject* lplpdataobj),HRESULT;
declare virtual ImportDataObject(IDataObject* lpdataobj,CLIPFORMAT cf, HGLOBAL hMetaPict),HRESULT;
}
class DataObject
{
declare virtual QueryInterface(riid as POINTER, ppvObj as POINTER),int;
declare virtual AddRef(),int;
declare virtual Release(),int;
declare virtual GetData( FORMATETC *pformatetcIn, uSTGMEDIUM *pmedium),int;
declare virtual GetDataHere( pointer *pformatetcIn, pointer *pmedium ),int;
declare virtual QueryGetData( pointer *pformatetc),int;
declare virtual GetCanonicalFormatEtc( pointer *pformatectIn ,pointer *pformatetcOut),int;
declare virtual SetData( pointer *pformatetc , uSTGMEDIUM *pmedium , int fRelease),int;
declare virtual EnumFormatEtc(int dwDirection , pointer *ppenumFormatEtc ),int;
declare virtual DAdvise(pointer *pformatetc, int advf, pointer *pAdvSink, pointer *pdwConnection),int;
declare virtual DUnadvise(int dwConnection),int;
declare virtual EnumDAdvise(pointer*ppenumAdvise),int;
int m_RefCounter;
uSTGMEDIUM m_stgmed;
FORMATETC m_fromat;
}
DataObject::QueryInterface(riid as GUID, ppvObj as pointer),int
{
if IsEqualGUID(riid, _IID_IUnknown)=1 or IsEqualGUID(riid, _IID_IDataObject)=1
{
AddRef();
*(pointer)ppvObj=this;
return S_OK;
}
else
{
return E_NOINTERFACE;
}
}
DataObject::AddRef(),int
{
m_RefCounter=m_RefCounter+1;
return m_RefCounter;
}
DataObject::Release(),int
{
m_RefCounter=m_RefCounter-1;
if m_RefCounter=0
{
delete this;
return 0;
}
return m_RefCounter;
}
DataObject::GetData( FORMATETC *pformatetcIn, uSTGMEDIUM *pmedium),int
{
If pformatetcIn->tymed=m_fromat.tymed
{
If pformatetcIn->cfFormat=m_fromat.cfFormat
{
hbitmap = OleDuplicateData(m_stgmed.hBitmap, 2, Null);
if hbitmap
{
pmedium->tymed = m_stgmed.tymed;
pmedium->hBitmap = hbitmap;
pmedium->pUnkForRelease = Null;
}
}
}
Return S_OK;
}
DataObject::GetDataHere( pointer *pformatetcIn, pointer *pmedium ),int
{
Return E_NOTIMPL;
}
DataObject::QueryGetData( pointer *pformatetc),int
{
Return E_NOTIMPL;
}
DataObject::GetCanonicalFormatEtc( pointer *pformatectIn ,pointer *pformatetcOut),int
{
Return E_NOTIMPL;
}
DataObject::SetData( pointer *pformatetc , pointer *pmedium , int fRelease),int
{
CopyMemory(&m_fromat,pformatetc,SizeOf(FORMATETC));
CopyMemory(&m_stgmed,pmedium,SizeOf(uSTGMEDIUM));
Return S_OK;
}
DataObject::EnumFormatEtc(int dwDirection , pointer *ppenumFormatEtc ),int
{
Return E_NOTIMPL;
}
DataObject::DAdvise(pointer *pformatetc, int advf, pointer *pAdvSink, pointer *pdwConnection),int
{
Return E_NOTIMPL;
}
DataObject::DUnadvise(int dwConnection),int
{
Return E_NOTIMPL;
}
DataObject::EnumDAdvise(pointer*ppenumAdvise),int
{
Return E_NOTIMPL;
}
class MyWindow : CWindow
{
declare MyWindow();
declare _MyWindow();
declare virtual OnCreate(),int;
declare virtual OnClose(),int;
declare virtual OnControl(int nID, int nNotifyCode, unsigned int hControl),int;
declare virtual Paste_Image();
CImage bmp;
unsigned int hBitmap;
int run;
}
//MyWindow Implementation
MyWindow::MyWindow()
{
}
MyWindow::_MyWindow()
{
}
MyWindow::Paste_Image()
{
int Ret;
int sc;
Dataobject *pods;
IRichEditOle *RichEditOleObject=null;
pods=new(Dataobject,1);
CRichEdit *c ;
c= GetControl(IDC_RICHEDIT);
SendMessageA(c->m_Hwnd, EM_GETOLEINTERFACE, 0, &RichEditOleObject);
If RichEditOleObject>0
{
pods=new(DataObject,1);
DataObject *lpDataObject = Null;
sc=pods->QueryInterface(_IID_IUnknown, &lpDataObject);
uSTGMEDIUM stgmed;
FORMATETC fromat;
stgmed.tymed = TYMED_GDI ; // Storage medium = HBITMAP handle
stgmed.hBitmap =hBitmap ; // HBITMAP handle
//Dosen't work
//stgmed.hBitmap =bmp.m_hImage ; // HBITMAP handle
stgmed.pUnkForRelease = Null ; // Use ReleaseStgMedium
fromat.cfFormat = CF_BITMAP ; // Clipboard format = CF_BITMAP
fromat.ptd = Null ; // Target Device = Screen
fromat.dwAspect = DVASPECT_CONTENT ; // Level of detail = Full content
fromat.lindex = -1 ; // Index = Not applicaple
fromat.tymed = TYMED_GDI ; // Storage medium = HBITMAP handle
lpDataObject->SetData(fromat, stgmed, True);
ILockBytes *lpLockBytes = Null;
sc = CreateILockBytesOnHGlobal(Null, True, &lpLockBytes);
If sc = S_OK
{
IStorage *lpStorage = Null;
StgCreateDocfileOnILockBytes(lpLockBytes, STGM_SHARE_EXCLUSIVE|STGM_CREATE|STGM_READWRITE, 0, &lpStorage);
IOleClientSite *lpClientSite = Null;
sc =RichEditOleObject->GetClientSite(&lpClientSite);
If sc = S_OK
{
IOleObject *lpOleObject;
sc = OleCreateStaticFromData(lpDataObject, _IID_IOleObject, OLERENDER_FORMAT, pods->m_fromat, lpClientSite, lpStorage, &lpOleObject);
If sc = S_OK
{
OleSetContainedObject(lpOleObject, True);
REOBJECT reobject;
//ZeroMemory_(@reobject, SizeOf(REOBJECT));
reobject.cbStruct = SizeOf(REOBJECT);
GUID clsid;
sc = lpOleObject->GetUserClassID(clsid);
reobject.cp = REO_CP_SELECTION;
reobject.clsid=clsid;
reobject.dvaspect = DVASPECT_CONTENT;
reobject.dwFlags = REO_RESIZABLE;
reobject.dwUser = 0;
reobject.poleobj = lpOleObject;
reobject.polesite = lpClientSite;
reobject.pstg = lpStorage;
reobject.sizel.cx=0;
reobject.sizel.cy=0;
Ret= RichEditOleObject->InsertObject(reobject);
}
}
}
If lpLockBytes
{
lpLockBytes->Release();
lpLockBytes=0;
}
If lpOleObject
{
lpOleObject->Release();
lpOleObject = Null;
}
If lpStorage
{
lpStorage->Release();
lpStorage = Null;
}
If lpClientSite
{
lpClientSite->Release();
lpClientSite = Null;
}
If RichEditOleObject
{
RichEditOleObject->Release();
RichEditOleObject = Null;
}
If lpDataObject
{
lpDataObject->Release();
lpDataObject= Null;
}
DeleteObject(hBitmap);
}
Return Ret;
}
global sub main()
{
//unsigned int Window;
MyWindow win;
win.Create(0,0,300,340,AWS_CAPTION | AWS_SYSMENU | AWS_AUTODRAW | AWS_VISIBLE | AWS_BORDER,0,"Demo",0);
win.AddControl(CTBUTTON,"Paste Image",10,260,100,20,AWS_VISIBLE|ABS_DEFAULT,0,10);
win.AddControl(CTRICHEDIT,"",10,10,280,200,AES_MULTILINE|AES_AUTOVSCROLL|AES_AUTOHSCROLL|AWS_VISIBLE|AWS_BORDER ,0,IDC_RICHEDIT);
win.run = 1;
do
{
wait();
} until win.run = 0;
return;
}
MyWindow::OnCreate(),int
{
CenterWindow();
}
MyWindow::OnClose(),int
{
run = 0;
return true;
}
MyWindow::OnControl(int nID, int nNotifyCode, unsigned int hControl),int
{
select (nid)
{
case 10:
if(nNotifyCode = 0)
{
// Dosen't work
//bmp.LoadFromFile("c:\carre_rouge.bmp");
// Change patch
hBitmap=LoadImageA(null, "c:\carre_rouge.bmp", 0, 0, 0, 80);
if hBitmap
{
Paste_Image();
}
}
}
return 0;
}