Article ID: 200491
Article Last Modified on 11/21/2006
void ConvertXYtoTwips(float FAR* x, float FAR* y)
{
// Get a device context.
HDC hdc = GetDC(NULL);
// Determine how many Twips are in one pixel.
CPoint pOne(1, 1);
SetMapMode(hdc, MM_TWIPS);
DPtoLP(hdc, &pOne, 1);
// Convert *x and *y to Twips units.
float xx = *x * pOne.x;
float yy = *y * pOne.y;//NOTE: both *y and pOne.y are negative values.
// Release the device context.
ReleaseDC(NULL, hdc);
// X and y are in Twips pixel units.
*x = xx;
*y = yy;
}
BEGIN_EVENTSINK_MAP(CTestDlg, CDialog)
//{{AFX_EVENTSINK_MAP(CTestDlg)
ON_EVENT(CTestDlg, IDC_TREECTRL1, 1555 /* OLEDragDrop */,
OnOLEDragDropTreectrl1,
VTS_PDISPATCH VTS_PI4 VTS_PI2 VTS_PI2 VTS_PR4 VTS_PR4)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CTestDlg::OnOLEDragDropTreectrl1(
LPDISPATCH FAR* Data, long FAR* Effect,
short FAR* Button, short FAR* Shift, float FAR* x, float FAR* y)
{
// Convert x and y to Twips pixel units.
ConvertXYtoTwips(x, y);
// Determine which node should be highlighted in the
// Microsoft TreeView control.
CNode node = m_TreeView.HitTest(*x, *y);
if (node)
{
VARIANT var;
var.vt = VT_DISPATCH;
var.pdispVal = node.m_lpDispatch;
m_TreeView.SetDropHighlight(&var);
}
}
// The node becomes a child node of the node named it is connected to.
#define tvwChild (short) 4
#include "node.h" // for CNode class
BOOL CTestDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// ...
m_TreeView.SetOLEDropMode(1);
CNodes nodes = m_TreeView.GetNodes();
nodes.Clear();
COleVariant NOPARAM( DISP_E_PARAMNOTFOUND, VT_ERROR );
CNode node = nodes.Add(
LPVARIANT(NOPARAM), // VARIANT* Relative
LPVARIANT(NOPARAM), // VARIANT* Relationship
LPVARIANT(COleVariant("R")), // VARIANT* Key
LPVARIANT(COleVariant("First")), // VARIANT* Text
LPVARIANT(NOPARAM), // VARIANT* Image
LPVARIANT(NOPARAM)); // VARIANT* SelectedImage
node = nodes.Add(
LPVARIANT(COleVariant("R")), // VARIANT* Relative
LPVARIANT(COleVariant( tvwChild ) ),// VARIANT* Relationship
LPVARIANT(COleVariant("C1")), // VARIANT* Key
LPVARIANT(COleVariant("Child 1")), // VARIANT* Text
LPVARIANT(NOPARAM), // VARIANT* Image
LPVARIANT(NOPARAM)); // VARIANT* SelectedImage
node = nodes.Add(
LPVARIANT(COleVariant("R")), // VARIANT* Relative
LPVARIANT(COleVariant( tvwChild ) ),// VARIANT* Relationship
LPVARIANT(COleVariant("C2")), // VARIANT* Key
LPVARIANT(COleVariant("Child 2")), // VARIANT* Text
LPVARIANT(NOPARAM), // VARIANT* Image
LPVARIANT(NOPARAM)); // VARIANT* SelectedImage
node = nodes.Add(
LPVARIANT(NOPARAM), // VARIANT* Relative
LPVARIANT(NOPARAM), // VARIANT* Relationship
LPVARIANT(COleVariant("S")), // VARIANT* Key
LPVARIANT(COleVariant("Second")), // VARIANT* Text
LPVARIANT(NOPARAM), // VARIANT* Image
LPVARIANT(NOPARAM)); // VARIANT* SelectedImage
return TRUE; // Return TRUE unless you set the focus to a control.
}
Additional query words: ocx
Keywords: kbbug kbcmnctrls kbdragdrop kbpending KB200491