Click here to Skip to main content
15,895,142 members
Articles / Desktop Programming / WTL

WTL Docking Windows

Rate me:
Please Sign up or sign in to vote.
4.89/5 (73 votes)
21 Nov 20077 min read 854.4K   14.1K   215  
This is an implementation of docking windows for the WTL library
// Copyright (c) 2000
// Sergey Klimov (kidd@ukr.net)

#ifndef WTL_DW_DDTRACKER_H_INCLUDED_
#define WTL_DW_DDTRACKER_H_INCLUDED_

#include<cassert>

class IDDTracker
{
public:
    virtual void BeginDrag(){}
    virtual void EndDrag(bool /*bCanceled*/){}
    virtual void OnMove(long /*x*/, long /*y*/){}

    virtual void OnCancelDrag(long /*x*/, long /*y*/){}
    virtual bool OnDrop(long /*x*/, long /*y*/)
	{
		return true;
	}
    virtual bool OnDropRightButton(long x, long y)
    {
       return OnDrop(x,y);
    }
    virtual bool OnDropLeftButton(long x, long y)
    {
       return OnDrop(x,y);
    }
    virtual bool ProcessWindowMessage(MSG* /*pMsg*/)
    {
       return false;
    }


};
template<class T>
class CDDTrackerBaseT
{
public:
    void BeginDrag(){}
    void EndDrag(bool /*bCanceled*/){}
    void OnMove(long /*x*/, long /*y*/){}

    void OnCancelDrag(long /*x*/, long /*y*/){}
    bool OnDrop(long /*x*/, long /*y*/)
	{
		return true;
	}
    bool OnDropRightButton(long x, long y)
    {
       return static_cast<T*>(this)->OnDrop(x,y);
    }
    bool OnDropLeftButton(long x, long y)
    {
       return static_cast<T*>(this)->OnDrop(x,y);
    }
    bool ProcessWindowMessage(MSG* /*pMsg*/)
    {
       return false;
    }
};

template<class T>
bool TrackDragAndDrop(T& tracker,HWND hWnd)
{
    bool bResult=true;
    tracker.BeginDrag();
    ::SetCapture(hWnd);
    MSG msg;
    while((::GetCapture()==hWnd)&&
            (GetMessage(&msg, NULL, 0, 0)))
    {
		if(!tracker.ProcessWindowMessage(&msg))
		{
		  switch(msg.message)
		  {
			   case WM_MOUSEMOVE:
					tracker.OnMove(GET_X_LPARAM( msg.lParam), GET_Y_LPARAM(msg.lParam));
					break;
			   case WM_RBUTTONUP:
					::ReleaseCapture();
					bResult=tracker.OnDropRightButton(GET_X_LPARAM( msg.lParam), GET_Y_LPARAM(msg.lParam));
					break;
			   case WM_LBUTTONUP:
					::ReleaseCapture();
					bResult=tracker.OnDropLeftButton(GET_X_LPARAM( msg.lParam), GET_Y_LPARAM(msg.lParam));
					break;
			   case WM_KEYDOWN:
					if(msg.wParam!=VK_ESCAPE)
						break;
			   case WM_RBUTTONDOWN:
			   case WM_LBUTTONDOWN:
					::ReleaseCapture();
					tracker.OnCancelDrag(GET_X_LPARAM( msg.lParam), GET_Y_LPARAM(msg.lParam));
					bResult=false;
					break;
			   case WM_SYSKEYDOWN:
					::ReleaseCapture();
					tracker.OnCancelDrag(GET_X_LPARAM( msg.lParam), GET_Y_LPARAM(msg.lParam));
					bResult=false;
			   default:
					DispatchMessage(&msg);
		  }
		}
    }
    tracker.EndDrag(!bResult);
    assert(::GetCapture()!=hWnd);
    return bResult;
}

class CDropPointTracker 
	: public CDDTrackerBaseT<CDropPointTracker>
{
public:
	bool OnDrop(long x, long y)
	{
		pt_.x=x;
		pt_.y=y;
		return true;
	}
	const POINT& DropPoint(void) const
	{
		return pt_;
	}
private:
	POINT pt_;
};

#endif // WTL_DW_DDTRACKER_H_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 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
Software Developer
Ireland Ireland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions