📄 plugindialog.cpp
字号:
/****************************************************************************************/
/* PluginDialog.cpp */
/* */
/* Author: Tom Morris */
/* Description: Plugin Demonstration */
/* */
/* The contents of this file are subject to the Genesis3D Public License */
/* Version 1.01 (the "License"); you may not use this file except in */
/* compliance with the License. You may obtain a copy of the License at */
/* http://www.genesis3d.com */
/* */
/* Software distributed under the License is distributed on an "AS IS" */
/* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See */
/* the License for the specific language governing rights and limitations */
/* under the License. */
/* */
/* The Original Code is Genesis3D, released March 25, 1999. */
/* Genesis3D Version 1.1 released November 15, 1999 */
/* Copyright (C) 1999 WildTangent, Inc. All Rights Reserved */
/* */
/* Prepared for GenEdit-Classic ver. 0.5, Dec. 15, 2000 */
/****************************************************************************************/
#include "stdafx.h"
#include "genedit.h"
#include "PluginDialog.h"
#include "Ram.h"
#include "Globals.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPluginDialog dialog
CPluginDialog::CPluginDialog(CWnd* pParent /*=NULL*/)
: CDialog(CPluginDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(CPluginDialog)
m_pluginEditBox = _T("");
Initialized = false;
//}}AFX_DATA_INIT
}
void CPluginDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPluginDialog)
DDX_Control(pDX, IDC_PLUGIN_STOPBTN, m_plugin1StopBTN);
DDX_Control(pDX, IDC_PLUGIN1_WAV1, m_plugin1Wav1);
DDX_Control(pDX, IDC_PLUGIN1_PLAYBTN, m_plugin1PlayBTN1);
DDX_Control(pDX, IDC_PLUGIN1_BRSBTN, m_plugin1BrowseBTN);
DDX_Text(pDX, IDC_EDIT1, m_pluginEditBox);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPluginDialog, CDialog)
//{{AFX_MSG_MAP(CPluginDialog)
ON_BN_CLICKED(IDC_PLUGIN1_BRSBTN, OnPlugin1Brsbtn)
ON_BN_CLICKED(IDC_PLUGIN1_PLAYBTN, OnPlugin1Playbtn)
ON_BN_CLICKED(IDC_PLUGIN_STOPBTN, OnPluginStopbtn)
ON_WM_CTLCOLOR()
ON_WM_CLOSE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPluginDialog message handlers
BOOL CPluginDialog::OnInitDialog()
{
CDialog::OnInitDialog();
m_brush.CreateSolidBrush(BLACK);
char * PluginText;
PluginText = CGlobals::LoadText(IDR_PLUGINTEXT );
if( PluginText != NULL )
{
m_pluginEditBox = PluginText;
geRam_Free( PluginText );
UpdateData( false );
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
// although I use a class called mp3Mgr, it sets up a filter graph for almost
// any popular media file type., including wav, and avi files.
void CPluginDialog::OnPlugin1Brsbtn()
{
int nItem = 0;
int itemtext = 0;
LPCTSTR wav = NULL;
CFileDialog m_backgrndwavFile
(
TRUE,
wav,
NULL,
OFN_EXTENSIONDIFFERENT | OFN_FILEMUSTEXIST ,
_T("media files(*.avi; *.mp3; *.wav)|*.avi;*.mp3;*.wav||"));
// get the current dir
char currDir[MAX_PATH + 1];
DWORD dwcNameSize = MAX_PATH + 1;
GetCurrentDirectory(dwcNameSize, currDir);
// se current dir as default
m_backgrndwavFile.m_ofn.lpstrInitialDir = currDir;
// set the title for the fileOpen dialogbox
static char szTitle[] = _T("ProtoGame File Opener");
m_backgrndwavFile.m_ofn.lpstrTitle = szTitle;
// open the openFile dialog
if(IDOK !=m_backgrndwavFile.DoModal())
return;
m_plugin1Wav1.DeleteItem(nItem); // clear the list to make room for new entry
POSITION pos = m_backgrndwavFile.GetStartPosition();
while (pos)
m_plugin1Wav1.InsertItem(m_plugin1Wav1.GetItemCount(), m_backgrndwavFile.GetNextPathName(pos));
m_wavfilepath = m_plugin1Wav1.GetItemText( itemtext, NULL );
if ((m_wavfilepath.Find("avi") != -1) || (m_wavfilepath.Find("mp3") != -1) ||
(m_wavfilepath.Find("wav") != -1)
)
{
m_plugin1StopBTN.EnableWindow(TRUE);
m_plugin1PlayBTN1.EnableWindow(TRUE);
}
}
void CPluginDialog::OnPlugin1Playbtn()
{
/*const char**/ tempMp3file = (LPCTSTR)m_wavfilepath;
DoBackgrndMp3(this->m_hWnd, (char*)tempMp3file, 0);
}
void CPluginDialog::OnPluginStopbtn()
{
if (Initialized)
StopBackgrndMp3(this->m_hWnd);
}
// not called at the moment.
bool CPluginDialog::UpdatePlugin1Dialog()
{
if (Initialized)
{
if (tempMp3file != NULL)
PlayMp3(0);
}
return true;
}
void CPluginDialog::OnOK()
{
if (Initialized)
StopBackgrndMp3(this->m_hWnd); // TODO: Add extra validation here
if (m_brush.m_hObject != NULL)
m_brush.DeleteObject();
this->DestroyWindow();
// CDialog::OnOK();
}
HBRUSH CPluginDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
// HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
LOGBRUSH logbrush;
switch (nCtlColor)
{
case CTLCOLOR_EDIT:
case CTLCOLOR_STATIC:
case CTLCOLOR_LISTBOX:
case CTLCOLOR_SCROLLBAR:
case CTLCOLOR_BTN:
case CTLCOLOR_MSGBOX:
case CTLCOLOR_DLG:
{
m_brush.GetLogBrush(&logbrush);
pDC->SetTextColor(DKGRAY);
pDC->SetBkColor(logbrush.lbColor);
return m_brush;
}
default:
return m_brush;
}
// return hbr;
// return m_brush;
}
void CPluginDialog::OnClose()
{
OnOK();
CDialog::OnClose();
}
//////////////////////////////////////////////////////////////////////
// Initmp3Mgr
/* This function gets the Windows Media Player and makes its functionality
available for us. We will use mp3Mgr to access this tool. */
//////////////////////////////////////////////////////////////////////
BOOL CPluginDialog::Initmp3Mgr(HWND hWnd)
{
// Filter interface initialize?
if( SUCCEEDED( CoInitialize( NULL )))
return TRUE;
return FALSE;
}
//////////////////////////////////////////////////////////////////////
// UnInitmp3Mgr
// Unloads mp3Mgr
//////////////////////////////////////////////////////////////////////
void CPluginDialog::UnInitmp3Mgr(HWND hWnd)
{
CoUninitialize( );
}
//////////////////////////////////////////////////////////////////////
// mp3Mgr
//
/* This funcion initializez mp3Mgr and connects it to the main window.
This is necessary so that streaming audio calls will deliver audio
to the main game window. */
//////////////////////////////////////////////////////////////////////
void CPluginDialog::mp3Mgr_Create(HWND hWnd)
{
// Initialise COM and the application
Initmp3Mgr(hWnd);
InitMedia(hWnd);
Initialized = true;
} // mp3Mgr
//////////////////////////////////////////////////////////////////////
// CanPlay
//
// Return true if we can go to a playing state from our current state
//////////////////////////////////////////////////////////////////////
BOOL CPluginDialog::CanPlay()
{
return (state == Stopped || state == Paused);
}
//////////////////////////////////////////////////////////////////////
// CanStop
//
// Return true if we can go to a stopped state from our current state
//////////////////////////////////////////////////////////////////////
BOOL CPluginDialog::CanStop()
{
return (state == Playing || state == Paused);
}
//////////////////////////////////////////////////////////////////////
// IsInitialized
//
// Return true if we have loaded and initialized a multimedia file
//////////////////////////////////////////////////////////////////////
BOOL CPluginDialog::IsInitialized()
{
return (state != Uninitialized);
}
//////////////////////////////////////////////////////////////////////
// ChangeStateTo
//////////////////////////////////////////////////////////////////////
void CPluginDialog::ChangeStateTo( State newState )
{
state = newState;
}
//////////////////////////////////////////////////////////////////////
// InitMedia
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -