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

📄 maintoolbar.cpp

📁 这是一个用VC++编写的FLSHPLAYER
💻 CPP
字号:
// MainToolBar.cpp : implementation file
//

#include "stdafx.h"
#include "FlashPlay.h"
#include "MainToolBar.h"

#include "FlashPlayView.h"
#include "MainFrm.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMainToolBar

CMainToolBar::CMainToolBar()
{
}

CMainToolBar::~CMainToolBar()
{
}


BEGIN_MESSAGE_MAP(CMainToolBar, CToolBar)
	//{{AFX_MSG_MAP(CMainToolBar)
	ON_WM_HSCROLL()
	ON_WM_VSCROLL()
	ON_WM_CREATE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMainToolBar message handlers

CSliderCtrl & CMainToolBar::GetSlider()
{
    return m_wndSlider;
}



void CMainToolBar::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	// TODO: Add your message handler code here and/or call default
    // when the user clicks a window’s horizontal scroll bar 水平
	
    // This line maps the slider control to the scroll bar parameter
	CSliderCtrl* pSlider = (CSliderCtrl*) pScrollBar;
	m_wndSpinCurFrame.SetPos(pSlider->GetPos());

    // Here we can load our own designed cursor while sliding. NICEEE, Ha :-)
	// HCURSOR hCursor = AfxGetApp()->LoadCursor(IDC_CURSOR_LEFTRIGHT); 
	// ::SetCursor(hCursor);

    // 广播自定义消息 WM_USER_CHANG_POSITION 
    CMainFrame *pFrame = 
             (CMainFrame*)AfxGetApp()->m_pMainWnd;
    CFlashPlayView *pView = (CFlashPlayView *) pFrame->GetActiveView();
    (CFlashPlayView *)pView->PostMessage(WM_USER_CHANG_POSITION, 1,
	        (LPARAM) (UINT) pSlider->GetPos() );

	CToolBar::OnHScroll(nSBCode, nPos, pScrollBar);
}

void CMainToolBar::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) 
{
	// TODO: Add your message handler code here and/or call default

    // when the user clicks the window’s vertical scroll bar 垂直
	CSpinButtonCtrl* pwndSpin = (CSpinButtonCtrl*) pScrollBar;
    m_wndSlider.SetPos( pwndSpin->GetPos() );
	// HCURSOR hCursor = AfxGetApp()->LoadCursor(IDC_CURSOR_UPDOWN); 
	// ::SetCursor(hCursor);
    
    // 广播自定义消息 WM_USER_CHANG_POSITION 
    CMainFrame *pFrame = 
             (CMainFrame*)AfxGetApp()->m_pMainWnd;
    CFlashPlayView *pView = (CFlashPlayView *) pFrame->GetActiveView();
    (CFlashPlayView *)pView->PostMessage(WM_USER_CHANG_POSITION, 1,
	        (LPARAM) (UINT) pwndSpin->GetPos() );

	CToolBar::OnVScroll(nSBCode, nPos, pScrollBar);
}

int CMainToolBar::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CToolBar::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here

	//########## You must modify the ID to your define ############//
    // Load the dummy buttons toolbar.
    if (!LoadToolBar (IDR_MAINFRAME))
        return -1;

    //##################################################//
	// Spinner Toolbar button modifying method 
	
	// DC to select font into
	CClientDC dc(this);
	// CFont object used to set the desired control fonts
	m_font.CreatePointFont (100, _T ("MS Sans Serif"));
    CFont* pOldFont = dc.SelectObject (&m_font);

    // TEXTMETRIC is Useful to measure and place the controls
	// in the desired positions
	TEXTMETRIC tm;
	dc.GetTextMetrics(&tm);
	int cxChar = tm.tmAveCharWidth;
	int cyChar = tm.tmHeight + tm.tmExternalLeading;
	dc.SelectObject (pOldFont);

	//################# the set of spinners #################

	// Edit Buddy to Spinner //
    CRect rect;

    int index = 0;
    while(GetItemID(index)!=ID_DUMMY_EDIT) index++;

    SetButtonInfo (index, ID_DUMMY_EDIT, TBBS_SEPARATOR , cxChar * 20);
	GetItemRect (index, &rect);
    rect.bottom = rect.top + (cyChar + 6);
    rect.right = rect.left + cxChar * 9-2;
	
	if(!m_wndEditCurFrame.CreateEx(WS_EX_CLIENTEDGE, // Make a 3D-border
          _T("EDIT"), NULL,
      WS_TABSTOP | ES_AUTOHSCROLL | ES_LEFT | ES_NOHIDESEL | WS_VISIBLE | WS_CHILD,
      rect, this, ID_DUMMY_EDIT))
      	return -1;
	m_wndEditCurFrame.SetFont (&m_font);
	
	// Spinner Buddy to Edit //
    index = 0;
    while(GetItemID(index)!=ID_DUMMY_EDIT) index++;

	SetButtonInfo (index, ID_DUMMY_SPIN, TBBS_SEPARATOR, cxChar * 3);
	GetItemRect (index, &rect);
    rect.bottom = rect.top + (cyChar + 6);
	
	if (!m_wndSpinCurFrame.Create(WS_CHILD | WS_VISIBLE | // dwStyle
						UDS_ALIGNRIGHT | UDS_SETBUDDYINT | UDS_ARROWKEYS,
						rect,					// rect
						this,		// CWnd* pParentWnd
						ID_DUMMY_SPIN))		// UINT  nID
    	return -1;
	
	m_wndSpinCurFrame.SetFont (&m_font);


    //-------------------------加入滑动条---------------------
    #define SNAP_WIDTH 350 //the width of the slider ctrl

    //set up the slider control as a snap mode select box
    //First get the index of the placeholder's position in the toolbar
    index = 0;
    while(GetItemID(index)!=IDP_PLACEHOLDER) index++;

    //next convert that button to a seperator and get its position
    SetButtonInfo(index, IDP_PLACEHOLDER, TBBS_SEPARATOR, SNAP_WIDTH);
    CRect rect1;
    GetItemRect(index, &rect1);

    //expand the rectangle to allow the slider room
    rect1.top++;
    rect1.bottom--;
    rect1.left += cxChar;

    // then Create the slider and show it
    if (!m_wndSlider.Create(WS_CHILD|WS_VISIBLE|TBS_NOTICKS|TBS_HORZ,
                                       rect1,this, IDP_PLACEHOLDER))
    {
       TRACE0("Failed to create slider\n");
       return FALSE;
    }

    // fill the slider box
    // m_wndSlider.SetRange(0,0);
    // -------------------------加入滑动条结束---------------------

    
    // bind the spinner to the Edit control
    m_wndSpinCurFrame.SetBuddy( &m_wndEditCurFrame );
	return 0;
}

void CMainToolBar::SetAllRange(long nRange)
{
	m_wndSlider.SetRange(0, nRange);
	m_wndSpinCurFrame.SetRange(0, nRange);
}

void CMainToolBar::SetPositions(long nCurPos)
{
	m_wndSlider.SetPos(nCurPos);
	m_wndSpinCurFrame.SetPos(nCurPos); //nCurPos = m_wndSlider.GetPos()
}

⌨️ 快捷键说明

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