⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tlbarpg.cpp

📁 The programs and applications on this disk have been carefully tested, but are not guaranteed for
💻 CPP
字号:
// TlBarPg.cpp : implementation file
//

#include "stdafx.h"
#include "wzd.h"
#include "TlBarPg.h"
#include "WzdTlBar.h"
#include "WzdPrjct.h"
#include "MainFrm.h"

#include <afxcmn.h>
#include <afxpriv.h>

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


/////////////////////////////////////////////////////////////////////////////
// CToolBarPage property page

IMPLEMENT_DYNCREATE(CToolBarPage, CPropertyPage)

CToolBarPage::CToolBarPage() : CPropertyPage(CToolBarPage::IDD)
{
	//{{AFX_DATA_INIT(CToolBarPage)
	//}}AFX_DATA_INIT
	m_bMoving=FALSE;
	m_nButtonCount=0;
	m_pToolBar=NULL;
	m_hMoveCursor=AfxGetApp()->LoadCursor(IDI_MOVING_BUTTON);
}

CToolBarPage::~CToolBarPage()
{
}

void CToolBarPage::DoDataExchange(CDataExchange* pDX)
{
	CPropertyPage::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CToolBarPage)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CToolBarPage, CPropertyPage)
	//{{AFX_MSG_MAP(CToolBarPage)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CToolBarPage message handlers

