
Problem in OLE DRAG AND DROP FROM VB SOURCE APP TO VC++ TARGET APP
I have developed an application in VB 5.0 which is to support drag and
drop operations.
The target application is developed in VC++ 2.0.
The user should be able to drag the text in a text control in one of the
forms of
the VB application and drop on to the view of the target VC++
application.
The target application expects a custom data format, So I register the
data format in the
start drag event of the source application and fill a byte array with
the appropriate
string and call setdata function to place the data on the dataobject.
The following is the exact code:
Public Declare Function RegisterClipboardFormat Lib _
"user32.dll" Alias "RegisterClipboardFormatA" _
(ByVal lpszFormat$) As Integer
Private Sub txtDeviceName_MouseDown(Button As Integer, Shift As Integer,
X As Single, Y As Single)
txtDeviceName.OLEDrag
End Sub
Private Sub txtDeviceName_OLEStartDrag(Data As DataObject,
AllowedEffects As Long)
Dim MyFormat As Integer
Dim szFormat As String
Dim szData As String, szTerminator As String
Dim I As Integer
szData = txtDeviceName.Text
szTerminator = "\0"
szData = szData + "::"
ReDim A(Len(szData) + 3)
For I = 0 To (Len(szData) - 1)
A(I) = Asc(Mid(szData, I + 1, 1))
Next I
A(I + 1) = 0
szFormat = "Catseye_NodeAddress"
MyFormat = RegisterClipboardFormat(szFormat)
If (txtDeviceName.Text <> "") Then
AllowedEffects = vbDropEffectCopy 'Or vbDropEffectMove
Data.Clear
'Data.SetData A, MyFormat
Data.SetData szData, vbCFText
Else
AllowedEffects = vbDropEffectNone
End If
End Sub
The following is the code of the target VC++ application.
COleDropTarget m_dropTarget;
void COletestView::OnInitialUpdate()
{
CView::OnInitialUpdate();
m_dropTarget.Register(this);
m_pSelection = NULL;
Quote:
}
DROPEFFECT COletestView::OnDragOver(COleDataObject* pDataObject, DWORD
dwKeyState, CPoint point)
{
UINT nCatseye = ::RegisterClipboardFormat("Catseye_NodeAddress");
if(pDataObject->IsDataAvailable(nCatseye))
return DROPEFFECT_COPY;
else
return DROPEFFECT_NONE;
return CView::OnDragOver(pDataObject, dwKeyState, point);
Quote:
}
BOOL COletestView::OnDrop(COleDataObject* pDataObject, DROPEFFECT
dropEffect, CPoint point)
{
UINT nCatseye = ::RegisterClipboardFormat("Catseye_NodeAddress");
HGLOBAL hSer;
if((hSer = pDataObject->GetGlobalData(nCatseye))!=NULL)
{
char* lpStr = (char*) GlobalLock(hSer);
m_szData = lpStr;
Invalidate();
GlobalUnlock(hSer);
}
return CView::OnDrop(pDataObject, dropEffect, point);
Quote:
}
The GetGlobalData function returns NULL in the Target application.
NOTE: I developed a test target application in VB 5.0 , in that case it
works fine.
Also, If the target application specifies the dropeffect as
DROPEFFECT_LINK,
How am to specify it in the allowedeffects parameter of the source
application since
there are only three effects namely vbdropeffectcopy,vbdropeffectmove
and vbdropeffectnone.
But for now even DROPEFFECT_COPY doesn't seem to work.
Am I missing anything important??
Thankyou,
Yours Sincerly,
Rajagopalan Anand.
Senior Software Engineer,
Eutech {*filter*}netics,
Singapore