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

📄 mainfrm.cpp

📁 这是一个用VC++编写的FLSHPLAYER
💻 CPP
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//

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

#include "MainFrm.h"

#include "FlashPlayView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
	//{{AFX_MSG_MAP(CMainFrame)
	ON_WM_CREATE()
	ON_COMMAND(ID_VIEW_FULL_SCREEN, OnViewFullScreen)
	ON_UPDATE_COMMAND_UI(ID_VIEW_FULL_SCREEN, OnUpdateViewFullScreen)
	ON_WM_CLOSE()
	ON_WM_SYSCOMMAND()
	ON_WM_SHOWWINDOW()
	ON_COMMAND(ID_VIEW_COMPACT_MODE, OnViewCompactMode)
	ON_UPDATE_COMMAND_UI(ID_VIEW_COMPACT_MODE, OnUpdateViewCompactMode)
	ON_WM_NCLBUTTONDBLCLK()
	//}}AFX_MSG_MAP

    ON_UPDATE_COMMAND_UI(ID_INDICATOR_CURFRM,OnUpdateCurFrame)

    // LOGO SUPPORT
	ON_REGISTERED_MESSAGE(ON_LOGO_CLICK,OnLogoClick)
    // LOGO SUPPORT

END_MESSAGE_MAP()

static UINT indicators[] =
{
	ID_SEPARATOR,           // status line indicator
	ID_INDICATOR_CFSTR,
    ID_INDICATOR_CURFRM,
    ID_INDICATOR_SEPARATOR,
	ID_INDICATOR_TFSTR,
	ID_INDICATOR_TOTALFRM,
};

/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
{
	// TODO: add member initialization code here
	m_bFullScreenMode=false;
    m_bIsCompactMode = FALSE;
    m_bXPMenuStyle = TRUE;
}

CMainFrame::~CMainFrame()
{
}

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
	if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
		return -1;

    if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
		| CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) )
		//||!m_wndToolBar.LoadToolBar(IDR_MAINFRAME)
	{
		TRACE0("Failed to create toolbar\n");
		return -1;      // fail to create
	}

	if (!m_wndStatusBar.Create(this) ||
		!m_wndStatusBar.SetIndicators(indicators,
		  sizeof(indicators)/sizeof(UINT)))
	{
		TRACE0("Failed to create status bar\n");
		return -1;      // fail to create
	}
    m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_CURFRM),"");
    m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_TOTALFRM),"");


	// TODO: Delete these three lines if you don't want the toolbar to
	//  be dockable
	m_wndToolBar.EnableDocking(CBRS_ALIGN_TOP|CBRS_ALIGN_BOTTOM);
	EnableDocking(CBRS_ALIGN_ANY);
	DockControlBar(&m_wndToolBar);
    m_wndToolBar.SetWindowText("Main ToolBar");

	// LOGO SUPPORT
	CControlBar* pTopDockBar = GetControlBar(AFX_IDW_DOCKBAR_TOP);
	if(pTopDockBar && m_wndLogo.Create(NULL,
									   WS_CHILD |
										WS_VISIBLE |
											BS_OWNERDRAW,
									   CRect(0,0,0,0),
									   pTopDockBar,
									   IDC_LOGO_BUTTON))
	{	
		m_wndLogo.LoadBitmaps(IDB_LOGO_BITMAP,
							  IDB_LOGOSEL_BITMAP);
		m_wndLogo.SizeToContent();
	}
	// LOGO SUPPORT


	if(m_bXPMenuStyle)BCMenu::SetMenuDrawMode(BCMENU_DRAWMODE_XP);
	else BCMenu::SetMenuDrawMode(BCMENU_DRAWMODE_ORIGINAL);


	return 0;
}

BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
	if( !CFrameWnd::PreCreateWindow(cs) )
		return FALSE;
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

    //从注册表中读出主窗口的位置及大小的信息
    TCHAR * strSection = _T("Settings");      //主键
    TCHAR * strPosX    = _T("X Coordinate");  //以下四种键值
    TCHAR * strPosY    = _T("Y Coordinate");
    TCHAR * strCX    = _T("Window's Width");
    TCHAR * strCY    = _T("Window's Height");
    CWinApp* pApp = AfxGetApp();   //获得应用程序实体
    cs.x  = pApp->GetProfileInt(strSection, strPosX, 0);
    cs.y  = pApp->GetProfileInt(strSection, strPosY, 0);
    cs.cx = pApp->GetProfileInt(strSection, strCX, 750);
    cs.cy = pApp->GetProfileInt(strSection, strCY, 550);

	return TRUE;
}

/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics

#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
	CFrameWnd::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
	CFrameWnd::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers

// LOGO SUPPORT
LRESULT CMainFrame::OnLogoClick(WPARAM, LPARAM)
{
	CString URL(_T("mailto:2003@2003.com")); 

	HINSTANCE result = ::ShellExecute(NULL, _T("open"), URL, NULL,NULL, SW_SHOW);

	if ((UINT)result <= HINSTANCE_ERROR)
	{
		TCHAR key[MAX_PATH + MAX_PATH] = {_T('\0')};
		TCHAR ext[_MAX_EXT] = {_T('\0')};

		_splitpath(URL,NULL,NULL,NULL,ext);
			
		if (GetRegKey(HKEY_CLASSES_ROOT, ext, key) == ERROR_SUCCESS) 
		{
			lstrcat(key, _T("\\shell\\open\\command"));

			if (GetRegKey(HKEY_CLASSES_ROOT,key,key) == ERROR_SUCCESS) 
			{
				TCHAR *pos;
				pos = _tcsstr(key, _T("\"%1\""));
				if (pos == NULL) 
				{                       
					pos = strstr(key, _T("%1"));
					if (pos == NULL)            
						pos = key+lstrlen(key)-1;
					else
						*pos = '\0';            
				}
				else
					*pos = '\0';                

				lstrcat(pos, _T(" "));
				lstrcat(pos, URL);

				::WinExec(key,SW_SHOW);
			}
		}
	}

	return 0;
}
// LOGO SUPPORT

CMainToolBar * CMainFrame::GetToolBar1()
{
    return &m_wndToolBar;
}


void CMainFrame::OnUpdateCurFrame(CCmdUI *pCmdUI)
{
    // CString strCurPos;
    // int nLineNum, nColNum;
    // int nSelStart, nSelEnd;
    // you're going to have to get a pointer
    // to the edit control in the view
    // m_wndEditCtrl->GetSel(nSelStart, nSelEnd);  
    // nLineNum = m_wndEditCtrl->LineFromChar(nSelStart);
    // nColNum = nSelStart - m_wndEditCtrl->LineIndex(nLineNum);
    // strCurPos.Format(ID_INDICATOR_CURPOS, 
    //                  nLineNum+1, 
    //                nColNum+1);
 
    m_wndStatusBar.SetPaneText(
        m_wndStatusBar.CommandToIndex(ID_INDICATOR_CURFRM), 
        m_strCur);
}


CStatusBar * CMainFrame::GetStatusBar()
{
    return  &m_wndStatusBar;
}

HMENU TempHandleMenu;

void CMainFrame::FullScreenModeOn()
{
    //我操你 MFC 的姥姥,此处只能用菜单句柄
    TempHandleMenu = (this->GetMenu())->m_hMenu ;
    //ASSERT(pMainMenu==NULL);
    this->SetMenu(NULL);
 
    // available only if there is an active doc  
	CMainFrame* pChild=this;  //CMDIChildWnd* pChild=MDIGetActive()
	if(!pChild) return;
	m_bToolBarWasVisible=(m_wndToolBar.IsWindowVisible()!=0);
	m_wndToolBar.ShowWindow(SW_HIDE);
	m_bStatusBarWasVisible=(m_wndStatusBar.IsWindowVisible()!=0);
	m_wndStatusBar.ShowWindow(SW_HIDE);
	// first create the new toolbar
	// this will contain the full-screen off button
	m_pwndFullScreenBar=new CNoMenuToolBar;
	m_pwndFullScreenBar->Create(this);
	m_pwndFullScreenBar->LoadToolBar(IDR_FULLSCREEN);
    m_pwndFullScreenBar->SetWindowText("On/Off Full Screen"); 
	m_pwndFullScreenBar->SetBarStyle(m_pwndFullScreenBar->GetBarStyle() |
		CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
	// to look better:
	m_pwndFullScreenBar->ModifyStyle(0, TBSTYLE_FLAT);
    m_pwndFullScreenBar->EnableDocking(0);
	// place the full-screen off button somewhere:
	CPoint pt(100,50);
	FloatControlBar(m_pwndFullScreenBar,pt);

	// now save the old positions of the main and child windows
	GetWindowRect(&m_mainRect);
	// remove the caption of the mainWnd:
	LONG style=::GetWindowLong(m_hWnd,GWL_STYLE);
    m_nWndStyle = style;
	style&=~WS_CAPTION;
	::SetWindowLong(m_hWnd,GWL_STYLE,style);

	int screenx=GetSystemMetrics(SM_CXSCREEN);
	int screeny=GetSystemMetrics(SM_CYSCREEN);
	// resize:
	SetWindowPos(NULL,-4,-4,screenx+8,screeny+8,SWP_NOZORDER);
	style=::GetWindowLong(pChild->m_hWnd,GWL_STYLE);
	m_bChildMax=(style & WS_MAXIMIZE)?true:false;
	// note here: m_bMainMax is not needed since m_hWnd only
	// changed its caption...
    // and maximize the child window
	// it will remove its caption, too.
	pChild->ShowWindow(SW_SHOWMAXIMIZED);
	RecalcLayout();
	m_bFullScreenMode=true;
    ((CFlashPlayView *)GetActiveView())->m_flash.EnableFullScreenMode(TRUE);
}

void CMainFrame::FullScreenModeOff()
{
	// You can use SaveBarState() in OnClose(),
	// so remove the newly added toolbar entirely
	// in order SaveBarState() not
	// to save its state. That is why I used dynamic
	// allocation
	delete m_pwndFullScreenBar;
	LONG style=::GetWindowLong(m_hWnd,GWL_STYLE);
	style|=WS_CAPTION;
	::SetWindowLong(m_hWnd,GWL_STYLE,m_nWndStyle); //style
	if(m_bToolBarWasVisible)
		m_wndToolBar.ShowWindow(SW_SHOW);
	if(m_bStatusBarWasVisible)
		m_wndStatusBar.ShowWindow(SW_SHOW);
	MoveWindow(&m_mainRect);
	RecalcLayout();
	CMainFrame* pChild=this;  //CMDIChildWnd* pChild=MDIGetActive()
	// pchild can be NULL if the USER closed all the
	// childs during Full Screen Mode:
	//if(pChild){
	//	if(m_bChildMax)
	//		MDIMaximize(pChild);
	//	else MDIRestore(pChild);
	//}

    //我操你 MFC 的姥姥,此处只能用菜单句柄和 SDK + Win32 API
    ::SetMenu(this->GetSafeHwnd(),TempHandleMenu);

	pChild->ShowWindow(SW_RESTORE);
	m_bFullScreenMode=false;
    ((CFlashPlayView *)GetActiveView())->m_flash.EnableFullScreenMode(FALSE);
}

void CMainFrame::OnViewFullScreen() 
{
	// TODO: Add your command handler code here
    if(m_bIsCompactMode)
		CompactModeOff();

	if(m_bFullScreenMode)
		FullScreenModeOff();
	else FullScreenModeOn();
}

void CMainFrame::OnUpdateViewFullScreen(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_bFullScreenMode);		
}

void CMainFrame::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	if(m_bFullScreenMode)
		FullScreenModeOff();	

    //将窗口的位置及大小写入注册表
    TCHAR * strSection = _T("Settings");
    TCHAR * strPosX    = _T("X Coordinate");
    TCHAR * strPosY    = _T("Y Coordinate");
    TCHAR * strCX    = _T("Window's Width");
    TCHAR * strCY    = _T("Window's Height");
    CRect rect;
    ::GetWindowRect (this->GetSafeHwnd(), &rect) ;
    CWinApp* pApp = AfxGetApp();
    pApp->WriteProfileInt(strSection, strPosX, rect.left);
    pApp->WriteProfileInt(strSection, strPosY, rect.top);
    pApp->WriteProfileInt(strSection, strCX, rect.Width());
    pApp->WriteProfileInt(strSection, strCY, rect.Height());

	CFrameWnd::OnClose();
}

void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam) 
{
	// TODO: Add your message handler code here and/or call default

	if(nID==SC_MAXIMIZE)
    {
        if(m_bIsCompactMode)
		    CompactModeOff();
        FullScreenModeOn();
    }
    else
        CFrameWnd::OnSysCommand(nID, lParam);
}


