Click here to Skip to main content
15,895,746 members
Articles / Desktop Programming / MFC

Screen Designer Classes

Rate me:
Please Sign up or sign in to vote.
4.93/5 (39 votes)
7 Mar 20045 min read 147.8K   3.9K   109  
Screen Designer Classes for MFC applications
// Copyright � 2002 Oink!
// FILE NAME	: DynDropTarget.cpp
// DESCRIPTION	: Provides basic member variables and functions for all
//				: CWnd objects to act as drop target for control dragged from
//				: toolbar
//
// PROGRAMMER	DATE		PATCH	DESCRIPTION
// ============	===========	=======	===============================================

#include "stdafx.h"
#include "dynscreen.h"
#include "dyndroptarget.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDynDropTarget

IMPLEMENT_DYNCREATE(CDynDropTarget, CCmdTarget)

CDynDropTarget::CDynDropTarget()
{
}

CDynDropTarget::~CDynDropTarget()
{
}


BEGIN_MESSAGE_MAP(CDynDropTarget, COleDropTarget)
	//{{AFX_MSG_MAP(CDynDropTarget)
		// NOTE - the ClassWizard will add and remove mapping macros here.
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDynDropTarget message handlers

BOOL CDynDropTarget::OnDrop(CWnd* pWnd, COleDataObject* pDataObject, DROPEFFECT dropEffect,CPoint point)
{
	// Detects a drop and adds a new control to the screen
	
	if (!(pDataObject->IsDataAvailable(m_nIDClipFormat)))
		return FALSE; 
	
	STGMEDIUM stgmedium;
	int nType;

	{
		if (pDataObject->GetData(m_nIDClipFormat, &stgmedium))
		{
			HGLOBAL hGlobal = stgmedium.hGlobal;
			LPCTSTR pText = (LPCTSTR)GlobalLock(hGlobal);
			nType = atoi(pText);
			// free memory
			GlobalUnlock(hGlobal);
			GlobalFree(hGlobal);
		}

		pWnd->SendMessage(WM_ADDCONTROL,(WPARAM)nType,(LPARAM)&point);
	}

	return FALSE;
}

DROPEFFECT CDynDropTarget::OnDragEnter( CWnd* pWnd, COleDataObject* pDataObject, DWORD dwKeyState, CPoint point )
{
	// Determines if data is available to drop

	if (pDataObject->IsDataAvailable(m_nIDClipFormat))
			return DROPEFFECT_COPY;

	return DROPEFFECT_NONE; 
}

DROPEFFECT CDynDropTarget::OnDragOver( CWnd* pWnd, COleDataObject* pDataObject, DWORD dwKeyState, CPoint point )
{
	// Determines if data is available to drop

	CString strPos;
	strPos.Format(" x: %d, y: %d ",point.x,point.y);

	if (pDataObject->IsDataAvailable(m_nIDClipFormat))
		return DROPEFFECT_COPY;

	return DROPEFFECT_NONE; 
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United Kingdom United Kingdom
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions