Click here to Skip to main content
15,861,172 members
Articles / Desktop Programming / WTL

Form Designer

26 Jul 2021CPOL24 min read 349.8K   82.5K   230  
Component for adding scriptable forms capabilities to an application.
// DragFrame.h: interface for the CDragFrame class.
//
// Author : David Shepherd
//			Copyright (c) 2002, DaeDoe-Software
//
/////////////////////////////////////////////////////////////////////////////

#if !defined(AFX_DRAGFRAME_H__BB43CD30_1F17_11D6_B6A6_EAD35813C044__INCLUDED_)
#define AFX_DRAGFRAME_H__BB43CD30_1F17_11D6_B6A6_EAD35813C044__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

/////////////////////////////////////////////////////////////////////////////
// forwards
class CDragFrameNotifySink;

/////////////////////////////////////////////////////////////////////////////
// CDragFrame
class CDragFrame : public CWindowImpl<CDragFrame>
{
public:
	// drag handles
	enum DragHandle {
		DragHandleNone			= 0,
		DragHandleTopLeft		= (1 << 0),
		DragHandleTop			= (1 << 1),
		DragHandleTopRight		= (1 << 2),
		DragHandleRight			= (1 << 3),
		DragHandleBottomRight	= (1 << 4),
		DragHandleBottom		= (1 << 5),
		DragHandleBottomLeft	= (1 << 6),
		DragHandleLeft			= (1 << 7),
		DragHandleAll			= 0xffffffff };
	// action
	enum Action { ActionNone, ActionMove, ActionSize };

private:
	// background color
	OLE_COLOR m_BackColor;
	// foreground color
	OLE_COLOR m_ForeColor;
	// associated window
	CWindow m_AssociatedWindow;
	// event notification sink
	CDragFrameNotifySink *m_pNotifySink;
	// bitmap of enabled drag handles
	DWORD m_EnabledDragHandles;
	// this will be set TRUE if the drag frame can be used to move
	// as well as size the associated window
	BOOL m_AllowMove;
	// this will be set TRUE if the frame should be hollow
	BOOL m_Hollow;

	// the action being performed
	Action m_Action;
	// the drag handle which initiated the action (if any)
	DragHandle m_ActionDragHandle;
	// the cursor position when the action was initiated
	CPoint m_ActionOrigin;
	// this will be set TRUE if the action is in limbo
	BOOL m_ActionInLimbo;

	// determines if the the specified drag handle is enabled
	BOOL IsDragHandleEnabled(DragHandle Handle) const;
	// returns the specified drag handle rectangle
	CRect GetDragHandleRect(DragHandle Handle) const;
	// determines which drag handle (if any) is located at the passed position
	DragHandle HitTest(const CPoint &Pos) const;

public:
	CDragFrame();
	virtual ~CDragFrame();

	// sets the drag frame colors
	void SetColors(OLE_COLOR BackColor,OLE_COLOR ForeColor);
	// returns the drag frame colors
	void GetColors(OLE_COLOR &BackColor,OLE_COLOR &ForeColor) const;
	// returns the drag frame size (or thickness)
	long GetFrameSize() const;
	// creates the drag frame
	BOOL Create(const CWindow &Parent,const CWindow &AssociatedWindow,
		CDragFrameNotifySink *pNotifySink,DWORD EnabledDragHandles=DragHandleAll,
		BOOL AllowMove=TRUE,BOOL Hollow=FALSE);
	// auto positions and sizes the drag frame to hug the associated window
	void AutoPositionAndSize();
	// enables the specified drag handles
	void EnableDragHandles(DWORD EnabledDragHandles);
	// activates the drag frame
	void ExternalActivate();

BEGIN_MSG_MAP(CDragFrame)
MESSAGE_HANDLER(WM_PAINT, OnPaint)
MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd)
MESSAGE_HANDLER(WM_SETCURSOR, OnSetCursor)
MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
MESSAGE_HANDLER(WM_LBUTTONUP, OnLButtonUP)
MESSAGE_HANDLER(WM_RBUTTONUP, OnRButtonUp)
MESSAGE_HANDLER(WM_MOUSEMOVE, OnMouseMove)
MESSAGE_HANDLER(WM_CAPTURECHANGED, OnCaptureChanged)
MESSAGE_HANDLER(WM_SIZE, OnSize)
END_MSG_MAP()

// message handlers
	LRESULT OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnEraseBkgnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnSetCursor(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnLButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnLButtonUP(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnRButtonUp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnMouseMove(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnCaptureChanged(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
};

/////////////////////////////////////////////////////////////////////////////
// CDragFrameNotifySink
class CDragFrameNotifySink
{
public:
	// move
	virtual void DFNS_BeginMove()=0;
	virtual void DFNS_Move(long cx,long cy)=0;
	virtual void DFNS_EndMove()=0;
	// size
	virtual void DFNS_BeginSize()=0;
	virtual void DFNS_Size(CDragFrame::DragHandle Handle,long cx,long cy)=0;
	virtual void DFNS_EndSize()=0;
	// context menu
	virtual void DFNS_ContextMenu()=0;
};

#endif // !defined(AFX_DRAGFRAME_H__BB43CD30_1F17_11D6_B6A6_EAD35813C044__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
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