void CMainFrame::OnShowWindow(BOOL bShow, UINT nStatus) 
{
	CFrameWnd::OnShowWindow(bShow, nStatus);
	
    /*
    CRect rect;
    ::GetWindowRect (this->GetSafeHwnd(), &rect) ;
    ::SetWindowPos (this->GetSafeHwnd(), NULL, 
               (GetSystemMetrics (SM_CXSCREEN) - rect.right + rect.left) / 2,
               (GetSystemMetrics (SM_CYSCREEN) - rect.bottom + rect.top) / 2,
               0, 0, SWP_NOZORDER | SWP_NOSIZE) ;
    //*/	
}

void CMainFrame::OnViewCompactMode() 
{
	// TODO: Add your command handler code here
	if(m_bFullScreenMode)
		FullScreenModeOff();

    if(m_bIsCompactMode)
		CompactModeOff();
	else CompactModeOn();
}

void CMainFrame::CompactModeOff()
{
	GetWindowRect(&m_mainRect);

	LONG style=::GetWindowLong(m_hWnd,GWL_STYLE);
	style|=WS_CAPTION;
	::SetWindowLong(m_hWnd,GWL_STYLE,m_nWndStyle); //style
	if(m_bToolBarWasVisible)
		m_wndToolBar.ShowWindow(SW_SHOW);
	if(m_bStatusBarWasVisible)
		m_wndStatusBar.ShowWindow(SW_SHOW);
	MoveWindow(&m_mainRect);
	RecalcLayout();
	CMainFrame* pChild=this;  

    //我操你 MFC 的姥姥,此处只能用菜单句柄和 SDK + Win32 API
    ::SetMenu(this->GetSafeHwnd(),TempHandleMenu);

	pChild->ShowWindow(SW_RESTORE);

	SetWindowPos(NULL,
        m_mainRect.left,m_mainRect.top,
        m_mainRect.Width(),m_mainRect.Height(),SWP_NOZORDER);
	style=::GetWindowLong(pChild->m_hWnd,GWL_STYLE);

    m_bIsCompactMode = FALSE;
    // 使得紧凑模式的设置  无效
    ((CFlashPlayView *)GetActiveView())->m_flash.EnableCompactMode(FALSE);
}

void CMainFrame::CompactModeOn()
{
    //我操你 MFC 的姥姥,此处只能用菜单句柄
    TempHandleMenu = (this->GetMenu())->m_hMenu ;
    this->SetMenu(NULL);
 
    // available only if there is an active doc  
	CMainFrame* pChild=this;  
	if(!pChild) return;
	m_bToolBarWasVisible=(m_wndToolBar.IsWindowVisible()!=0);
	m_wndToolBar.ShowWindow(SW_HIDE);
	m_bStatusBarWasVisible=(m_wndStatusBar.IsWindowVisible()!=0);
	m_wndStatusBar.ShowWindow(SW_HIDE);

	// now save the old positions of the main and child windows
	GetWindowRect(&m_mainRect);
	// remove the caption of the mainWnd:
	LONG style=::GetWindowLong(m_hWnd,GWL_STYLE);
    m_nWndStyle = style;
	style&=~WS_CAPTION;
	::SetWindowLong(m_hWnd,GWL_STYLE,style);

	// resize:
	SetWindowPos(NULL,
        m_mainRect.left,m_mainRect.top,
        m_mainRect.Width(),m_mainRect.Height()-1,SWP_NOZORDER);
	style=::GetWindowLong(pChild->m_hWnd,GWL_STYLE);

	pChild->ShowWindow(SW_SHOW);
	RecalcLayout();

    m_bIsCompactMode = TRUE;
    ((CFlashPlayView *)GetActiveView())->m_flash.EnableCompactMode(TRUE);
}

void CMainFrame::OnUpdateViewCompactMode(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_bIsCompactMode);
}


HMENU CMainFrame::NewMenu()
{
    // Load the menu from the resources
    // ****replace IDR_MAINFRAME with your menu ID****
    m_menu.LoadMenu(IDR_MAINFRAME);  
    // One method for adding bitmaps to menu options is 
    // through the LoadToolbar member function.This method 
    // allows you to add all the bitmaps in a toolbar object 
    // to menu options (if they exist). The function parameter 
    // is an the toolbar id. There is also a function called 
    // LoadToolbars that takes an array of id's.
    m_menu.LoadToolbar(IDR_MAINFRAME);

    return(m_menu.Detach());
}

void CMainFrame::OnNcLButtonDblClk(UINT nHitTest, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
    if(m_bIsCompactMode)
        CompactModeOff();
    FullScreenModeOn();

	CFrameWnd::OnNcLButtonDblClk(nHitTest, point);
}

⌨️ 快捷键说明

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