Files
2026-06-13 00:10:11 +08:00

3081 lines
83 KiB
C++

// ---------------------------------------------------------------------------
#include <vcl.h>
#include <System.IOUtils.hpp>
#pragma hdrstop
#include "GlobalUnit.h"
#include "UploadFormUnit.h"
#include "MainFormUnit.h"
#include "AudioEffectFormUnit.h"
#include "SetupFormUnit.h"
#include "RecordFormUnit.h"
#include "LoginFormUnit.h"
#include "BaseFormUnit.h"
#include "ComposeFormUnit.h"
#include "CompleteFormUnit.h"
#include "SkinHintWindow.h"
#include "MessageFormUnit.h"
#include "MicSetFormUnit.h"
#include "AboutFormUnit.h"
#include "ProgressFormUnit.h"
#include "UpdateFormUnit.h"
#include "HelpFormUnit.h"
#include "SaveFormUnit.h"
#include "ManageSongFormUnit.h"
#include "SoftwaresFormUnit.h"
#include "PayMentFormUnit.h"
#include "PredefineProjectFormUnit.h"
#include "CustomerSettingFormUnit.h"
#include "ImgCopperFormUnit.h"
#include "SplashFormUnit.h"
#define USER_TIME_HINT 30
// ---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma link "PNGButton"
#pragma resource "*.dfm"
USEFORM("SetupFormUnit.cpp", SetupForm);
USEFORM("RecordFormUnit.cpp", RecordForm);
USEFORM("BaseFormUnit.cpp", BaseForm);
USEFORM("ComposeFormUnit.cpp", ComposeForm);
USEFORM("CompleteFormUnit.cpp", CompleteForm);
USEFORM("HelpFormUnit.cpp", HelpForm);
USEFORM("MessageFormUnit.cpp", MessageForm);
TMainForm *MainForm;
#define AUTOSAVE_TIMER_UNABLE 0 //add by tj 2014/3/5
#define AUTOSAVE_FILE_SAVE 1
#define AUTOSAVE_FILE_CLEAR 2
TPNGButton *g_btnFontChange;
Vcl::Extctrls::TPanel *g_panelFontName;
CommonListBoxUnit::TListBox *g_lbFontSelect;
// ---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner) : TForm(Owner)
{
HintWindowClass = __classid(TSkinHintWindow);
//背景图
m_pImgTopLeft = new TPngImage();
m_pImgTopLeft->LoadFromResourceName(int(HInstance), L"PngTopLeft");
m_pImgTopRight = new TPngImage();
m_pImgTopRight->LoadFromResourceName(int(HInstance), L"PngTopRight");
m_pImgTopTile = new TPngImage();
m_pImgTopTile->LoadFromResourceName(int(HInstance), L"PngTopTile");
m_pImgVerTile = new TPngImage();
m_pImgVerTile->LoadFromResourceName(int(HInstance), L"PngVerticalTile");
m_pImgHorTile = new TPngImage();
m_pImgHorTile->LoadFromResourceName(int(HInstance), L"PngHorizonTile");
m_pImgBottomLeft = new TPngImage();
m_pImgBottomLeft->LoadFromResourceName(int(HInstance), L"PngBottomLeft");
m_pImgBottomRight = new TPngImage();
m_pImgBottomRight->LoadFromResourceName(int(HInstance), L"PngBottomRight");
//通知图片
m_pImgNoticeNum = new TPngImage();
m_pImgNoticeNum->LoadFromResourceName(int(HInstance), "ImgNoticeNum");
g_aAudioEffectTypes[0] = FX_ECHO;
g_aAudioEffectTypes[1] = FX_DISTORTION;
g_aAudioEffectTypes[2] = FX_ROTATE;
g_aAudioEffectTypes[3] = FX_REVERB;
g_aAudioEffectTypes[4] = FX_COMPRESSOR;
g_aAudioEffectTypes[5] = FX_WAH;
g_aAudioEffectTypes[6] = FX_CHORUS;
g_aAudioEffectTypes[7] = FX_PARAMEQ;
g_aAudioEffectTypes[8] = FX_PHASER;
g_aAudioEffectTypes[9] = FX_PITCH;
g_aAudioEffectTypes[10] = FX_APR;
m_pNotificationGetTimer = NULL;
m_pNotificationForm = NULL;
m_pCDTimer = NULL;
}
// ---------------------------------------------------------------------------
__fastcall TMainForm::~TMainForm()
{
if (m_pImgTopLeft) delete m_pImgTopLeft;
if (m_pImgTopRight) delete m_pImgTopRight;
if (m_pImgTopTile) delete m_pImgTopTile;
if (m_pImgNoticeNum) delete m_pImgNoticeNum;
if( m_pImgVerTile ) delete m_pImgVerTile;
if( m_pImgHorTile ) delete m_pImgHorTile;
if( m_pImgBottomLeft ) delete m_pImgBottomLeft;
if( m_pImgBottomRight ) delete m_pImgBottomRight;
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::CreateParams(TCreateParams &Params)
{
TForm::CreateParams(Params);
wcscpy(Params.WinClassName, (LPCTSTR)APPNAME);
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::FormCreate(TObject *Sender)
{
// 获取DPI
HDC hdc = GetDC(NULL);
if (hdc != NULL) {
g_xDpi = GetDeviceCaps(hdc, LOGPIXELSX);
g_yDpi = GetDeviceCaps(hdc, LOGPIXELSY);
ReleaseDC(NULL, hdc);
}
g_szFont8 = int(8 * 96.0 / g_yDpi + 0.5);//m_lblFont8->Font->Size; //
g_szFont9 = int(9 * 96.0 / g_yDpi + 0.5);//m_lblFont9->Font->Size; //
g_szFont16 = int(16 * 96.0 / g_yDpi + 0.5);//m_lblFont16->Font->Size; //
// ShowMessage("Font8:"+IntToStr(g_szFont8)+",Font9:"+IntToStr(g_szFont9)+",Font16:"+IntToStr(g_szFont16));
Randomize();
DragAcceptFiles(Handle, true);
g_hProjectEvent = CreateEvent(NULL, FALSE, TRUE, NULL);
SetTransparent( this );
string strRoot = ((AnsiString)g_strUserPath.c_str()).c_str();
HRESULT hResult = f_CS_GetVersion();
if( hResult!=CS_VERSION ){
MessageForm->ShowMessage("初始化网络服务组件失败!", MB_ICONERROR | MB_OK);
PostMessage(Handle, WM_CLOSE, 0, 0);
return;
}
SplashForm->ShowProgress( "初始化媒体控制组件......" );
hResult = f_MM_GetVersion();
if( hResult!=MM_VERSION || f_MM_InitialObjects(Handle, (char*)strRoot.c_str())!=S_OK ){
MessageForm->ShowMessage("初始化媒体控制组件失败!", MB_ICONERROR | MB_OK);
PostMessage(Handle, WM_CLOSE, 0, 0);
return;
}
GetInitVar();
if( g_fSpeakerVolume<0 )
g_fSpeakerVolume = f_MM_GetStreamVolume( 0 ) / 100.0;
else
f_MM_SetStreamVolume(0, g_fSpeakerVolume);
if( g_fRecordVolume<0 )
g_fRecordVolume = f_MM_GetStreamVolume( 1 ) / 100.0;
else
f_MM_SetStreamVolume( 1, g_fRecordVolume );
g_fSpeakerVolume_SVD = g_fSpeakerVolume;
g_fRecordVolume_SVD = g_fRecordVolume;
SetMelodyTempo(g_nMelodyTempo, true);
SetMelodyTS(g_iMelodyTimeSignature, true);
SplashForm->ShowProgress( "初始化输入输出设备......" );
HRESULT res = f_MM_CheckIODevice( g_iPlaybackDevice, g_strPlaybackDevice,
g_iRecordDevice, g_strRecordDevice );
if( !(res&0xFF) )
g_iPlaybackOutput = -1;
if( !(res&0xFF00) )
g_iRecordInput = -1;
res = f_MM_SetIODevice( g_iPlaybackDevice, g_iPlaybackOutput, g_iRecordDevice, g_iRecordInput );
if( res!=S_OK ){
g_iPlaybackDevice = -1;
g_iPlaybackOutput = -1;
g_iRecordDevice = -1;
g_iRecordInput = -1;
g_strPlaybackDevice[0] = 0;
g_strRecordDevice[0] = 0;
f_MM_SetIODevice( g_iPlaybackDevice, g_iPlaybackOutput, g_iRecordDevice, g_iRecordInput );
f_MM_CheckIODevice( g_iPlaybackDevice, g_strPlaybackDevice, g_iRecordDevice, g_strRecordDevice );
}
f_MM_SetRecordAutoAdjust( g_bRecordAutoAdjust );
ResetAudioEffects();
SplashForm->ShowProgress( "扫描SF音色库......" );
InitFontList();
if (g_lstFonts.size() == 0) {
MessageForm->ShowMessage("初始化音色库失败!", MB_ICONERROR | MB_OK);
PostMessage(Handle, WM_CLOSE, 0, 0);
return;
}
SetSelectFont();
g_strFontFile_SVD = g_strFontFile;
m_lblFontName->Font->Color = RGB(60,43,23);
m_lblFontName->Caption = g_lstFonts[g_idFont]->strFontName;
m_btnFontChange->Enabled = g_lstFonts.size()>1;
m_lbFontSelect->ItemIndex = g_idFont;
if( m_lbFontSelect->Count < g_lstFonts.size() ){
for( int i=0; i<g_lstFonts.size(); i++ ){
m_lbFontSelect->AddItem( g_lstFonts[i]->strFontName, NULL );
}
int nShowRow = m_lbFontSelect->Count<8 ? m_lbFontSelect->Count : 8;
m_lbFontSelect->Height = nShowRow * m_lbFontSelect->ItemHeight;
//m_lbFontSelect->Top = m_panelFontName->Top - m_lbFontSelect->Height;
}
g_btnFontChange = m_btnFontChange;
g_panelFontName = m_panelFontName;
g_lbFontSelect = m_lbFontSelect;
// g_iWindowState = wsMaximized;
SplashForm->ShowProgress( "初始化窗体组件......" );
// 绘制圆角窗体
HRGN hRgn = CreateRoundRectRgn(0, 0, Width + 1, Height + 1, 6, 6);
SetWindowRgn(Handle, hRgn, TRUE);
DeleteObject(hRgn);
// 设置全局提示框属性
Application->HintHidePause = 10000; // 延长停留时间为10秒
// Screen->HintFont->Color = RGB(60,43,23);
Screen->HintFont->Size = 10; //int(10 * 96.0 / g_yDpi + 0.5); //
// 创建Tab页
for (int i = 0; i < TABSHEET_NUM; i++) {
m_paTabSheets[i] = new TTabSheet(this); //TBackgroundTabSheet(this, i );//
m_paTabSheets[i]->PageControl = m_pPgCtrl_Work;
m_paTabSheets[i]->TabVisible = false;
m_paTabSheets[i]->Align = alCustom;
m_paTabSheets[i]->SetBounds(0, 0, m_pPgCtrl_Work->Width, m_pPgCtrl_Work->Height);
}
m_pPgCtrl_Work->ActivePageIndex = 0;
// 创建5个子窗口,放于PageControl上作为Tab页
SetupForm = new TSetupForm(this);
SetupForm->Parent = m_paTabSheets[0];
SetupForm->Align = alClient;
SetupForm->Visible = true;
RecordForm = new TRecordForm(this);
RecordForm->Parent = m_paTabSheets[1];
RecordForm->Align = alClient;
RecordForm->Visible = true;
BaseForm = new TBaseForm(this);
BaseForm->Parent = m_paTabSheets[2];
BaseForm->Align = alClient;
BaseForm->Visible = true;
ComposeForm = new TComposeForm(this);
ComposeForm->Parent = m_paTabSheets[3];
ComposeForm->Align = alClient;
ComposeForm->Visible = true;
CompleteForm = new TCompleteForm(this);
CompleteForm->Parent = m_paTabSheets[4];
CompleteForm->Align = alClient;
CompleteForm->Visible = true;
HelpForm = new THelpForm(this);
HelpForm->Parent = m_paTabSheets[5];
HelpForm->Align = alClient;
HelpForm->Visible = true;
// 提示
m_pStyleInfoWnd = new TSkinHintWindow(this);
m_pTimerHint = new TTimer(this);
m_pTimerHint->Enabled = false;
m_pTimerHint->Interval = USER_TIME_HINT;
m_pTimerHint->OnTimer = HintTimerProc;
m_bShowHint = false;
m_btnStep[0] = m_btnFirstStep;
m_btnStep[1] = m_btnSecStep;
m_btnStep[2] = m_btnThrdStep;
m_btnStep[3] = m_btnFrthStep;
m_btnStep[4] = m_btnFifthStep;
// 创建系统菜单
m_pSysMenu = new TSystemMenu(this);
// m_pSysMenu->CreateCustomMenuItem("新建工程(F6)...", OnCreateNewProject);
m_pSysMenu->CreateCustomMenuItem("新建工程");
m_pSysMenu->CreateCustomMenuItem("空白工程(F6)", OnCreateNewProject, 0);
m_pSysMenu->CreateCustomMenuItem("预设工程...", OnPredefineProject, 0);
m_pSysMenu->CreateCustomMenuItem("打开工程(F2)...", OnLoadProject);
m_pSysMenu->CreateCustomMenuItem("打开最近工程");
m_pSysMenu->CreateCustomMenuItem("保存工程(F3)", OnSaveProject);
m_pSysMenu->CreateCustomMenuItem("工程另存为(F4)...", OnSaveProject);
m_pSysMenu->CreateCustomMenuItem("-");
m_pSysMenu->CreateCustomMenuItem("输入输出设备...", OnIOSetting);
m_pSysMenu->CreateCustomMenuItem("偏好设置...", OnCustomerSetting);
m_pSysMenu->CreateCustomMenuItem("-");
m_pSysMenu->CreateCustomMenuItem("帮助与反馈(F1)", OnUserHelp);
m_pSysMenu->CreateCustomMenuItem("用户手册", OnUserManual);
// m_pSysMenu->CreateCustomMenuItem("唱作网动态", OnNotification);
m_pSysMenu->CreateCustomMenuItem("更多软件...", OnSoftwares);
m_pSysMenu->CreateCustomMenuItem("关于...", OnAbout);
m_pSysMenu->CreateCustomMenuItem("-");
m_pSysMenu->CreateCustomMenuItem("退出", CloseBoxClick);
m_pSysMenu->EnabledMenuItem(MENU_SAVE, false);
m_pSysMenu->EnabledMenuItem(MENU_SAVEAS, false);
UpdateProjectMenuItems();
m_lblUsername->Font->Color = RGB(60, 43, 23);
m_lblLoging->Font->Color = RGB(230, 204, 180);
m_labCaption->Font->Color = RGB(60, 43, 23);
// 执行文件版本信息
DWORD dwHandle;
DWORD dwVerLen = GetFileVersionInfoSize(Application->ExeName.c_str(),
&dwHandle);
if (dwVerLen) {
TCHAR *lpData = new TCHAR[dwVerLen];
if (GetFileVersionInfo(Application->ExeName.c_str(), 0, dwVerLen,
lpData)) {
PVSFixedFileInfo lpffi;
UINT uLen;
if (VerQueryValue(lpData, TEXT("\\"), (void **)&lpffi, &uLen)) {
g_infoSoftwareUpdate.version.majorVersion =
HIWORD(lpffi->dwFileVersionMS);
g_infoSoftwareUpdate.version.minorVersion =
LOWORD(lpffi->dwFileVersionMS);
g_infoSoftwareUpdate.version.modifyVersion =
HIWORD(lpffi->dwFileVersionLS);
g_infoSoftwareUpdate.version.buildVersion =
LOWORD(lpffi->dwFileVersionLS);
}
}
delete[]lpData;
}
sprintf(g_strCurrentVersion, "%d.%d.%d.%d",
g_infoSoftwareUpdate.version.majorVersion, g_infoSoftwareUpdate.version.minorVersion,
g_infoSoftwareUpdate.version.modifyVersion, g_infoSoftwareUpdate.version.buildVersion);
DebugPrint("软件版本:%d.%d.%d.%d \n",
g_infoSoftwareUpdate.version.majorVersion, g_infoSoftwareUpdate.version.minorVersion,
g_infoSoftwareUpdate.version.modifyVersion, g_infoSoftwareUpdate.version.buildVersion);
SplashForm->ShowProgress( "初始化网络服务组件......" );
//初始化网络服务
// strcpy( g_strServerURL, "new.ichangzuo.com" );
// strcpy( g_strServerURL, "www.ichangzuo.com" );
// strcpy( g_strServerURL, "LocalHost" );
// strcpy( g_strServerURL, "47.98.232.209" );
// strcpy( g_strServerURL, "192.168.5.80" );
char* idDevice = GetMacAdress();
DebugPrint("MAC: %02X-%02X-%02X-%02X-%02X-%02X", (UCHAR)idDevice[0],(UCHAR)idDevice[1],(UCHAR)idDevice[2]
,(UCHAR)idDevice[3],(UCHAR)idDevice[4],(UCHAR)idDevice[5] );
if (f_CS_InitialService(Handle, SOFTWARE_ID, &g_infoSoftwareUpdate,
g_strServerURL, (char*)strRoot.c_str(), idDevice ) == S_OK) {
g_bAutoLogin = GetAutoLogin(g_infoUser.strUserName,
g_infoUser.strPassword);
if (g_bAutoLogin) {
f_CS_Login(&g_infoUser, false);
m_btnLogin->Visible = false;
m_lblLoging->Visible = true;
m_btnCancelLog->Visible = true;
m_panelNoticeNum->Left = 138;
}
f_CS_AutoDownloadStyle( g_bAutoDownloadStyle );
}
else {
MessageForm->ShowMessage("网络服务启动失败!\n(将无法进行网络相关操作)",
MB_ICONERROR | MB_OK);
m_btnLogin->Visible = false;
CompleteForm->EnableNextStep(false);
}
if (strlen(g_strServerURL) == 0) {
m_pSysMenu->EnabledMenuItem(MENU_FORUM, false);
}
// m_pNotificationGetTimer = new TTimer(this); //add by tj 2014/04/17
// m_pNotificationGetTimer->Enabled = true;
// m_pNotificationGetTimer->Interval = NOTIFICATION_GETNOTI_PERIOD;
// m_pNotificationGetTimer->OnTimer = NotificationTimerProc;
g_strAutoProjName = g_strUserPath;
g_strAutoProjName += _T(AUTOSAVE_FILENAME);
UnicodeString strParam = ParamStr(1);
if (!strParam.IsEmpty()) {
m_strLoadProjectName = strParam.c_str();
PostMessage(Handle, UM_LOADPROJECT, 0, 0);
return;
}
else {
PostMessage(Handle, UM_NEWPROJECT, 0, 0);
}
if(g_bAutoSave) { //add by tj 2013/3/6
PostMessage(Handle, UM_OPENAUTOPROJ, 0, 0);
}else if( g_bAutoOpenProject && g_bAutoOpenProjectEnable ){ //add by tj 2014/05/15
String fileName = g_lstRecentProject.begin()->c_str();
if( FileExists(fileName) ){
m_strLoadProjectName = fileName;
PostMessage(Handle, UM_LOADPROJECT, 0, 0);
}
}
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::FormClose(TObject *Sender, TCloseAction &Action)
{
ClearCDTimer();
if( g_bLogon ){
f_CS_Logoff();
}
if( m_pNotificationGetTimer ){
delete m_pNotificationGetTimer;
m_pNotificationGetTimer = NULL;
}
if( m_pNotificationForm ) {
delete m_pNotificationForm;
m_pNotificationForm = NULL;
}
ClearAutoProj();
ClearGlobalVars();
ClearFontList();
SetInitVar(true);
HRESULT hr;
// SAFE_DELETE(HelpForm)
if( m_pPgCtrl_Work->ActivePageIndex>=0 ){
TForm * pForm = (TForm*)m_paTabSheets[m_pPgCtrl_Work->ActivePageIndex]->Controls[0];
pForm->OnDeactivate( NULL );
}
for (int i = 0; i < TABSHEET_NUM-1; i++) {
if (m_paTabSheets[i]) {
TForm * pForm = (TForm*)m_paTabSheets[i]->Controls[0];
if (pForm){
delete pForm;
}
delete m_paTabSheets[i];
}
}
if (f_CS_DestroyService) {
if (FAILED(hr = f_CS_DestroyService())) {
DebugPrint("Destroy client service failed! code=%x\n", hr);
}
}
if (f_MM_DestroyObjects) {
if (FAILED(hr = f_MM_DestroyObjects())) {
DebugPrint("Destroy media objects Failed! code=%x\n", hr);
}
}
if (f_SM_Release) {
if (FAILED(hr = f_SM_Release())) {
DebugPrint("Relase midi handle failed! code=%x\n", hr);
}
}
if (m_pSysMenu)
delete m_pSysMenu;
if (m_pTimerHint)
delete m_pTimerHint;
if (m_pStyleInfoWnd)
delete m_pStyleInfoWnd;
CloseHandle(g_hProjectEvent);
for(int i=0; i<g_lstMacAddress.size(); i++) {
SAFE_DELETE(g_lstMacAddress[i])
}
g_lstMacAddress.clear();
// for(int i=0; i<g_lstMacAddressNew.size(); i++) {
// SAFE_DELETE(g_lstMacAddressNew[i])
// }
// g_lstMacAddressNew.clear();
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::FormCloseQuery(TObject *Sender, bool &CanClose)
{
if( HasProjectModified() ){// || g_lstOpusStages.size()>0
// && g_strProjectName.length()==0 ) {
int mrRet = MessageForm->ShowMessage("是否保存当前工程?",
MB_ICONQUESTION | MB_YESNOCANCEL);
if (mrRet == mrYes) {
DebugPrint("确认保存");
OnSaveProject(NULL);
}
else if (mrRet == mrCancel) {
CanClose = false;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::WMEraseBkgnd(Winapi::Messages::TWMEraseBkgnd &Message)
{
if( m_pImgTopTile ){
TCanvas* tempCanvas = new TCanvas;
tempCanvas->Handle = Message.DC;
//绘制上半部
tempCanvas->Draw( 0, 0, m_pImgTopLeft ); //左框
int wConner = m_pImgBottomLeft->Width,
hConner = m_pImgBottomLeft->Width,
wTopTile = m_pImgTopTile->Width,
hTopTile = m_pImgTopTile->Height,
wHorTile = m_pImgHorTile->Width,
hVerTile = m_pImgVerTile->Height,
rArea = ClientWidth - wConner, //区域右端
bArea = ClientHeight - hConner; //区域底端
//底图
for (int x=wConner; x<rArea; x+=wTopTile){
tempCanvas->Draw(x, 0, m_pImgTopTile );
}
tempCanvas->Draw( rArea, 0, m_pImgTopRight ); //右框
//绘制下半部边框
for (int y=hTopTile; y<bArea; y+=hVerTile){
tempCanvas->Draw( 0, y, m_pImgVerTile ); //左边框
tempCanvas->Draw( rArea, y, m_pImgVerTile ); //右边框
}
//绘制底边框
tempCanvas->Draw( 0, bArea, m_pImgBottomLeft ); //左下角
for (int w=wConner; w<rArea; w+=wHorTile){
tempCanvas->Draw( w, bArea, m_pImgHorTile ); //中间部分
}
tempCanvas->Draw( rArea, bArea, m_pImgBottomRight ); //右下角
delete tempCanvas;
Message.Result = true;
}
else{
DefaultHandler( &Message );
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::WMDpiChanged(TMessage &Message)
{
int dx = Message.WParamLo,
dy = Message.WParamHi;
}
//---------------------------------------------------------------------------
void TMainForm::UpdateProjectMenuItems()
{
int index = m_pSysMenu->GetMenuItemIndex("打开最近工程");
if (index >= 0) {
m_pSysMenu->DeleteSubMenu(index);
if (g_lstRecentProject.size() == 0) {
m_pSysMenu->EnabledMenuItem(index, false);
}
else {
m_pSysMenu->EnabledMenuItem(index, true);
for (int i = 0; i < g_lstRecentProject.size(); i++) {
String strText = g_lstRecentProject[i].c_str();
m_pSysMenu->CreateCustomMenuItem(strText, OnLoadProject, index);
}
}
}
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::OnSaveProject(TObject *Sender)
{
TMenuItem* pItem = (TMenuItem*)Sender;
wstring strProjectName;
if( !pItem || pItem->MenuIndex == MENU_SAVEAS || g_strProjectName.length() == 0) {
// 指定工程文件名
TSaveDialog * pDlg = new TSaveDialog(NULL);
pDlg->Title = "保存工程";
pDlg->Options << ofCreatePrompt << ofOverwritePrompt;
pDlg->Filter = "编曲工程文件 (*.cpj)|*.cpj";
pDlg->DefaultExt = "cpj";
pDlg->FileName = ExtractFileName(g_strProjectName.c_str());
pDlg->InitialDir = ExtractFilePath(g_strProjectName.c_str());
if (pDlg->FileName.Length() == 0) {
String strTemp = L"Untitle-";
strTemp += g_strTSName[g_iMelodyTimeSignature];
strTemp += L"-";
strTemp += IntToStr(g_nMelodyTempo);
pDlg->FileName = strTemp;
}
if (pDlg->Execute(Handle)) {
strProjectName = pDlg->FileName.c_str();
}
delete pDlg;
}
else {
strProjectName = g_strProjectName;
}
if (strProjectName.length() > 0) {
// Perform(UM_HANDLEAUTOPROJ, AUTOSAVE_FILE_CLEAR, 0);//add by tj 2014/3/5
g_iCurrentPage = m_pPgCtrl_Work->ActivePageIndex;
if( g_iCurrentPage==5 ){
g_iCurrentPage = HelpForm->m_iPrevPageIndex;
}
//先编曲
ReloadBaseCompose();
ReloadCompose();
TProgressForm *frmProgress = new TProgressForm(NULL);
int ret = frmProgress->Project_Save(strProjectName.c_str());
int eExtra = frmProgress->GetOpertaionResult();
delete frmProgress;
if (ret==mrOk && eExtra==0 ) {
MessageForm->ShowMessage("工程文件保存成功。", MB_OK | MB_ICONINFORMATION);
m_labCaption->Caption =
String(APPNAME) + L" - " + TPath::GetFileNameWithoutExtension
(strProjectName.c_str());
g_bAutoOpenProjectEnable = true; //add by tj 2014/05/15
SetInitVar();
m_pSysMenu->EnabledMenuItem(MENU_SAVE, true);
m_pSysMenu->EnabledMenuItem(MENU_SAVEAS, true);
UpdateProjectMenuItems();
//add upload by tj 2004/03/26
if( g_strProjectName.length()!=0 ) {
String strName = g_strProjectName.c_str();
AnsiString strTitle = TPath::GetFileNameWithoutExtension( strName );
strcpy( g_infoSong.strSongName, strTitle.c_str() );
}
}
// m_tAutoSaveTimer->Enabled = true; //add by tj 2014/3/5
}
Update();
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::OnCreateNewProject(TObject *Sender)
{
if (g_lstMelodyBars.size() > 0 && (g_strProjectName.length() == 0 ||
HasProjectModified())) {
int mrRet = MessageForm->ShowMessage("是否保存当前工程?",
MB_ICONQUESTION | MB_YESNOCANCEL);
if (mrRet == mrYes) {
DebugPrint("确认保存");
OnSaveProject(NULL);
}
else if (mrRet == mrCancel) {
return;
}
}
TForm * pForm = (TForm*)m_paTabSheets[m_pPgCtrl_Work->ActivePageIndex]->Controls[0];
pForm->OnDeactivate(NULL);
NewProject();
SetInitVar(true);
// SetActivePage(1);
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::OnPredefineProject(TObject * Sender)
{
OnCreateNewProject( NULL );
//显示预定义工程窗口
TPredefineProjectForm *ppf = new TPredefineProjectForm(NULL);
if( ppf->ShowModal()==mrOk ){
//设置节拍速度
if( g_iMelodyTimeSignature!=ppf->m_Ts ){
SetupForm->SetDefaultStyle( ppf->m_Ts );
SetMelodyTS( ppf->m_Ts );
}
if( g_nMelodyTempo!=ppf->m_Tempo ){
SetMelodyTempo( ppf->m_Tempo );
}
f_SM_InputWavNotes(NULL, NULL, 0, 192, ppf->m_Ts, ppf->m_Tempo, NULL);
int iTonal = ppf->m_KeyType;
int nMSNum = ppf->m_RavStage;
int aPreset[3] = { 7, 5, 0 };
memcpy(aPreset, ppf->m_Preset, 3 * sizeof(int));
//预定义RawBars
g_iMelodyKey = ppf->m_Key;
int var = 0;
int nBarCount = 0;
for( int i=0; i<nMSNum; i++ ){
int ind = i;
if( nMSNum>2 ){
if( i==1 ){
ind = 2;
var--;
}
else if( i==2 )
ind = 1;
}
int nRepeat = (ind==2) ? 1 : 2;
for( int r=0; r<nRepeat; r++ ){
for( int j=0; j<8; j++ ){
MELODYBAR * pBar = new MELODYBAR;
pBar->iChords[0] = u_arrPredefChords[ind][iTonal][aPreset[i]][j];
if( j==7 ) pBar->iFill = r;
g_lstMelodyBars.push_back( pBar );
}
MELODYSTAGE * pMStage = new MELODYSTAGE;
pMStage->iFirstBar = nBarCount;
pMStage->iLastBar = nBarCount + 7;
pMStage->iVar = var++;
g_lstMelodyStages.push_back( pMStage );
nBarCount += 8;
}
}
ResetAudioEffects();
g_bPredefine = true;
g_iComposeKey = -1;
PostMessage(Handle, UM_REFRESH_PAGE_STATE, PAGE_ALL, 0);
PostMessage(Handle, UM_JUMP_PAGE, WPARAM(4),LPARAM(0));
}
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::OnLoadProject(TObject *Sender)
{
TMenuItem* pItem = (TMenuItem*)Sender;
wstring strProjectName;
if( pItem==NULL) {
strProjectName = m_strLoadProjectName.c_str();
}
else if (pItem->Tag >= 0) {
strProjectName = g_lstRecentProject[pItem->MenuIndex];
}
if (g_lstMelodyBars.size() > 0 && (g_strProjectName.length() == 0 ||
HasProjectModified())) {
int mrRet = MessageForm->ShowMessage("是否保存当前工程?",
MB_ICONQUESTION | MB_YESNOCANCEL);
if (mrRet == mrYes) {
DebugPrint("确认保存");
OnSaveProject(NULL);
}
else if (mrRet == mrCancel) {
return;
}
}
TForm * pForm = (TForm*)m_paTabSheets[m_pPgCtrl_Work->ActivePageIndex]->Controls[0];
pForm->OnDeactivate(NULL);
SetInitVar(true);
if( strProjectName.empty() ){
// 指定工程文件名
TOpenDialog * pDlg = new TOpenDialog(NULL);
pDlg->Title = "打开工程";
pDlg->Options << ofFileMustExist;
pDlg->FileName = ExtractFileName(g_strProjectName.c_str());
pDlg->InitialDir = ExtractFilePath(g_strProjectName.c_str());
pDlg->Filter = "编曲工程文件 (*.cpj)|*.cpj";
pDlg->DefaultExt = "cpj";
if (pDlg->Execute(Handle)) {
strProjectName = pDlg->FileName.c_str();
}
delete pDlg;
}
if( !strProjectName.empty() ){
LoadProject(strProjectName.c_str());
}
Update();
}
// ---------------------------------------------------------------------------
void TMainForm::LoadProject(LPCTSTR strName)
{
// Perform(UM_HANDLEAUTOPROJ, AUTOSAVE_FILE_CLEAR, 0);//add by tj 2014/3/5
int iCurrActivePage = m_pPgCtrl_Work->ActivePageIndex;
if (iCurrActivePage == 1) {
RecordForm->StopClick(NULL);
}
else if (iCurrActivePage == 2) {
BaseForm->StopClick(NULL);
}
else if (iCurrActivePage == 3) {
ComposeForm->StopClick(NULL);
}
else if (iCurrActivePage == 4) {
CompleteForm->StopClick(NULL);
}
TProgressForm *frmProgress = new TProgressForm(NULL);
int ret = frmProgress->Project_Load(strName);
int eExtra = frmProgress->GetOpertaionResult();
delete frmProgress;
if( ret==mrOk ) {
g_bAutoOpenProjectEnable = true; //add by tj 2014/05/15
//add upload by tj 2004/03/26
memset( &g_infoSong, 0, sizeof(TSONGINFO) );
g_infoSong.size = sizeof(TSONGINFO);
memset( g_infoSong.iMusicStyle, -1, 4 );
g_infoSong.iSubmit = 1;
if( g_strProjectName.length()!=0 ) {
String strName = g_strProjectName.c_str();
AnsiString strTitle = TPath::GetFileNameWithoutExtension( strName );
strcpy( g_infoSong.strSongName, strTitle.c_str() );
}
if (!SetSelectFont()) {
String strMsg;
strMsg = g_strProjError[E_PROJ_INVALIDFONT - E_PROJ_NOERROR - 1];
MessageForm->ShowMessage(strMsg, MB_ICONINFORMATION | MB_OK);
}
else{
m_lbFontSelect->ItemIndex = g_idFont;
m_lblFontName->Caption = g_lstFonts[g_idFont]->strFontName;
}
m_labCaption->Caption = String(APPNAME) + L" - " + TPath::GetFileNameWithoutExtension
(strName);
SetInitVar();
m_pSysMenu->EnabledMenuItem(MENU_SAVE, true);
m_pSysMenu->EnabledMenuItem(MENU_SAVEAS, true);
UpdateProjectMenuItems();
int iActivePage = iCurrActivePage;
if (g_iCurrentPage >= 0) {
iActivePage = g_iCurrentPage;
}
if (g_lstMelodyBars.size() == 0 && iActivePage > 1) {
iActivePage = 1;
}
else if (g_lstMelodyStages.size() == 0 && iActivePage > 2) {
iActivePage = 2;
}
if( g_lstMelodyStages.size()>0 && !g_bBaseComposeLoaded ){
ReloadBaseCompose();
}
for( int i = 0; i < 5; i++ ){
if( g_lstMelodyBars.empty() && i>1 ){
m_btnStep[i]->Enabled = false;
}
else{
m_btnStep[i]->Enabled = true;
}
}
PostMessage(Handle, UM_JUMP_PAGE, WPARAM(iActivePage),LPARAM(0));
}
else if( eExtra!=0 ){
String strErr;
if (eExtra > E_PROJ_NOERROR) {
strErr = g_strProjError[eExtra - E_PROJ_NOERROR - 1];
}
MessageForm->ShowMessage(strErr, MB_ICONERROR | MB_OK);
for (int i = 0; i < g_lstRecentProject.size(); i++) {
if (LowerCase(g_lstRecentProject[i].c_str()) == LowerCase(strName))
{
g_lstRecentProject.erase(g_lstRecentProject.begin() + i);
UpdateProjectMenuItems();
break;
}
}
NewProject();
}
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::OnBtnSysMenuClick(TObject *Sender)
{
TPNGButton *pButton = (TPNGButton*)Sender;
TPoint pointClient(pButton->Left, pButton->Top + pButton->Height - 2);
TPoint pointScreen = ClientToScreen(pointClient);
PostMessage(Handle, UM_SHOWSYSMENU, WPARAM(pointScreen.X),
LPARAM(pointScreen.Y));
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::OnShowSysMenu(TMessage &msg)
{
m_pSysMenu->Popup(int(msg.WParam), int(msg.LParam));
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::OnUserHelp(TObject *Sender)
{
HelpBoxClick(NULL);
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::OnForumVist(TObject *Sender)
{
char strURL[256];
f_CS_GetWebPageURL( URL_TECHFORUM, strURL );
ShellExecute(Handle, NULL, ((String)strURL).c_str(), NULL, NULL, SW_SHOWNORMAL);
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::OnSoftwares(TObject *Sender)
{
PostMessage(Handle, UM_SHOWMORE, 0, 0);
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::OnAbout(TObject *Sender)
{
PostMessage(Handle, UM_SHOWABOUT, 0, 0);
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::WMNCHitTest(TWMNCHitTest &Msg)
{
TForm::Dispatch(&Msg);
if (Msg.Result == HTCLIENT && Msg.XPos > Left + DPIX(152) && Msg.XPos <
Left + Width - DPIX(95) && Msg.YPos < Top + DPIY(24))
Msg.Result = HTCAPTION;
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::WMNCLButtonDblClk(TWMNCLButtonDblClk &Msg)
{
if (Msg.HitTest == HTCAPTION && m_pPgCtrl_Work->ActivePageIndex != 0) {
if (WindowState == wsNormal) {
WindowState = wsMaximized;
}
else
WindowState = wsNormal;
g_iWindowState = WindowState;
}
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::OnRestoreWindow(TMessage &msg)
{
if (WindowState == wsMinimized) {
WindowState = g_iWindowState;
}
FormStyle = fsStayOnTop;
Application->BringToFront();
FormStyle = fsNormal;
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::OnShowNextPage(TMessage &msg)
{
m_pSysMenu->EnabledMenuItem(MENU_SAVE, true);
m_pSysMenu->EnabledMenuItem(MENU_SAVEAS, g_strProjectName.length() > 0);
int iActivePage = m_pPgCtrl_Work->ActivePageIndex + (msg.WParam ? 1 : -1);
if( msg.LParam != 0)
{
OnSelectPageStep(( TObject*)m_btnStep[4]);
return ;
}
SetActivePage(iActivePage);
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::OnLoadProjectMessage(TMessage &msg)
{
if (msg.LParam != 0) {
int BUF_SIZE = 256;
TCHAR szName[] = TEXT("MyFileMappingObject");
LPTSTR pBuf;
HANDLE hMapFile = OpenFileMapping(FILE_MAP_ALL_ACCESS,
// read/write access
FALSE, // do not inherit the name
szName); // name of mapping object
if (hMapFile) {
pBuf = (LPTSTR) MapViewOfFile(hMapFile, // handle to map object
FILE_MAP_ALL_ACCESS, // read/write permission
0, 0, BUF_SIZE);
if (pBuf) {
m_strLoadProjectName = pBuf;
UnmapViewOfFile(pBuf);
PostMessage(Handle, UM_LOADPROJECT, 0, 0);
}
CloseHandle(hMapFile);
}
}
else {
OnLoadProject(NULL);
}
msg.Result = true;
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::OnSaveProjectMessage(TMessage &msg)
{
OnSaveProject(NULL);
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::OnNewProjectMessage(TMessage &msg)
{
NewProject();
}
// ---------------------------------------------------------------------------
void TMainForm::NewProject()
{
g_bAutoOpenProjectEnable = false; //add by tj 2014/05/15
m_labCaption->Caption = String(APPNAME) + L" - Untitle";
m_pSysMenu->EnabledMenuItem(MENU_SAVE, false);
m_pSysMenu->EnabledMenuItem(MENU_SAVEAS, false);
ClearGlobalVars();
ClearSVDVars();
memset( &g_infoSong, 0, sizeof(TSONGINFO) );
g_infoSong.size = sizeof(TSONGINFO);
memset( g_infoSong.iMusicStyle, -1, 4 );
g_infoSong.iSubmit = 1;//add upload by tj 2004/03/26
g_bPredefine = false;
g_iMelodyKey = g_iComposeKey = -1;
g_bkMelody.Clear();
g_bkCompose.Clear();
g_strProjectName.clear();
// 缺省打开进入录音页面
if(g_iSelectedStyleID==-1){//如果没选择风格,随机选择
SetupForm->SetDefaultStyle();
}
SetActivePage(1);
m_btnThrdStep->Enabled = false;
m_btnFrthStep->Enabled = false;
m_btnFifthStep->Enabled = false;
ResetAudioEffects();
f_CS_ResetProject();
g_bProjStylePaid = false;
}
// ---------------------------------------------------------------------------
void TMainForm::SetActivePage(int iActiveIndex)
{
int iOriActive = m_pPgCtrl_Work->ActivePageIndex;
if( iOriActive==iActiveIndex )
return;
for(int i = 0; i < 5; i++){
m_btnStep[i]->SetDown((iActiveIndex==i));
}
m_pPgCtrl_Work->ActivePageIndex = iActiveIndex;
if (iActiveIndex == 0) {
if (WindowState == wsMaximized){
WindowState = wsNormal;
}
m_btnMaxBox->Enabled = false;
}
else {
if (WindowState != g_iWindowState){
WindowState = g_iWindowState;
}
if (WindowState == wsNormal) {
m_btnMaxBox->Enabled = true;
}
}
m_pPgCtrl_Work->ActivePage->SetBounds(0, 0, m_pPgCtrl_Work->Width, m_pPgCtrl_Work->Height);
TForm * pForm = (TForm*)m_paTabSheets[iActiveIndex]->Controls[0];
pForm->OnActivate(NULL);
if( iActiveIndex<5 )
pForm->Perform( UM_SETFONTPOSITION, 0, 0 );
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::CloseBoxClick(TObject *Sender)
{
// OnSysExit(Sender);
Close();
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::MinBoxClick(TObject *Sender)
{
WindowState = wsMinimized;
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::FormResize(TObject *Sender)
{
switch (WindowState) {
case wsMaximized:
case wsNormal: {
if (WindowState == wsMaximized) {
Align = alClient;
m_btnMaxBox->Visible = false;
m_btnRestBox->Visible = true;
}
else {
Align = alNone;
m_btnMaxBox->Visible = true;
if (m_pPgCtrl_Work->ActivePageIndex == 0) {
m_btnMaxBox->Enabled = false;
}
else {
m_btnMaxBox->Enabled = true;
}
m_btnRestBox->Visible = false;
}
LockWindowUpdate(Handle);
int xBrd = DPIX(6),
yBrd = DPIY(6);
// 绘制圆角窗体
HRGN hRgn = CreateRoundRectRgn(0, 0, Width + 1, Height + 1, xBrd, yBrd);
SetWindowRgn(Handle, hRgn, TRUE);
DeleteObject(hRgn);
int xGap = DPIX(22);
m_btnCloseBox->Left = Width - xGap - xBrd;
m_btnMaxBox->Left = m_btnCloseBox->Left - xGap;
m_btnRestBox->Left = m_btnCloseBox->Left - xGap;
m_btnMinBox->Left = m_btnMaxBox->Left - xGap;
m_btnHelpBox->Left = m_btnMinBox->Left - xGap;
m_labCaption->Left = (Width - m_labCaption->Width) / 2;
m_pImageStep->Left = (Width - m_pImageStep->Width) / 2;
m_btnFirstStep->Left = m_pImageStep->Left + m_btnFirstStep->ClientRect.Width()/2;
m_btnFifthStep->Left = m_pImageStep->BoundsRect.Right - DPIX(30);
int iInterval = (m_btnFifthStep->Left - m_btnFirstStep->BoundsRect.Right)/4 - m_btnFifthStep->ClientRect.Width() + DPIX(5);
m_btnSecStep->Left = m_btnFirstStep->BoundsRect.Right + iInterval;
m_btnThrdStep->Left = m_btnSecStep->BoundsRect.Right + iInterval;
m_btnFrthStep->Left = m_btnThrdStep->BoundsRect.Right + iInterval;
m_btnFifthStep->Left = m_btnFrthStep->BoundsRect.Right + iInterval;
m_lblExtFont->Left = Width - DPIX(110);
m_pPgCtrl_Work->SetBounds( m_pPgCtrl_Work->Left, m_pPgCtrl_Work->Top,
ClientWidth - 2 * xBrd, ClientHeight - m_pImgTopTile->Height - yBrd );
m_pPgCtrl_Work->ActivePage->SetBounds(0, 0, m_pPgCtrl_Work->Width, m_pPgCtrl_Work->Height);
if( m_pPgCtrl_Work->ActivePageIndex<5 ){
TForm * pForm = (TForm*)m_paTabSheets[m_pPgCtrl_Work->ActivePageIndex]->Controls[0];
pForm->Perform( UM_SETFONTPOSITION, 0, 0 );
}
LockWindowUpdate(NULL);
}
break;
default:
break;
}
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::MaxBoxClick(TObject *Sender)
{
WindowState = wsMaximized;
g_iWindowState = WindowState;
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::RestBoxClick(TObject *Sender)
{
WindowState = wsNormal;
g_iWindowState = WindowState;
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::LoginClick(TObject *Sender)
{
PostMessage(Handle, UM_LOGIN, 0, 0);
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::OnNetworkError(TMessage &msg)
{
WORD eMessage = HIWORD(msg.WParam);
WORD eExtra = LOWORD(msg.WParam);
DebugPrint("网络访问错误,消息号:%d,错误号:0x%X\n", eMessage, eExtra);
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::OnNetworkMessage(TMessage &msg)
{
WORD eMessage = HIWORD(msg.WParam);
WORD eExtra = LOWORD(msg.WParam);
switch (eMessage) {
case e_loginResponse:
if (eExtra == 0) {
PTUSERINFO pUserInfo = PTUSERINFO(msg.LParam);
m_btnLogin->Visible = false;
m_lblLoging->Visible = false;
m_btnCancelLog->Visible = false;
m_panelNoticeNum->Left = DPIX(142);
String strHeaderPath = g_strUserPath.c_str();
strHeaderPath += L"header\\";
String strIconFile = strHeaderPath + g_infoUser.strIconFile;
if( !FileExists( strIconFile ) )
strIconFile = strHeaderPath + L"default.jpg";
GetPic(strIconFile, true);
m_imgUserIcon->Picture->LoadFromFile( strIconFile );
if( strlen(g_infoUser.strNickName)>0 ){
m_lblUsername->Caption = g_infoUser.strNickName;
}
else{
m_lblUsername->Caption = g_infoUser.strUserName;
}
TPngImage *pImgVip = new TPngImage();
if(-1==g_infoUser.accountInfo.vipPeriod){
pImgVip->LoadFromResourceName(int(HInstance), L"vipForever");
m_imgVip->Hint = L"终身VIP会员";
}else if( 0==g_infoUser.accountInfo.vipPeriod ) {
pImgVip->LoadFromResourceName(int(HInstance), L"vipNone");
m_imgVip->Hint = L"点击成为VIP会员";
}else {
pImgVip->LoadFromResourceName(int(HInstance), L"vipTimer");
String strDay = L"VIP权限剩余";
int nDay = g_infoUser.accountInfo.vipPeriod/(60*60*24);
int nAdd = g_infoUser.accountInfo.vipPeriod%(60*60*24)==0?0:1;
strDay += IntToStr(nDay+nAdd);
strDay += L"天,点击续费";
m_imgVip->Hint = strDay;
}
m_imgVip->Picture->Assign(pImgVip);
SAFE_DELETE(pImgVip)
m_imgVip->ShowHint = true;
m_panelUserInfo->Visible = true;
g_bLogon = true;
DebugPrint(
"用户信息:\n ID=%d\n nickname: %s\n banlance=%d\n styleNum=%d\n authority=0x%X\n icon: %s\n",
g_infoUser.accountInfo.ID, g_infoUser.strNickName,
g_infoUser.accountInfo.balance,
g_infoUser.ownStyleNum, g_infoUser.accountInfo.authority,
g_infoUser.strIconFile );
Update();
g_bRecProtect = IsProtected();
f_MM_SetRecordProtect( g_bRecProtect );
int nPublic = f_CS_GetNewNoticeNum( 0 );
int num = f_CS_GetNewNoticeNum( g_infoUser.accountInfo.ID );
m_panelNoticeNum->Parent = m_panelUserInfo;
m_panelNoticeNum->Left = DPIX(94);
m_panelNoticeNum->Top = 0;
if( num>0 || nPublic>0 ){
m_pbUserNoticeNum->Tag = num + nPublic;
if( !m_panelNoticeNum->Visible ){
m_panelNoticeNum->Visible = true;
}
else{
m_panelNoticeNum->Invalidate();
}
String strNoticeHint = "有 ";
if( nPublic>0 ){
strNoticeHint += nPublic;
strNoticeHint += " 条网站最新公告\n和 ";
}
strNoticeHint += num;
strNoticeHint += " 条未读个人消息\n请点击查看";
m_pbUserNoticeNum->Hint = strNoticeHint;
}
}
else{
if( eExtra==e_LoginPasswordError || eExtra == e_LoginUserNotExist || eExtra==e_VipExceeded
|| eExtra==e_UserLocked || eExtra == e_UserDeleted){
ShowErrorMessage( eExtra, "登录失败!" );
g_infoUser.strPassword[0] = 0;
PostMessage(Handle, UM_LOGIN, 0, 0);
}
}
break;
case e_iconResponse:
if (eExtra == 0) {
String strIconFile = g_strUserPath.c_str();
strIconFile += L"header\\";
strIconFile += g_infoUser.strIconFile;
if( FileExists( strIconFile ) ) {
GetPic(strIconFile, true);
m_imgUserIcon->Picture->LoadFromFile( strIconFile );
}
}
break;
case e_logoffResponse:
m_btnLogin->Visible = true;
m_panelUserInfo->Visible = false;
m_lblLoging->Visible = false;
m_btnCancelLog->Visible = false;
m_panelNoticeNum->Parent = this;
m_panelNoticeNum->Left = DPIX(124);
m_panelNoticeNum->Top = DPIY(2);
m_panelNoticeNum->Visible = false;
//add upload by tj 2004/03/26
if( !strcmp( g_infoSong.strSinger, g_infoUser.strNickName ) )
g_infoSong.strSinger[0] = '\0';
if( !strcmp( g_infoSong.strLyricist, g_infoUser.strNickName ) )
g_infoSong.strLyricist[0] = '\0';
if( !strcmp( g_infoSong.strComposer, g_infoUser.strNickName ) )
g_infoSong.strComposer[0] = '\0';
if( !strcmp( g_infoSong.strArranger, g_infoUser.strNickName ) )
g_infoSong.strArranger[0] = '\0';
char strName[80];
strcpy(strName, g_infoUser.strUserName);
memset(&g_infoUser, 0, sizeof(g_infoUser));
strcpy(g_infoUser.strUserName, strName);
if( HelpForm ) HelpForm->SetNoticeNum( 0, 1 );
g_bLogon = false;
break;
case e_versionResponse:
if (eExtra == e_DatabaseError) {
DebugPrint("服务器数据访问失败!\n");
break;
}
else {
if (eExtra == e_UpdateMandatory || eExtra == e_UpdateOptional) {
int year = g_infoSoftwareUpdate.tIssueDate >> 16;
int month = (g_infoSoftwareUpdate.tIssueDate & 0xFF00) >> 8;
int day = g_infoSoftwareUpdate.tIssueDate & 0xFF;
string sDescribe = UTF8ToMBCS(g_infoSoftwareUpdate.strDescribe);
DebugPrint(
"最新的客户端版本:Ver %d.%d.%d.%04d\n发布时间:%d-%d-%d\n文件大小:%dK\n文件描述:%s\n",
g_infoSoftwareUpdate.version.majorVersion,
g_infoSoftwareUpdate.version.minorVersion,
g_infoSoftwareUpdate.version.modifyVersion,
g_infoSoftwareUpdate.version.buildVersion, year, month, day,
g_infoSoftwareUpdate.nFileSize, sDescribe.c_str());
if (eExtra == e_UpdateMandatory) {
DebugPrint("该版本为强制更新版。\n\n");
LogoffClick(NULL);
g_bUpdateMandatory = true;
// m_panelUserInfo->Visible = false;
m_btnLogin->Visible = false;
m_lblLoging->Visible = false;
m_btnCancelLog->Visible = false;
CompleteForm->EnableNextStep(false);
}
// don't display the update information while new user operator the software first
UpdateForm = new TUpdateForm(NULL);
UpdateForm->ShowModal();
delete UpdateForm;
}
}
break;
case e_noticeUpdateResponse:
if (eExtra == 0) {
WORD idUser = HIWORD(msg.LParam);
WORD nUnchecked = LOWORD(msg.LParam);
// HelpForm->SetNoticeNum( nUnchecked, idUser ? 1 : 0 );
int nUser = f_CS_GetNewNoticeNum( g_infoUser.accountInfo.ID );
int nPublic = f_CS_GetNewNoticeNum( 0 );
if( nUser>0 || nPublic>0 ){
m_pbUserNoticeNum->Tag = nUser + nPublic;
if( !m_panelNoticeNum->Visible ){
m_panelNoticeNum->Visible = true;
}
else{
m_panelNoticeNum->Invalidate();
}
//int nPublic = HelpForm->GetNoticeNum( 0 );
// int nUser = HelpForm->GetNoticeNum( 1 );
String strNoticeHint = "有 ";
if( nPublic>0 ){
strNoticeHint += nPublic;
strNoticeHint += " 条网站最新公告";
if( nUser>0 ){
strNoticeHint += "\n和 ";
}
}
if( nUser>0 ){
strNoticeHint += nUser;
strNoticeHint += " 条未读个人消息\n请点击查看";
}
m_pbUserNoticeNum->Hint = strNoticeHint;
}
else{
m_panelNoticeNum->Visible = false;
}
}
break;
}
}
void __fastcall TMainForm::LogoffClick(TObject *Sender)
{
// if( g_bLogon )
f_CS_Logoff();
/* m_btnLogin->Visible = true;
m_panelUserInfo->Visible = false;
m_lblLoging->Visible = false;
m_btnCancelLog->Visible = false;
m_panelNoticeNum->Parent = this;
m_panelNoticeNum->Left = 124;
m_panelNoticeNum->Top = 2;
m_panelNoticeNum->Visible = false;
//add upload by tj 2004/03/26
if( !strcmp( g_infoSong.strSinger, g_infoUser.strNickName ) )
g_infoSong.strSinger[0] = '\0';
if( !strcmp( g_infoSong.strLyricist, g_infoUser.strNickName ) )
g_infoSong.strLyricist[0] = '\0';
if( !strcmp( g_infoSong.strComposer, g_infoUser.strNickName ) )
g_infoSong.strComposer[0] = '\0';
if( !strcmp( g_infoSong.strArranger, g_infoUser.strNickName ) )
g_infoSong.strArranger[0] = '\0';
char strName[80];
strcpy(strName, g_infoUser.strUserName);
memset(&g_infoUser, 0, sizeof(g_infoUser));
strcpy(g_infoUser.strUserName, strName);
HelpForm->SetNoticeNum( 0, 1 );
g_bLogon = false;
*/
}
// ---------------------------------------------------------------------------
void TMainForm::InitFontList()
{
UnicodeString strPath = g_strExecutePath.c_str(),
strWildcard[2] = { L"*.", L"*.sf2" };
AnsiString strFileName = strPath.c_str();
char strFontName[80];
// 添加音色库
TSearchRec sr;
int iAttr = 0;
g_strFontPath = g_strExecutePath;
g_strFontPath += L"Fonts\\";
strPath = g_strFontPath.c_str();
for( int i=0; i<2; i++ ){
if (FindFirst(strPath + strWildcard[i], iAttr, sr) == 0) {
do {
strFileName = g_strFontPath.c_str();
strFileName += sr.Name;
if (f_MM_GetFontInfo(strFileName.c_str(), strFontName ) == S_OK) {
bool bAdd = true;
int iInsert = -1;
for( int j=0; j<g_lstFonts.size(); j++ ){
FONTINFO* pF = g_lstFonts[j];
int iComp = StrComp( strFontName, pF->strFontName );
if( iComp < 0 ){
iInsert = j;
break;
}
else if( iComp==0 ){
bAdd = false;
break;
}
}
if( bAdd ){
FONTINFO * pNewFI = new FONTINFO;
strcpy(pNewFI->strFileName, strFileName.c_str());
if (strlen(strFontName) > 0)
strcpy(pNewFI->strFontName, strFontName);
else{
char *c_name = strFileName.c_str(),
*name = strrchr( c_name, '\\' )+1,
*ext = strrchr( c_name, '.' );
if( ext>name ){
strncpy( pNewFI->strFontName, name, ext-name );
pNewFI->strFontName[ext-name] = '\0';
}
else
strcpy(pNewFI->strFontName, name );
}
if( iInsert<0 ){
g_lstFonts.push_back(pNewFI);
}
else{
g_lstFonts.insert( g_lstFonts.begin()+iInsert, pNewFI );
}
}
}
}
while (FindNext(sr) == 0);
FindClose(sr);
}
else {
iAttr = GetLastError();
}
}
HRESULT res = 0;
char strExtDir[256] = "";
if( !g_strExtFontsPath.empty() ){
sprintf( strExtDir, "%s\\ext\\", ((AnsiString)g_strExtFontsPath.c_str()).c_str() );
res = f_MM_CheckExtFont( strExtDir );
}
if( !(res & 0x01) ){
char strDefExtDir[256];
sprintf( strDefExtDir, "%sFonts\\ext\\", ((AnsiString)g_strExecutePath.c_str()).c_str() );
if( stricmp( strDefExtDir, strExtDir ) ){
res = f_MM_CheckExtFont( strDefExtDir );
}
}
g_bExtFontUsable = res & 0x01;
if( g_bExtFontUsable ){
// m_lblExtFont->Visible = false;
m_lblExtFont->Tag = 1;
m_lblExtFont->Caption = L"iChangzuo.com";
m_lblExtFont->Hint = L"欢迎访问唱作网";
TFontStyles fs;
fs << fsUnderline;
fs << fsItalic;
m_lblExtFont->Font->Style = fs;
FONTINFO * pFI = new FONTINFO;
strcpy(pFI->strFileName, "extend fonts" );
strcpy(pFI->strFontName, "唱作网扩展音色库" );
g_lstFonts.insert( g_lstFonts.begin(), pFI );
}
}
// ---------------------------------------------------------------------------
bool TMainForm::SetSelectFont()
{
bool bLastFontFound = false;
int idDefaultFont = -1;
for (int i = 0; i < g_lstFonts.size(); i++) {
FONTINFO * pFI = g_lstFonts[i];
if (ExtractFileName(pFI->strFileName).Compare(g_strDefaultSoundSet) == 0) {
idDefaultFont = i;
}
if (ExtractFileName(pFI->strFileName).Compare(g_strFontFile.c_str()) == 0) {
bLastFontFound = true;
g_idFont = i;
break;
}
}
if (!bLastFontFound) {
if (idDefaultFont != -1) {
g_strFontFile = str2wstr(g_strDefaultSoundSet);
g_idFont = idDefaultFont;
}
else {
g_strFontFile = ExtractFileName(g_lstFonts[0]->strFileName).c_str();
g_idFont = 0;
}
}
AnsiString strFontFile;
if( g_strFontFile.compare( L"extend fonts" ) )
strFontFile = g_strFontPath.c_str();
strFontFile += g_strFontFile.c_str();
f_MM_SetFont(strFontFile.c_str());
return bLastFontFound;
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::FormKeyDown(TObject *Sender, WORD &Key, TShiftState Shift)
{
if( !Shift.Contains( ssAlt ) ){
switch (Key) {
case VK_F1:{
TMenuItem* pItem = m_pSysMenu->GetMainMenuItem(MENU_HELP);
if( pItem->Enabled )
OnUserHelp();
}
break;
case VK_F2: {
TMenuItem* pItem = m_pSysMenu->GetMainMenuItem(0);
if( pItem->Enabled )
OnLoadProject(pItem);
}
break;
case VK_F3:
case VK_F4: {
int index = (Key == VK_F3) ? MENU_SAVE : MENU_SAVEAS;
TMenuItem* pItem = m_pSysMenu->GetMainMenuItem(index);
if (pItem->Enabled)
OnSaveProject(pItem);
}
break;
case VK_F6: {
OnCreateNewProject();
}
break;
case VK_RETURN:
if( m_lbFontSelect->Visible ){
int iSel = m_lbFontSelect->ItemIndex;
if( iSel!=g_idFont ){
m_lblFontName->Caption = g_lstFonts[iSel]->strFontName;
if( f_MM_SetFont( g_lstFonts[iSel]->strFileName )==S_OK ){
g_idFont = iSel;
g_strFontFile = ExtractFileName(g_lstFonts[iSel]->strFileName).c_str();
}
}
m_lbFontSelect->Hide();
}
break;
case 'L':
if( m_btnFontChange->Enabled ){
FontChangeMouseDown( NULL, mbLeft, TShiftState(1<<ssLeft), 0, 0 );
}
break;
}
}
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::HintTimerProc(TObject* Sender)
{
m_pTimerHint->Enabled = false;
m_bShowHint = true;
TPoint point(m_imgUserFrame->Width, 2);
// TPoint point(0, m_imgUserFrame->Top + m_imgUserFrame->Height);
point = m_imgUserFrame->ClientToScreen(point);
String strHint = "用户名:";
strHint += g_infoUser.strUserName;
strHint += "\n昵 称:";
strHint += g_infoUser.strNickName;
strHint += "\n音符数:";
strHint += IntToStr(g_infoUser.accountInfo.balance);
// strHint += "\n魅力值:";
// strHint += IntToStr(g_infoUser.accountInfo.pops);
// strHint += "\n粉丝数:";
// strHint += IntToStr(g_infoUser.accountInfo.fans);
// strHint += "\n歌曲数:";
// strHint += IntToStr(g_infoUser.accountInfo.songs);
strHint += "\n\n点击查看详情";
m_pStyleInfoWnd->ShowHintWindow(point, strHint);
}
void __fastcall TMainForm::UsernameMouseEnter(TObject *Sender)
{
Screen->Cursor = crHandPoint;
m_lblUsername->Font->Color = clBlue;
TFontStyles fs;
fs << fsUnderline;
fs << fsBold;
m_lblUsername->Font->Style = fs;
if (!m_bShowHint) {
m_pTimerHint->Enabled = true;
m_bShowHint = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::UsernameMouseLeave(TObject *Sender)
{
m_pStyleInfoWnd->ReleaseHandle();
m_pTimerHint->Enabled = false;
m_bShowHint = false;
Screen->Cursor = crDefault;
m_lblUsername->Font->Color = clBlack;
TFontStyles fs;
fs << fsBold;
m_lblUsername->Font->Style = fs;
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::UsernameMouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
char strURL[256];
f_CS_GetWebPageURL( URL_USERCENTER, strURL );
ShellExecute(Handle, NULL, ((String)strURL).c_str(), NULL, NULL, SW_SHOWNORMAL);
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::AcceptFiles(TMessage& Msg)
{
const int m_nMaxFileNameLen = 255;
wchar_t m_wsFileName[m_nMaxFileNameLen];
DragQueryFile((HDROP)Msg.WParam, 0, m_wsFileName, m_nMaxFileNameLen);
if (g_lstMelodyBars.size() > 0 && (g_strProjectName.length() == 0 ||
HasProjectModified())) {
int mrRet = MessageForm->ShowMessage("是否保存当前工程?",
MB_ICONQUESTION | MB_YESNOCANCEL);
if (mrRet == mrYes) {
DebugPrint("确认保存");
OnSaveProject(NULL);
}
else if (mrRet == mrCancel) {
return;
}
}
SetInitVar(true);
LoadProject(m_wsFileName);
DragFinish((HDROP)Msg.WParam);
}
// ---------------------------------------------------------------------------
void TMainForm::SetSysMenuState(int iMenuIndex, bool bIsEnable)
{
m_pSysMenu->EnabledMenuItem(iMenuIndex, bIsEnable);
}
// ---------------------------------------------------------------------------
int TMainForm::GetActivePageIndex()
{
return m_pPgCtrl_Work->ActivePageIndex + 1;
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::OnSelectPageStep(TObject *Sender)
{
int iTagIndex = ((TPNGButton*)Sender)->Tag % 5;
int iOldPage = m_pPgCtrl_Work->ActivePageIndex;
if( iOldPage == iTagIndex)
return;
if( iOldPage == 0 || iOldPage == 1 || iOldPage == 4 || iOldPage==5 )
g_bCanStep = true;
PostMessage(Handle, UM_JUMP_PAGE, WPARAM(iTagIndex),LPARAM(this));
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::OnJumpPage(TMessage & Msg)
{
int iOldPage = m_pPgCtrl_Work->ActivePageIndex;
int iNextPage = (int)Msg.WParam;
TForm * pForm = (TForm*)m_paTabSheets[iOldPage]->Controls[0];
pForm->OnDeactivate((TObject*)Msg.LParam);
if( !g_bBaseComposeLoaded && (iNextPage==3 || iNextPage==4) ){
ReloadBaseCompose();
}
if( g_bCanStep || iOldPage==5 ){
if( iOldPage==iNextPage )
pForm->OnActivate(NULL);
else
SetActivePage(iNextPage);
m_pSysMenu->EnabledMenuItem( MENU_SAVE, g_lstMelodyBars.size()>0
&& iNextPage!=0 && iNextPage!=5 );
m_pSysMenu->EnabledMenuItem( MENU_SAVEAS, g_lstMelodyBars.size()>0
&& iNextPage!=0 && iNextPage!=5 );
}
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::OnRefreshStepPageState(TMessage & Msg)
{
bool bEnableProj = Msg.WParam & 0x1;
if( !bEnableProj || !m_btnStep[0]->Enabled ){ //录音,禁止打开/新建工程/帮助
for( int j=0; j<=MENU_HELP; j++ ){
if( j==MENU_SAVE || j==MENU_SAVEAS )
m_pSysMenu->EnabledMenuItem( j, bEnableProj && g_lstMelodyBars.size()>0 );
else
m_pSysMenu->EnabledMenuItem( j, bEnableProj );
}
}
for( int i = 0; i < 5; i++ ){
if( g_lstMelodyBars.empty() && i>1 ){
m_btnStep[i]->Enabled = false;
}
else{
m_btnStep[i]->Enabled = (Msg.WParam>>i) & 0x1;
}
}
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::HelpBoxClick(TObject *Sender)
{
TMenuItem* pItem = m_pSysMenu->GetMainMenuItem(MENU_HELP);
if( pItem->Enabled && m_pPgCtrl_Work->ActivePageIndex!=5 ){
HelpForm->m_iPrevPageIndex = m_pPgCtrl_Work->ActivePageIndex;
PostMessage(Handle, UM_JUMP_PAGE, WPARAM(5),LPARAM(this));
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::OnShowAbout(TMessage & Msg)
{
TAboutForm * pDlg = new TAboutForm(NULL);
pDlg->ShowModal();
delete pDlg;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::OnShowMore(TMessage & Msg)
{
// TSoftwaresForm * pDlg = new TSoftwaresForm(NULL);
//
// pDlg->ShowModal();
//
// delete pDlg;
char strURL[256];
f_CS_GetWebPageURL(URL_SOFTWARE, strURL);
ShellExecute(Handle, NULL, ((String)strURL).c_str(), NULL, NULL, SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::OnOpenManual(TMessage & Msg)
{
OnUserManual();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::OnUserManual(TObject *Sender)
{
HWND hHelp = FindWindow(NULL, L"伴奏魔方 用户手册");
if (hHelp) {
ShowWindow(hHelp, SW_RESTORE);
}
else {
String helpFile = g_strExecutePath.c_str();
helpFile += "Help/ACManual.chm";
ShellExecute(Handle, L"Open", helpFile.c_str(), NULL, NULL,
SW_MAXIMIZE);
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::OnAudioEffect(TMessage & Msg)
{
TAudioEffectForm * pAEForm = new TAudioEffectForm(NULL, Msg.WParam);
if( pAEForm->ShowModal()==mrOk ){
SaveAutoProj();
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::UserNoticeNumPaint(TObject *Sender)
{
int x = 0;
if( m_bUNHot ){
x = -m_pImgNoticeNum->Width/2;
}
m_pbUserNoticeNum->Canvas->Draw(x, 0, m_pImgNoticeNum);
String strText = m_pbUserNoticeNum->Tag;
m_pbUserNoticeNum->Canvas->Brush->Style = bsClear;
m_pbUserNoticeNum->Canvas->Font->Color = clWhite;
int txtWidth = m_pbUserNoticeNum->Canvas->TextWidth( strText );
int txtHeight = m_pbUserNoticeNum->Canvas->TextHeight( strText );
m_pbUserNoticeNum->Canvas->TextOut( (m_pbUserNoticeNum->Width - txtWidth)/2.0+0.5,
(m_pbUserNoticeNum->Height -txtHeight)/2.0,
strText );
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::UserNoticeNumClick(TObject *Sender)
{
char strURL[256];
f_CS_GetWebPageURL( URL_USERNOTICE, strURL );
ShellExecute(Handle, NULL, ((String)strURL).c_str(), NULL, NULL, SW_SHOWNORMAL);
// int num = 0;
// f_CS_GetNotice( num, NULL, 0 );
// f_CS_GetNotice( num, NULL, g_infoUser.accountInfo.ID );
// TMenuItem* pItem = m_pSysMenu->GetMainMenuItem(MENU_HELP);
// if( pItem->Enabled ){
// if( m_pPgCtrl_Work->ActivePageIndex!=5 ){
// HelpForm->m_iPrevPageIndex = m_pPgCtrl_Work->ActivePageIndex;
// SetActivePage( 5 );
// }
// /*
// if( HelpForm->GetNoticeNum(0)>0 ){
// HelpForm->SetPage( 2 );
// }
// else{
// HelpForm->SetPage( 3 );
// }
// */
// if( HelpForm->GetNoticeNum(1)>0 ){
// HelpForm->SetPage( TAB_NT );
// }
// }
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::UserNoticeNumMouseEnter(TObject *Sender)
{
m_bUNHot = true;
m_pbUserNoticeNum->Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::UserNoticeNumMouseLeave(TObject *Sender)
{
m_bUNHot = false;
m_pbUserNoticeNum->Invalidate();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::UMStartCDTimer(TMessage &Message)
{
if(m_pCDTimer==NULL){
m_pCDTimer = new TTimer(this);
m_pCDTimer->Interval = 1000;
m_pCDTimer->OnTimer = CDTimerProc;
m_pCDTimer->Tag = CODE_INTERVAL;
m_pCDTimer->Enabled = true;
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::CDTimerProc(TObject* Sender)
{
if(LoginForm!=NULL){
LoginForm->OnCDTimer(m_pCDTimer->Tag);
}
if( m_pCDTimer->Tag==0 ){
ClearCDTimer();
}
else{
m_pCDTimer->Tag--;
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ClearCDTimer()
{
if( m_pCDTimer ){
m_pCDTimer->Enabled = false;
delete m_pCDTimer;
m_pCDTimer = NULL;
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::OnLogin(TMessage &msg)
{
if( g_bUpdateMandatory )
return;
bool bSync = msg.WParam;
AnsiString strUsernameBk = g_infoUser.strUserName,
strPasswordBk = g_infoUser.strPassword;
LoginForm = new TLoginForm(this);
LoginForm->m_bAutoLog = g_bAutoLogin;
LoginForm->m_strUsername = strUsernameBk;
LoginForm->m_strPassword = strPasswordBk;
BOOL bRepeat = FALSE;
do{
if (LoginForm->ShowModal() == mrOk) {
AnsiString astr = LoginForm->m_strUsername;
strncpy(g_infoUser.strUserName, astr.c_str(), astr.Length() + 1);
astr = LoginForm->m_strPassword;
strncpy(g_infoUser.strPassword, astr.c_str(), astr.Length() + 1);
if( !LoginForm->m_bRegister && !bSync ){
m_btnLogin->Visible = false;
m_lblLoging->Visible = true;
m_btnCancelLog->Visible = true;
m_panelNoticeNum->Left = 138;
g_bAutoLogin = LoginForm->m_bAutoLog;
f_CS_Login(&g_infoUser, FALSE);
}
else{
TProgressForm * dlgProgress = new TProgressForm(NULL);
int ret = LoginForm->m_bRegister ?
dlgProgress->User_Register(LoginForm->isEmailOrMobile) :
dlgProgress->User_Login();
int eExtra = dlgProgress->GetOpertaionResult();
delete dlgProgress;
bRepeat = false;
if( ret!=mrCancel ){
if( eExtra==0 ){
if( g_infoUser.accountInfo.ID==0 ){
DebugPrint( "Invalid user ID.\n" );
}
g_bRecProtect = IsProtected();
f_MM_SetRecordProtect( g_bRecProtect );
g_bLogon = true;
}
else{
ShowErrorMessage( eExtra, LoginForm->m_bRegister ? "注册失败!"
: "登录失败!" );
g_infoUser.strPassword[0] = 0;
LoginForm->m_strPassword = "";
if( eExtra==e_LoginPasswordError
|| eExtra==e_LoginUserNotExist
|| eExtra==e_UsernameExist){
bRepeat = TRUE;
}
}
}
}
}
else {
bRepeat = FALSE;
LogoffClick(NULL);
strncpy(g_infoUser.strUserName, strUsernameBk.c_str(), strUsernameBk.Length() + 1);
strncpy(g_infoUser.strPassword, strPasswordBk.c_str(), strPasswordBk.Length() + 1);
}
}
while( bRepeat );
delete LoginForm;
LoginForm = NULL;
}
// ---------------------------------------------------------------------------
void __fastcall TMainForm::OnSaveMusic(TMessage & Msg)
{
//必须登录后才能进入保存面
if( !g_bLogon ){
Perform( UM_LOGIN, true, 0 );
}
if( !g_bLogon )
return;
ReloadCompose( g_iComposeKey );
//保存到文件
if( !g_strLastSaveFile.empty() ){ //检查有效性
String strPath = ExtractFilePath( g_strLastSaveFile.c_str() );
if( !DirectoryExists( strPath, false ) )
g_strLastSaveFile = L"";
}
TSaveForm * pSave = new TSaveForm(NULL, g_strLastSaveFile.c_str(),
g_iLastSaveOption, g_iLastSaveType );
if( pSave->ShowModal()==mrOk ){
String strFileName = pSave->m_editFileName->Text.c_str();
int iFileType = 0;
if( ExtractFileExt(strFileName).CompareIC(".wav")==0 ){
iFileType = FILETYPE_WAVE;
}
else if( ExtractFileExt(strFileName).CompareIC(".mp3")==0 ){
iFileType = FILETYPE_MP3;
}
else if( ExtractFileExt(strFileName).CompareIC(".mid")==0 ){
iFileType = FILETYPE_MIDI;
}
else{
DebugPrint("无效的文件名:%s\n", pSave->m_editFileName->Text);
goto Cleanup_Line;
}
g_iLastSaveType = iFileType;
int iSaveOption = 0;
if( pSave->m_imgComposeCheck->Tag )
iSaveOption |= SAVE_COMPOSE;
if( pSave->m_imgSongCheck->Tag )
iSaveOption |= SAVE_SONG;
//先检查文件名有效性
int iFileHandle = FileOpen( strFileName, fmOpenReadWrite );
bool bCreate = false;
if( iFileHandle<0 ){
iFileHandle = FileCreate( strFileName );
bCreate = true;
}
if( iFileHandle<0 ){
ShowErrorMessage( e_OpenFileFailed, L"保存失败!" );
goto Cleanup_Line;
}
else{
FileClose( iFileHandle );
if( bCreate )
DeleteFile( strFileName );
}
int iOperation = e_PO_Pay4Basic;
if( iSaveOption & SAVE_COMPOSE ){
iOperation |= e_PO_Pay4Compose;
int iSel = m_lbFontSelect->ItemIndex;
if( iSel>=0 && !strcmp(g_lstFonts[iSel]->strFileName, "extend fonts") )
iOperation |= e_PO_Pay4Fonts;
}
// 检查是否可复制
if( iFileType==FILETYPE_MP3 && ( iSaveOption & SAVE_COMPOSE )
&& ( (iSaveOption & SAVE_SONG ) || g_bPredefine )
&& !g_strMP3File.IsEmpty() && FileExists( g_strMP3File, false ) ){
if( g_strMP3File.CompareIC( strFileName )){
CopyFile( g_strMP3File.c_str(), strFileName.c_str(), false );
}
g_strLastSaveFile = strFileName.c_str();
g_iLastSaveOption = iSaveOption;
String strMessage = "歌曲保存成功。";
MessageForm->ShowMessage( strMessage, MB_OK|MB_ICONINFORMATION );
}
else{
SaveMedia( iOperation, iSaveOption, iFileType, strFileName );
}
}
Cleanup_Line:
delete pSave;
Update();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::OnUploadMusic(TMessage & Msg)
{
//必须登录后才能进入上传界面
if( !g_bLogon )
Perform( UM_LOGIN, true, 0 );
if( !g_bLogon )
return;
ReloadCompose( g_iComposeKey );
if( !g_strMP3File.IsEmpty() && !FileExists( g_strMP3File ))
g_strMP3File = "";
//首先检测上传许可
TProgressForm *frmProgress = new TProgressForm(NULL);
int ret = frmProgress->User_UploadSong( NULL, NULL );//add upload by tj 2004/03/26
int eExtra = frmProgress->GetOpertaionResult();
delete frmProgress;
if( ret==mrCancel ){
return;
}
else if( eExtra!=0 ){
if( eExtra==e_InvalidAuthority ){
TManageSongForm * frmManage = new TManageSongForm(NULL, false);
ret = frmManage->ShowModal();
delete frmManage;
}
else{
ShowErrorMessage( eExtra, "验证失败!" );
}
return;
}
//填写歌曲信息
//add upload by tj 2004/03/26
TUploadForm * pUpload = new TUploadForm( NULL );
wstring strFileName;
while( pUpload->ShowModal()==mrOk ){ //显示对话框直到上传成功或用户取消
eExtra = 0;
strFileName = g_strMP3File.c_str();
//如此前未保存,则保存到Save目录下
if( strFileName.empty() ){
strFileName = g_strUserPath;
strFileName += L"Save\\";
MkDir( strFileName.c_str() );
strFileName += pUpload->m_editSongName->Text.c_str();
strFileName += L".mp3";
int iOperation = e_PO_Pay4Basic | e_PO_Pay4Compose;
int iSel = m_lbFontSelect->ItemIndex;
if( iSel>=0 && !strcmp(g_lstFonts[iSel]->strFileName, "extend fonts") )
iOperation |= e_PO_Pay4Fonts;
eExtra = SaveMedia( iOperation, SAVE_COMPOSESONG, FILETYPE_MP3, strFileName.c_str(), true );
}
//得到文件名,开始上传
if( eExtra==0 ){
//保存伴奏工程
if( g_infoSong.strCpjName && strlen( g_infoSong.strCpjName )>0 ){
SaveProject( g_infoSong.strCpjName, PROJ_MODE_UPLOAD );
}
TSHAREINFO infoShare;
frmProgress = new TProgressForm(NULL);
//add upload by tj 2004/03/26
ret = frmProgress->User_UploadSong( strFileName.c_str(), &infoShare );
eExtra = frmProgress->GetOpertaionResult();
delete frmProgress;
//删除伴奏工程
if( g_infoSong.strCpjName && strlen( g_infoSong.strCpjName )>0 && FileExists( g_infoSong.strCpjName ) ){
DeleteFile( g_infoSong.strCpjName );
}
if( ret==mrOk && eExtra==0 ){
TManageSongForm * frmManage = new TManageSongForm(NULL, true, infoShare.idSong );
frmManage->ShowModal();
delete frmManage;
break;
}
}
//统一处理错误返回值
if( eExtra!=0 ){
if( eExtra==e_InvalidAuthority ){
TManageSongForm * frmManage = new TManageSongForm(NULL, false);
ret = frmManage->ShowModal();
delete frmManage;
if( ret!=mrOk ){
break;
}
}
else if( eExtra!=-1 && eExtra!=e_UserCanceled ){
ShowErrorMessage( eExtra, "上传失败!" );
break;
}
}
}
delete pUpload;
Update();
}
//---------------------------------------------------------------------------
int TMainForm::SaveMedia( int iOperation, int iSaveOption, int iFileType, String strFileName, bool bUpload )
{
UINT nIdCount = 0, aIdStyle[MAX_STYLE_NUM];
for( int i=0; i<g_lstComposeStages.size(); i++ ){
int id = g_lstComposeStages[i]->idStyle;
bool bExist = false;
for( int j=0; j<nIdCount; j++ ){
if( id==aIdStyle[j] ){
bExist = true;
break;
}
}
if( !bExist ){
if( nIdCount>=MAX_STYLE_NUM ){
char buf[200];
sprintf( buf, "每首歌曲的风格数量不能超过 %d 个", MAX_STYLE_NUM );
MessageForm->ShowMessage( buf, MB_ICONERROR|MB_OK );
return false;
}
else{
aIdStyle[nIdCount++] = id;
}
}
}
int nUserBalance = g_infoUser.accountInfo.balance,
nCost = 0,
arrCost[MAX_STYLE_NUM];
TProgressForm * dlgProgress = new TProgressForm(NULL);
int ret = dlgProgress->User_CheckPayment( iOperation, nIdCount, aIdStyle, arrCost, &nCost, &nUserBalance );
int eExtra = dlgProgress->GetOpertaionResult();
delete dlgProgress;
bool bConfirm = false;
if( ret==mrOk ){
g_infoUser.accountInfo.balance = nUserBalance;
if( eExtra==0 || eExtra==e_VerifyInsufficient ){
if( nCost==0 )
bConfirm = true;
else{
TPayMentForm *payMentForm = new TPayMentForm(NULL, iOperation, nIdCount, aIdStyle,
arrCost, nCost, nUserBalance);
bConfirm = ( mrYes==payMentForm->ShowModal() );
delete payMentForm;
if( !bConfirm )
eExtra = e_UserCanceled;
}
}
}
if( bConfirm ){
TProgressForm * dlgProgress = new TProgressForm(NULL);
int ret = dlgProgress->MM_SaveMedia( iSaveOption, iFileType, strFileName.c_str(),
iOperation, nIdCount, aIdStyle );
eExtra = dlgProgress->GetOpertaionResult();
delete dlgProgress;
if( ret==mrOk ){
bool bTip = false;
for( int i=0; i<nIdCount; i++ ){
if( arrCost[i]>0 ){
bTip = true;
break;
}
}
if( bTip ){
//保存风格支付记录
g_bRecProtect = IsProtected();
f_MM_SetRecordProtect( g_bRecProtect );
AnsiString strProjectName = g_strAutoProjName.c_str();
SaveProject( strProjectName.c_str() );
g_bProjStylePaid = true;
}
if( bUpload ){
g_strMP3File = strFileName;
}
else{
g_strLastSaveFile = strFileName.c_str();
g_iLastSaveOption = iSaveOption;
if( iFileType==FILETYPE_MP3 && ( iSaveOption & SAVE_COMPOSE )
&& ( (iSaveOption & SAVE_SONG ) || g_bPredefine )){
g_strMP3File = strFileName;
//g_bSongSaved = true;
}
//SetInitVar();
MessageForm->ShowMessage( "歌曲保存成功。", MB_OK|MB_ICONINFORMATION );
}
if( bTip ){
String strMessage = "风格已支付,请及时保存工程。\n\n是否立即保存?";
if( mrYes==MessageForm->ShowMessage( strMessage, MB_YESNO|MB_ICONQUESTION ) ){
PostMessage( Handle, UM_SAVEPROJECT, 0, 0 );
}
}
}
else if( !bUpload && eExtra!=0 && eExtra!=e_UserCanceled ){
ShowErrorMessage( eExtra, L" 保存失败!" );
}
}
else if( !bUpload && eExtra!=0 && eExtra!=e_UserCanceled ){
ShowErrorMessage( eExtra, L"鉴权失败!" );
}
return eExtra;
}
//---------------------------------------------------------------------------
/*
bool TMainForm::CheckPayment( int iOperation )
{
bool bPaid = false;
if( !g_bLogon ){
Perform( UM_LOGIN, true, 0 );
}
if( g_bLogon ){
UINT nIdCount = 0, aIdStyle[MAX_STYLE_NUM];
// aIdStyle[nIdCount++] = g_iSelectedStyleID;
for( int i=0; i<g_lstComposeStages.size(); i++ ){
int id = g_lstComposeStages[i]->idStyle;
bool bExist = false;
for( int j=0; j<nIdCount; j++ ){
if( id==aIdStyle[j] ){
bExist = true;
break;
}
}
if( !bExist ){
if( nIdCount>=MAX_STYLE_NUM ){
char buf[200];
sprintf( buf, "每首歌曲的风格数量不能超过 %d 个", MAX_STYLE_NUM );
MessageForm->ShowMessage( buf, MB_ICONERROR|MB_OK );
return false;
}
else{
aIdStyle[nIdCount++] = id;
}
}
}
int nUserBalance = g_infoUser.accountInfo.balance,
nCost = 0,
arrCost[MAX_STYLE_NUM];
TProgressForm * dlgProgress = new TProgressForm(NULL);
int ret = dlgProgress->User_CheckPayment( iOperation, nIdCount, aIdStyle, arrCost, &nCost, &nUserBalance );
int eExtra = dlgProgress->GetOpertaionResult();
delete dlgProgress;
if( ret==mrOk ){
g_infoUser.accountInfo.balance = nUserBalance;
if( eExtra==0 || eExtra==e_VerifyInsufficient){
bool bConfirmed = true;
if( nCost>0 ){
TPayMentForm *payMentForm = new TPayMentForm(NULL, iOperation, nIdCount, aIdStyle,
arrCost, nCost, nUserBalance);
if( mrYes!=payMentForm->ShowModal() ){
bConfirmed = false;
}
delete payMentForm;
}
if( bConfirmed ){
TProgressForm * dlgProgress = new TProgressForm(NULL);
int ret = dlgProgress->User_ConfirmPayment( iOperation, nIdCount, aIdStyle,
&nUserBalance );
int eExtra = dlgProgress->GetOpertaionResult();
delete dlgProgress;
if( ret==mrOk ){
if( eExtra==0 ){
bPaid = true;
g_infoUser.accountInfo.balance = nUserBalance;
bool bTip = false;
for( int i=0; i<nIdCount; i++ ){
if( arrCost[i]>0 ){
bTip = true;
break;
}
}
if( bTip ){
g_bProjStylePaid = true;
String msg = "风格支付成功!\n\n为避免重复支付,请记住保存工程。";
MessageForm->ShowMessage( msg, MB_ICONINFORMATION|MB_OK );
}
}
else{
ShowErrorMessage( eExtra, L"支付失败!" );
}
}
}
}
else if( eExtra==e_InvalidStyleID ){ //风格失效,待进一步提示
ShowErrorMessage( eExtra, L"鉴权失败!" );
}
else{
ShowErrorMessage( eExtra, L"鉴权失败!" );
}
}
}
Update();
return bPaid;
}
//---------------------------------------------------------------------------
*/
void TMainForm::ShowErrorMessage( int errcode, String strOperation )
{
String msg = strOperation + L"\n";
if( errcode==e_InvalidUserID ){
msg += L"无效的用户。";
}
else if( errcode==e_InvalidStyleID ){
msg += L"所选的风格之一已失效。";
}
else if( errcode==e_VerifyInsufficient ){
msg += L"唱作音符余额不足,请登录网站获取。";
}
else if( errcode==e_DatabaseError ){
msg += L"数据库访问失败,请稍后重试。";
}
else if( errcode==e_ServiceBusy ){
msg += L"服务器忙,请稍后重试。";
}
else if( errcode==e_SocketError ){
msg += L"网络故障,请关闭程序后重试。";
}
else if( errcode==e_WaitTimeout ){
msg += L"网络超时,请稍后重试。";
}
else if( errcode==e_LoginPasswordError ){
msg += L"输入密码错,请重新输入。";
}
else if( errcode==e_LoginUserNotExist ){
msg += L"无效的用户名,请重新输入。";
}
else if( errcode==e_UsernameExist ){
msg += L"用户名已存在,请重新注册。";
}
else if( errcode==e_UserLocked ){
msg += L"该账户被冻结,请重新注册。";
}
else if( errcode==e_UserDeleted ){
msg += L"该账户已被删除,请重新注册。";
}
else if( errcode==e_OpenFileFailed ){
msg += L"文件操作错误。";
}
else if( errcode==e_InvalidDataID
|| errcode==e_InvalidPackID
|| errcode==e_InvalidData ){
msg += L"文件传输失败。";
}
else if( errcode==e_VipExceeded ){
msg += L"账号登录设备数已达上限,请稍后再试。";
}
else{
msg += L"未知原因。";
}
MessageForm->ShowMessage( msg, MB_ICONERROR|MB_OK );
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::OnMicSetting(TMessage & Msg)
{
OnIOSetting();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::OnOpenAutoProj(TMessage & Msg) //add by tj 2013/12/31
{
GetAutoSaveReg();
if( !FileExists(g_strAutoProjName.c_str()) )
return;
String strMsg = L"将恢复上次未保存的工程。\n是否恢复工程?";
MessageForm->m_btnYes->Hint = L"恢复工程";
MessageForm->m_btnNo->Hint = L"放弃恢复工程";
int mrRet = MessageForm->ShowMessage( strMsg, MB_ICONQUESTION|MB_YESNO );
MessageForm->m_btnYes->Hint = "";
MessageForm->m_btnNo->Hint = "";
if( mrRet==mrYes ) {
mrRet = ::LoadProject(g_strAutoProjName.c_str(), NULL);
SetInitVar();
if (mrRet) {
DebugPrint("open auto Save project....");
//add upload by tj 2004/03/26
memset( &g_infoSong, 0, sizeof(TSONGINFO) );
g_infoSong.size = sizeof(TSONGINFO);
memset( g_infoSong.iMusicStyle, -1, 4 );
g_infoSong.iSubmit = 1;
if( g_strProjectName.length()!=0 ) {
String strName = g_strProjectName.c_str();
AnsiString strTitle = TPath::GetFileNameWithoutExtension( strName );
strcpy( g_infoSong.strSongName, strTitle.c_str() );
}
if (!SetSelectFont()) {
String strMsg;
strMsg = g_strProjError[E_PROJ_INVALIDFONT - E_PROJ_NOERROR - 1];
MessageForm->ShowMessage(strMsg, MB_ICONINFORMATION | MB_OK);
}
SetInitVar();
if( g_strProjectName.length()==0 )
m_labCaption->Caption = String(APPNAME) + L" - Untitle";
else{
String strName = g_strProjectName.c_str();
m_labCaption->Caption = String(APPNAME) + L" - " +
TPath::GetFileNameWithoutExtension( strName );
}
m_pSysMenu->EnabledMenuItem(MENU_SAVE, true);
m_pSysMenu->EnabledMenuItem(MENU_SAVEAS, true);
int iActivePage = m_pPgCtrl_Work->ActivePageIndex;
if (g_iCurrentPage >= 0) {
iActivePage = g_iCurrentPage;
}
if (g_lstMelodyBars.size() == 0 && iActivePage > 1) {
iActivePage = 1;
}
else if (g_lstMelodyStages.size() == 0 && iActivePage > 2) {
iActivePage = 2;
}
if( g_lstMelodyStages.size()>0 && !g_bBaseComposeLoaded ){
ReloadBaseCompose();
}
for( int i = 0; i < 5; i++ ){
if( g_lstMelodyBars.empty() && i>1 ){
m_btnStep[i]->Enabled = false;
}
else{
m_btnStep[i]->Enabled = true;
}
}
PostMessage(Handle, UM_JUMP_PAGE, WPARAM(iActivePage),LPARAM(0));
}
else {
DebugPrint("open auto Save project invalidate....");
String strErr = L"恢复工程无效";
MessageForm->ShowMessage(strErr, MB_ICONERROR | MB_OK);
NewProject();
}
Update();
}
else{
g_strProjectName.clear();
}
g_bAutoSave = false;
SetAutoSaveReg();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::UMNotification(TMessage & Msg)
{
if( !m_pNotificationGetTimer )
return;
static bool bAutoShowHappened = false;
static bool bMenuShowHappened = false;
if( Msg.WParam == NOTIFICATION_SHOW_CLOSED ){
bAutoShowHappened = true;
m_pNotificationGetTimer->Enabled = false;
if( m_pNotificationForm ) {
delete m_pNotificationForm;
m_pNotificationForm = NULL;
}
}else if( Msg.WParam == NOTIFICATION_NO_JSONDATA ){
if( m_pNotificationForm ) {
delete m_pNotificationForm;
m_pNotificationForm = NULL;
}
if( !bAutoShowHappened ) {
m_pNotificationGetTimer->Enabled = true;
}
if( bMenuShowHappened ) {
bMenuShowHappened = false;
MessageForm->ShowMessage("暂不能获取唱作网动态,请稍后再试!", MB_ICONERROR | MB_OK);
}
}else if( Msg.WParam == NOTIFICATION_MENU_JSONDATA ){
m_pNotificationGetTimer->Enabled = false;
if( m_pNotificationForm== NULL) {
NotificationTimerProc(m_pNotificationGetTimer);
bMenuShowHappened = true;
}
}else if( Msg.WParam == NOTIFICATION_SHOW_FORM ){
if( m_pNotificationForm ){
m_pNotificationForm->setPANEL();
m_pNotificationForm->Show();
}
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::NotificationTimerProc(TObject* Sender)
{
TTimer *notiTimer = (TTimer *)Sender;
if( notiTimer == m_pNotificationGetTimer ) {
m_pNotificationGetTimer->Enabled = false;
if( m_pNotificationForm == NULL ) {
m_pNotificationForm = new TNotificationForm(this);
}
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::OnNotification(TObject *Sender)
{
PostMessage(Handle, UM_NOTIFICATION,
NOTIFICATION_MENU_JSONDATA, 0 );
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::OnCustomerSetting(TObject *Sender)
{
TCustomerSettingForm *csForm = new TCustomerSettingForm(NULL);
if( mrYes == csForm->ShowModal() ){
g_bAutoOpenProject = csForm->m_pCSPanel->m_bAutoOpenProject;
g_bAutoDownloadStyle = csForm->m_pCSPanel->m_bDownloadStyle;
f_CS_AutoDownloadStyle(g_bAutoDownloadStyle);
if( g_iShowType != csForm->m_pCSPanel->m_bAlphaKey ){
if( m_pPgCtrl_Work->ActivePageIndex==2 ){
BaseForm->ChangeChordMode( csForm->m_pCSPanel->m_bAlphaKey );
}
else if( m_pPgCtrl_Work->ActivePageIndex==3 ){
ComposeForm->ChangeChordMode( csForm->m_pCSPanel->m_bAlphaKey );
}
else{
g_iShowType = csForm->m_pCSPanel->m_bAlphaKey;
}
}
// ((TChordPanel*)m_pChordPanel)->SetKeyMode( csForm->m_pCSPanel->m_bAlphaKey );
g_iPreStageDefault = csForm->m_pCSPanel->m_cPreStage;
g_iPreStyleSort = csForm->m_pCSPanel->m_iPreStyleSort;
g_bPrebeat = csForm->m_pCSPanel->m_bPreBeat;
}
delete csForm;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::OnIOSetting(TObject *Sender)
{
TForm * pForm = (TForm*)m_paTabSheets[m_pPgCtrl_Work->ActivePageIndex]->Controls[0];
pForm->OnDeactivate(NULL);
TMicSetForm * pDlg = new TMicSetForm(NULL);
if( pDlg->ShowModal()==mrOk ){
TForm* pActiveForm = NULL;
if( m_pPgCtrl_Work->ActivePageIndex==1 )
pActiveForm = RecordForm;
else if( m_pPgCtrl_Work->ActivePageIndex==4 )
pActiveForm = CompleteForm;
if( pActiveForm ){
pActiveForm->Perform( MSG_RECORD_VOLJUST, (WPARAM)((g_fRecordVolume+0.005)*100), 0 );
}
}
delete pDlg;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::UserIconClick(TObject *Sender)
{
// String strHeaderPath = g_strUserPath.c_str();
// strHeaderPath += L"header\\";
//
// String strIconFile = strHeaderPath + g_infoUser.strIconFile;
//
// if( !FileExists( strIconFile ) )
// strIconFile = strHeaderPath + L"default.jpg";
//
// GetPic(strIconFile, true);
// TPicture *pPic = new TPicture();
// pPic->LoadFromFile( strIconFile );
//
// TImgCopperForm *pTImgCopperForm = new TImgCopperForm(this, TRect(0, 0, 90, 90), pPic);
// pTImgCopperForm->Caption = L"编辑头像";
//
// pTImgCopperForm->Width = 260;
// pTImgCopperForm->Height = 300;
//
// if( mrOk==pTImgCopperForm->ShowModal() ) {
//
// bool bUploadUsrIcon = false;
// if( NULL==g_pTThreadHttpPostUsrIcon ) {
//
// bUploadUsrIcon = true;
//
// }else if( !g_pTThreadHttpPostUsrIcon->Started ||
// (g_pTThreadHttpPostUsrIcon->Started && g_pTThreadHttpPostUsrIcon->Finished) )
// {
// bUploadUsrIcon = true;
// }
//
// if( bUploadUsrIcon ){
//
// m_strUsrIconPath = pTImgCopperForm->m_strCopperPath;
//
// SAFE_DELETE(g_pTThreadHttpPostUsrIcon)
// g_pTThreadHttpPostUsrIcon
// = new TThreadHttpPostUsrIcon(true, this,
// pTImgCopperForm->m_strCopperPath);
// g_pTThreadHttpPostUsrIcon->Priority = tpIdle;
// g_pTThreadHttpPostUsrIcon->Start();
// }
// }
//
// SAFE_DELETE(pTImgCopperForm);
// SAFE_DELETE(pPic);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::OnUploadUsrIcon(TMessage & Msg)
{
String strFileName = g_pTThreadHttpPostUsrIcon->m_strFileName;
if( strFileName.Length() ) {
String strHeaderPath = g_strUserPath.c_str();
strHeaderPath += L"header\\";
strHeaderPath += strFileName;
if( strFileName.Length() ) {
TPicture *userICon = new TPicture();
userICon->LoadFromFile(m_strUsrIconPath);
m_imgUserIcon->Picture = userICon;
SAFE_DELETE(userICon);
CopyFile(m_strUsrIconPath.c_str(), strHeaderPath.c_str(), true);
DeleteFile(m_strUsrIconPath);
strcpy(g_infoUser.strIconFile, wstr2str(strFileName.c_str()).c_str());
}
}
SAFE_DELETE(g_pTThreadHttpPostUsrIcon)
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::VipClick(TObject *Sender)
{
char strURL[256];
f_CS_GetWebPageURL( URL_VIPMEMBER, strURL );
String urlVIP = strURL;
if( urlVIP.Length() ) {
ShellExecute(Handle, NULL, urlVIP.c_str(), NULL, NULL, SW_SHOWNORMAL);
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FontChangeMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
{
if( Button==mbLeft && Shift.Contains(ssLeft) ){
if( !m_lbFontSelect->Visible ){
m_btnFontChange->Down = true;
TForm * pForm = (TForm*)m_paTabSheets[m_pPgCtrl_Work->ActivePageIndex]->Controls[0];
pForm->Perform( UM_HIDEPOPCONTROL, 0, 0 );
m_lbFontSelect->Show();
m_lbFontSelect->SetFocus();
}
else{
m_btnFontChange->Down = false;
m_lbFontSelect->Hide();
}
}
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::FontSelectMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
{
if( X>=0 && X < m_lbFontSelect->Width && Y>=0 && Y<m_lbFontSelect->Height ){
int iSel = m_lbFontSelect->ItemIndex;
if( iSel>=0 ){
if( iSel!=g_idFont && f_MM_SetFont( g_lstFonts[iSel]->strFileName )==S_OK ){
g_idFont = iSel;
g_strFontFile = ExtractFileName(g_lstFonts[iSel]->strFileName).c_str();
m_lblFontName->Caption = g_lstFonts[iSel]->strFontName;
g_strMP3File = "";
}
else{
m_lbFontSelect->ItemIndex = g_idFont;
}
}
}
m_btnFontChange->Down = false;
m_lbFontSelect->Hide();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::DownloadExtFontClick(TObject *Sender)
{
char strURL[256];
if( m_lblExtFont->Tag==0 )
f_CS_GetWebPageURL( URL_EXTFONT, strURL );
else
strcpy( strURL, "http://www.iChangzuo.com" );
ShellExecute(Handle, NULL, ((String)strURL).c_str(), NULL, NULL, SW_SHOWNORMAL);
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ExtFontMouseEnter(TObject *Sender)
{
m_lblExtFont->Font->Color = clHotLight;
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ExtFontMouseLeave(TObject *Sender)
{
m_lblExtFont->Font->Color = clBlue;
}
//---------------------------------------------------------------------------