Click here to Skip to main content
15,891,136 members
Articles / Desktop Programming / MFC

Drag & Drop in FlexGrid Using Arbitrary Formats

Rate me:
Please Sign up or sign in to vote.
4.76/5 (12 votes)
2 Jun 2003CPOL3 min read 129.6K   2.4K   30  
Implementing drag and rop within MS Flexgrid control using any format
#if !defined(AFX_SOURCEGRID_H__58A49E35_5888_4A98_B51E_BD8C96514D76__INCLUDED_)
#define AFX_SOURCEGRID_H__58A49E35_5888_4A98_B51E_BD8C96514D76__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// SourceGrid.h : header file
//
#include "MSFlexGrid.h"
#include <afxctl.h>

/////////////////////////////////////////////////////////////////////////////
// CSourceGrid window
const int SOURCE_ROWS = 2;
const int SOURCE_COLUMNS = 5;
const int RESOURCE_COUNT = SOURCE_ROWS*SOURCE_COLUMNS;

class CSourceGrid;
struct CellData
{
	int i_resourceNumber;
	CSourceGrid * p_gridSource;
};

class CSourceGrid : public CMSFlexGrid
{
// Construction
public:
	CSourceGrid();

// Attributes
public:
	void v_GetCurrentCellData(CellData & r_currentCellData);
	LPDISPATCH GetResourceIcon(int resourceNumber);

// Operations
public:
	static void DitherBlt (HDC hdcDest, int nXDest, int nYDest, int nWidth, 
				int nHeight, HBITMAP hbm, int nXSrc, int nYSrc);

	void AssignResource(int resourceNumber);
	void UnAssignResource(int resourceNumber);
protected:
	void v_UpdateCellDisplay();
	int GetResourceNumber(int row, int col);
	void v_GetImageListBitmap(IMAGEINFO & r_imageInfo, CBitmap & r_bitmap);


// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CSourceGrid)
	//}}AFX_VIRTUAL

// Implementation
public:
	virtual ~CSourceGrid();

	void Initialize();

	// Generated message map functions
protected:
	//{{AFX_MSG(CSourceGrid)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()

	afx_msg BOOL OnMouseMove(short Button, short Shift, long x, long y);
	afx_msg BOOL OnOLEStartDrag(LPDISPATCH FAR* Data, long FAR* AllowedEffects);
	afx_msg BOOL OnOLECompleteDrag(long FAR* Effect);
	DECLARE_EVENTSINK_MAP()

	CellData m_currentCellData;
	BOOL m_dragging;
	BOOL m_busy;

	BOOL m_resourcesAssigned[RESOURCE_COUNT];
	CPictureHolder m_iconsAvailable[RESOURCE_COUNT];
	CPictureHolder m_iconsAssigned[RESOURCE_COUNT];
};

/////////////////////////////////////////////////////////////////////////////

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_SOURCEGRID_H__58A49E35_5888_4A98_B51E_BD8C96514D76__INCLUDED_)

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
United States United States
Roaming halfway around the globe programming in C++, MFC, COM/ATL, WTL, C#, .NET, OLEDB, ADO, ADO/X.

Living under the pleasant weather of Irvine, California, Ferdie is a Computer Engineering graduate of Mapua Institute of Technology (MIT Smile | :) ) in Philippines. Developed GIS applications in Japan for 5 years. Now a member of a team developing Windows GUI and real time software for semi-robotic equipments.

Comments and Discussions