Article View: borland.public.cppbuilder.nativeapi
Article #5528Re: Dragging from application to explorer
From: Gizmo
Date: Sat, 13 Aug 2005 14:05
Date: Sat, 13 Aug 2005 14:05
79 lines
3072 bytes
3072 bytes
"Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote:
>
>You will need to use OLE Drag&Drop for that. Specifically, you need to
>derive your own classes from IDropSource and IDataObject, and then call
>DoDragDrop(). Refer to MSDN for more details.
>
>
>Gambit
>
>
So much for beautifully, but if I want to insert (for instance in Word) formatted text. I tried to do this inserting text in format HTML. The Following code does not work. As it is correct to do this?
void __fastcall TForm1::DBGrid1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
if(!Shift.Contains(ssLeft)) return;
TGridCoord GC = DBGrid1->MouseCoord(X, Y);
if(GC.X || GC.Y) return;
m_bDragMode = true;
TStringList *sl = new TStringList();
sl->Add("<HTML>");
sl->Add("<BODY>");
sl->Add("<B>bold.</B> <I><B>This is bold italic.</B></I> <I>This</I>");
sl->Add("</BODY>");
sl->Add("</HTML>");
wstr = sl->Text;
delete sl;
}
void __fastcall TForm1::DBGrid1MouseMove(TObject *Sender,
TShiftState Shift, int X, int Y)
{
if(m_bDragMode && Shift.Contains(ssLeft)) {
USES_CONVERSION;
TDropSource* pdsrc = new TDropSource;
if(pdsrc == NULL)
return;
pdsrc->AddRef();
TDataObject* pdobj = new TDataObject(pdsrc);
if(pdobj == NULL)
return;
pdobj->AddRef();
FORMATETC fmtetc = {0};
fmtetc.cfFormat = RegisterClipboardFormat("HTML Format");//CF_TEXT;
fmtetc.dwAspect = DVASPECT_CONTENT;
fmtetc.lindex = -1;
fmtetc.tymed = TYMED_HGLOBAL;
STGMEDIUM medium = {0};
medium.tymed = TYMED_HGLOBAL;
TCHAR* str = OLE2T(wstr.c_bstr());
medium.hGlobal = GlobalAlloc(GMEM_MOVEABLE, strlen(str)+1); //for NULL
TCHAR* pMem = (TCHAR*)GlobalLock(medium.hGlobal);
strcpy(pMem,str);
GlobalUnlock(medium.hGlobal);
pdobj->SetData(&fmtetc,&medium,TRUE);
TDragSourceHelper dragSrcHelper;
TPoint ptDrag(X, Y);
dragSrcHelper.InitializeFromWindow(DBGrid1->Handle, ptDrag, pdobj);
DWORD dwEffect;
HRESULT hr = ::DoDragDrop(pdobj, pdsrc, DROPEFFECT_COPY, &dwEffect);
pdsrc->Release();
pdobj->Release();
m_bDragMode = false;
}
}
Technical Details
Message-ID:
<42fdfe35$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<42e93634@newsgroups.borland.com> <42e94260$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,fe3349103cecbbb9 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Gizmo" <_gizmo@mail.ru> Sender: "Gizmo" <_gizmo@mail.ru> Reply-To: "Gizmo" <_gizmo@mail.ru> Subject: Re: Dragging from application to explorer Newsgroups: borland.public.cppbuilder.nativeapi X-User-Info: 195.201.33.13 X-Forwarded-For: unknown References: <42e93634@newsgroups.borland.com> <42e94260$1@newsgroups.borland.com> NNTP-Posting-Host: 207.105.83.66 Message-ID: <42fdfe35$1@newsgroups.borland.com> Date: 13 Aug 2005 07:05:41 -0700 X-Trace: newsgroups.borland.com 1123941941 207.105.83.66 (13 Aug 2005 07:05:41 -0700) Lines: 80 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail