Click here to Skip to main content
15,884,628 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 831.1K   14.1K   215  
This is an implementation of docking windows for the WTL library
// Copyright (c) 2000
// Sergey Klimov (kidd@ukr.net)

#if !defined(AFX_DDTRACKER_H__36DE1857_9CA8_4B9C_B263_C6A7987FF764__INCLUDED_)
#define AFX_DDTRACKER_H__36DE1857_9CA8_4B9C_B263_C6A7987FF764__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 void OnDrop(long /*x*/, long /*y*/){}
    virtual void OnDropRightButton(long x, long y)
    {
       OnDrop(x,y);
    }
    virtual void OnDropLeftButton(long x, long y)
    {
       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*/){}
    void OnDrop(long /*x*/, long /*y*/){}
    void OnDropRightButton(long x, long y)
    {
       ((T*)this)->OnDrop(x,y);
    }
    void OnDropLeftButton(long x, long y)
    {
       ((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();
					tracker.OnDropRightButton(GET_X_LPARAM( msg.lParam), GET_Y_LPARAM(msg.lParam));
					break;
			   case WM_LBUTTONUP:
					::ReleaseCapture();
					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;
}
#endif // !defined(AFX_DDTRACKER_H__36DE1857_9CA8_4B9C_B263_C6A7987FF764__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