BOOL CToolBarPage::OnInitDialog() 
{
	CPropertyPage::OnInitDialog();

	// create and load breeder toolbar
	m_ToolBar.Create(this);
	m_ToolBar.LoadToolBar(IDR_MAINFRAME);

	// load breeder toolbar bitmap
	m_bitmap.LoadBitmap(IDR_MAINFRAME);

	// get window and button count
	m_nButtonCount=m_ToolBar.GetToolBarCtrl().GetButtonCount();


	CRect rect;
	GetClientRect(&rect);
	m_xBitmapStart=rect.Width()/6;
	m_yBitmapStart=rect.Height()/6;

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CToolBarPage::OnPaint() 
{
	CPaintDC dc(this); // device context for painting

	// display breeder toolbar bitmap
	CDC memDC;
	memDC.CreateCompatibleDC(&dc);
	memDC.SelectObject(&m_bitmap);

	int x=m_xBitmapStart;
	int y=m_yBitmapStart;
	for (int i=0; i<m_nButtonCount; i++)
	{
		dc.BitBlt(x,y,BUTTON_WIDTH,BUTTON_HEIGHT, &memDC, i*BUTTON_WIDTH, 0, SRCCOPY);
		x+=BUTTON_WIDTH+BUTTON_XSPACING;
	}
	memDC.DeleteDC();
}

BOOL CToolBarPage::OnSetActive() 
{
	SetCapture();
	return CPropertyPage::OnSetActive();
}

BOOL CToolBarPage::OnKillActive() 
{
	ReleaseCapture();	
	return CPropertyPage::OnKillActive();
}

void CToolBarPage::OnLButtonDown(UINT nFlags, CPoint point) 
{
	m_bMoving=FALSE;
	ClientToScreen(&point);
	CWnd *pWnd=WindowFromPoint(point);

	// if point is parent or child of
	if (pWnd!=this && (pWnd==GetParent() || GetParent()->IsChild(pWnd)))
	{
		CPoint pt(point);
		pWnd->ScreenToClient(&pt);
		if (pt.y>=0)
		{
			pWnd->SendMessage(WM_LBUTTONDOWN,nFlags,MAKELONG(pt.x,pt.y));
		}
		else
		{
			UINT ht=pWnd->SendMessage(WM_NCHITTEST,0,MAKELONG(point.x,point.y));
			pWnd->SendMessage(WM_NCLBUTTONDOWN,ht,MAKELONG(point.x,point.y));
		}
		return;
	}

	// see if this is a toolbar button
	if (m_pToolBar=GetToolBar(point))
	{

		m_nButtonMoved=GetButtonIndex(m_pToolBar, point);
	 	m_pToolBar->GetToolBarCtrl().GetButton(m_nButtonMoved,&m_tbbutton);
		m_bMoving=TRUE;
		::SetCursor(m_hMoveCursor);
	}

	// else if this window
	else if (pWnd==this)
	{
		ScreenToClient(&point);
		point.Offset(-m_xBitmapStart,-m_yBitmapStart);
		CRect rect(0,0,(BUTTON_WIDTH+BUTTON_XSPACING)*m_nButtonCount,BUTTON_HEIGHT);
		if (rect.PtInRect(point))
		{
			m_nButtonMoved=0;
			int i=point.x/(BUTTON_WIDTH+BUTTON_XSPACING);
			for (int j=0;j<m_nButtonCount;j++)
			{
				UINT k;
				int l;
				m_ToolBar.GetButtonInfo(j,k,k,l);
				if (l==i)
				{
					m_nButtonMoved=j;
					break;
				}
			}
	 		m_ToolBar.GetToolBarCtrl().GetButton(m_nButtonMoved,&m_tbbutton);
			m_bMoving=TRUE;
			::SetCursor(m_hMoveCursor);
			SetCapture();
		}
	}

	CPropertyPage::OnLButtonDown(nFlags, point);
}

void CToolBarPage::OnLButtonUp(UINT nFlags, CPoint point) 
{
	if (m_bMoving)
	{

		// delete button from source toolbar
		if (m_pToolBar)
		{
			m_pToolBar->GetToolBarCtrl().DeleteButton(m_nButtonMoved);
		}

		// if dropped anywhere but toolbar property page
		CRect rect;
		ClientToScreen(&point);
		GetWindowRect(&rect);
		if (!rect.PtInRect(point))
		{
			// if dropped on existing toolbar, add button to it
			CToolBar *pToolBar;
			if (pToolBar=GetToolBar(point))
			{
				int i = GetButtonIndex(pToolBar,point);
				pToolBar->GetToolBarCtrl().InsertButton(i,&m_tbbutton);
				UpdateToolBar(pToolBar);
			}
			// else create a new toolbar and add our button to it
			else
			{
			 	pToolBar = (CWzdToolBar*)new CWzdToolBar;
				CList<CToolBar*,CToolBar*> *pList=((CMainFrame*)AfxGetMainWnd())->GetToolBarList();
				pList->AddTail( pToolBar );
				pToolBar->Create( GetParentFrame(), WS_CHILD|WS_VISIBLE|CBRS_TOP|CBRS_TOOLTIPS );
				SIZE sizeButton, sizeImage;
				sizeImage.cx = BUTTON_WIDTH;
				sizeImage.cy = BUTTON_HEIGHT;
				sizeButton.cx = sizeImage.cx + BUTTON_XSPACING;
				sizeButton.cy = sizeImage.cy + BUTTON_YSPACING;
				pToolBar->SetSizes(sizeButton, sizeImage);
				pToolBar->EnableDocking(CBRS_ALIGN_ANY | CBRS_FLOAT_MULTI);

				// add all possible tool button bitmaps
				pToolBar->GetToolBarCtrl().AddBitmap(m_nButtonCount,IDR_MAINFRAME);

				// add new button to this new toolbar
				pToolBar->GetToolBarCtrl().InsertButton(0,&m_tbbutton);

				UINT nMode;
				BOOL bHorz;
				if (GetToolBarNear(point,nMode,bHorz))
				{
					// dock toolbar centered on cursor
					CSize size = pToolBar->CalcFixedLayout(FALSE,bHorz);
					if (bHorz)
						point.x-=size.cx/2;
					else
						point.y-=size.cy/2;
					CRect rectx(point,size);
			 		GetParentFrame()->DockControlBar(pToolBar,nMode,&rectx);
					pToolBar->Invalidate();
					GetParentFrame()->RecalcLayout();
				}
				else
				{
					GetParentFrame()->FloatControlBar( pToolBar, point, CBRS_ALIGN_TOP); 
				}
			}
		}
		// else update source toolbar if any
		else if (m_pToolBar)
		{
			UpdateToolBar(m_pToolBar);

			// if no buttons left on toolbar, delete it
			if (m_pToolBar && m_pToolBar->GetToolBarCtrl().GetButtonCount()==0)
			{
				POSITION pos;
				CList<CToolBar*,CToolBar*> *pList=((CMainFrame*)AfxGetMainWnd())->GetToolBarList();
				if (pos=pList->Find(m_pToolBar))
				{
					pList->RemoveAt(pos);
					m_pToolBar->m_bAutoDelete=TRUE;
					if (!m_pToolBar->IsFloating())
					{
						m_pToolBar->SendMessage(WM_CLOSE);
					}
					else
					{
						CDockBar* pDockBar = m_pToolBar->m_pDockBar;
						CMiniDockFrameWnd* pDockFrame =	(CMiniDockFrameWnd*)pDockBar->GetParent();
						pDockFrame->ShowWindow(SW_HIDE);
						pDockFrame->SendMessage(WM_CLOSE);
					}
				}
			}
		}
		m_bMoving=FALSE;
		::SetCursor(AfxGetApp()->LoadStandardCursor(IDC_ARROW));
	}

	CPropertyPage::OnLButtonUp(nFlags, point);
}

//////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////
// Helper Toolbar Functions

CToolBar *CToolBarPage::GetToolBar(CPoint point)
{
	CRect rect;
	CList<CToolBar*,CToolBar*> *pList=((CMainFrame*)AfxGetMainWnd())->GetToolBarList();
	if (!pList->IsEmpty())
	{
		for (POSITION pos = pList->GetHeadPosition(); pos; )
		{	
			CToolBar *pToolBar=pList->GetNext(pos);
			pToolBar->GetWindowRect(&rect);
			if (rect.PtInRect(point))
			{
				return pToolBar;
			}
		}
	}
	return(NULL);
}

int CToolBarPage::GetButtonIndex(CToolBar *pToolBar, CPoint point)
{
	CRect rect;
	pToolBar->ScreenToClient(&point);
	int nButtons = pToolBar->GetToolBarCtrl().GetButtonCount();
	for (int i=0; i<nButtons; i++)
	{
		pToolBar->GetItemRect(i,&rect);
		if (rect.PtInRect(point))
		{
			return(i);
		}
	}
	return(-1);
}

void CToolBarPage::UpdateToolBar(CToolBar *pToolBar)
{
	if (pToolBar)
	{
		if (pToolBar->IsFloating())
		{
			CDockBar* pDockBar = pToolBar->m_pDockBar;
			CMiniDockFrameWnd* pDockFrame =	(CMiniDockFrameWnd*)pDockBar->GetParent();
			pDockFrame->RecalcLayout(TRUE);
			pDockFrame->UpdateWindow();
		}
		else
		{
			pToolBar->Invalidate();
			GetParentFrame()->RecalcLayout();
		}
	}
}

BOOL CToolBarPage::GetToolBarNear(CPoint &point,UINT &nMode,BOOL &bHorz)
{
	CRect rect;
	BOOL bDock = FALSE;
	CDockState dockstate;
	((CMainFrame *)AfxGetMainWnd())->GetDockState(dockstate);
	for (int i=0; i<dockstate.m_arrBarInfo.GetSize(); i++)
	{
		CControlBarInfo *pBarInfo = (CControlBarInfo *)dockstate.m_arrBarInfo[i];
		CControlBar *pBar = (CControlBar *)pBarInfo->m_pBar;

		// if this bar is visible, can be docked and isn't floating, check it out
		if (pBarInfo->m_bVisible && pBarInfo->m_bDocking && !pBar->IsFloating())
		{
			pBarInfo->m_pBar->GetWindowRect(&rect);
			DWORD dwStyle = pBar->GetBarStyle();
			if (bHorz = (dwStyle & CBRS_ORIENT_HORZ))
			{
				// if user clicked in this region, dock new toolbar here
				if (point.y>=rect.top && point.y<rect.bottom)
				{
					bDock=TRUE;
					point.y=rect.top;
					if (dwStyle & CBRS_ALIGN_TOP)
						nMode = AFX_IDW_DOCKBAR_TOP;
					else
						nMode = AFX_IDW_DOCKBAR_BOTTOM;
					break;
				}
			}
			else
			{
				// else if user clicked in this region, dock here
				if (point.x>=rect.left && point.x<rect.right)
				{
					bDock=TRUE;
					point.x=rect.left;
					if (dwStyle & CBRS_ALIGN_LEFT)
						nMode = AFX_IDW_DOCKBAR_LEFT;
					else
						nMode = AFX_IDW_DOCKBAR_RIGHT;
					break;
				}
			}
		}
	}
	return(bDock);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -