advancedlg.cpp

来自「Visual C++编写的虚拟环绕声系统」· C++ 代码 · 共 2,022 行 · 第 1/5 页

CPP
2,022
字号
			ID_MICWND_STATIC
			);

		// 绘制 MIC 窗口中的说明
		CRect MICIntroduceRect;
		MICIntroduceRect.left  =MICWndRect.left  +MICWndRect.Width()/6;
		MICIntroduceRect.top   =MICWndRect.top   +MICWndRect.Height()/6;
		MICIntroduceRect.right =MICWndRect.right -MICWndRect.Width()/6;;
		MICIntroduceRect.bottom=MICWndRect.bottom-MICWndRect.Height()/2;
		MICIntroduceStatic.Create
			(
			" Welcome To Use The MicroPhone(MIC) Controller",
			WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_PUSHBUTTON|BS_ICON,
			MICIntroduceRect,
			this,
			ID_MICINTRODUCE_STATIC
			);

		// 绘制 MIC 窗口中的 PLAY 按钮
		MICIntroduceRect.left  =MICWndRect.left  +MICWndRect.Width()/3;
		MICIntroduceRect.top   =MICWndRect.top   +MICWndRect.Height()/2;
		MICIntroduceRect.right =MICWndRect.left  +MICWndRect.Width()/2;
		MICIntroduceRect.bottom=MICWndRect.bottom-MICWndRect.Height()/4;
		MICPlay.Create
			(
			"Play",
			WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_PUSHBUTTON|BS_ICON,
			MICIntroduceRect,
			this,
			ID_MICPLAY_BUTTON
			);
		((CButton*)GetDlgItem(ID_MICPLAY_BUTTON))->SetIcon(AfxGetApp()->LoadIcon(IDI_PLAY_ICON));

		// 绘制 MIC 窗口中的 STOP 按钮
		MICIntroduceRect.left  =MICIntroduceRect.right;
		MICIntroduceRect.right =MICIntroduceRect.left+MICWndRect.Width()/6;
		MICStop.Create
			(
			"Stop",
			WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_PUSHBUTTON|BS_ICON,
			MICIntroduceRect,
			this,
			ID_MICSTOP_BUTTON
			);
		((CButton*)GetDlgItem(ID_MICSTOP_BUTTON))->SetIcon(AfxGetApp()->LoadIcon(IDI_STOP_ICON));


		// 为 MIC 申请工作缓冲区
		for (i=0;i<DataBufferNumber;i++)
		{
			MICDataHDR[i]=(LPWAVEHDR)GlobalAllocPtr(GMEM_MOVEABLE|GMEM_SHARE,sizeof(WAVEHDR));
			MICDataHDR[i]->lpData=(LPSTR)GlobalAllocPtr(GMEM_MOVEABLE|GMEM_SHARE,DataBufferSize);
			MICDataHDR[i]->dwBufferLength=DataBufferSize;
			MICDataHDR[i]->dwBytesRecorded=0L;
			MICDataHDR[i]->dwFlags=0L;
			MICDataHDR[i]->dwLoops=0L;
		}    

		// 设置状态为 WORKSTATE_MIC
		WorkState=WORKSTATE_MIC;
		
		// 画 MIC 初始界面的一幅画
		CDC pDisplayMemDC;
		CClientDC dc(this);
		pBitmap.DeleteObject(); // 清除以前加载的位图
		pBitmap.LoadBitmap(IDB_MICBEGIN_BITMAP); // 加载新的位图
		pDisplayMemDC.CreateCompatibleDC(&dc);
		pDisplayMemDC.SelectObject(&pBitmap);
		dc.BitBlt(15,10,100,90,&pDisplayMemDC,0,0,SRCCOPY);
		RedrawMyself=TRUE;

		// 声卡混音器控制
		HMIXER hMixer;
		MIXERCONTROLDETAILS_BOOLEAN     MyMixerControlDetails_f[20];
		MIXERCONTROLDETAILS_UNSIGNED    MyMixerControlDetails_u[2];
		UINT mmr;
		// 打开 Mixer
		mmr=mixerOpen
			(
			&hMixer,
			0L,
			(DWORD)m_hWnd,
			0L,
			CALLBACK_WINDOW
			);
		if (MMSYSERR_NOERROR != mmr)
		{
			MessageBox
				(
				" Unable TO Open The Mixer. mixerOpen() Failed!",
				NULL,
				MB_OK|MB_ICONEXCLAMATION
				);
		}
		// 使CD的音量静音///////恢复原有状态
		MyMixerControlDetails_f[0].fValue = 1;
		CDVolumeMuteControlDetails.paDetails=MyMixerControlDetails_f;
//		CDVolumeMuteControlDetails.paDetails=&CDVolumeMuteOldState;
		mmr = mixerSetControlDetails
			(
			(HMIXEROBJ)hMixer,
			&CDVolumeMuteControlDetails,
			MIXER_SETCONTROLDETAILSF_VALUE
			);
		if (MMSYSERR_NOERROR != mmr)
		{
			MessageBox
				(
				" Unable To Set The Mixer.\n mixerSetControlDetails() Failed\n Program May Be Abnormal!!",
				NULL,
				MB_OK|MB_ICONEXCLAMATION
				);
		}
		// 使Line的音量静音////////恢复原有状态
		MyMixerControlDetails_f[0].fValue = 1;
		LineVolumeMuteControlDetails.paDetails=MyMixerControlDetails_f;
//		LineVolumeMuteControlDetails.paDetails=&LineVolumeMuteOldState;
		mmr = mixerSetControlDetails
			(
			(HMIXEROBJ)hMixer,
			&LineVolumeMuteControlDetails,
			MIXER_SETCONTROLDETAILSF_VALUE
			);
		if (MMSYSERR_NOERROR != mmr)
		{
			MessageBox
				(
				" Unable To Set The Mixer.\n mixerSetControlDetails() Failed\n Program May Be Abnormal!!",
				NULL,
				MB_OK|MB_ICONEXCLAMATION
				);
		}
		// 使MIC的音量静音
		MyMixerControlDetails_f[0].fValue = 1;
		MICVolumeMuteControlDetails.paDetails=MyMixerControlDetails_f;
		mmr = mixerSetControlDetails
			(
			(HMIXEROBJ)hMixer, 
			&MICVolumeMuteControlDetails, 
			MIXER_SETCONTROLDETAILSF_VALUE
			);
		if (MMSYSERR_NOERROR != mmr)
		{
			MessageBox
				(
				" Unable To Set The Mixer.\n mixerSetControlDetails() Failed\n Program May Be Abnormal!!",
				NULL,
				MB_OK|MB_ICONEXCLAMATION
				);
		}
		// 设置MIC为录音声源
		for (i=0;i<20;i++)
			MyMixerControlDetails_f[i].fValue=0;
		MyMixerControlDetails_f[MICRecordItemID].fValue=1;
		RecordControlDetails.paDetails=MyMixerControlDetails_f;
		mmr = mixerSetControlDetails
			(
			(HMIXEROBJ)hMixer, 
			&RecordControlDetails,
			MIXER_SETCONTROLDETAILSF_VALUE 
			);
		if (MMSYSERR_NOERROR != mmr)
		{
			MessageBox
				(
				" Unable To Set The Mixer.\n mixerSetControlDetails() Failed\n Program May Be Abnormal!!",
				NULL,
				MB_OK|MB_ICONEXCLAMATION
				);
		}
		// 恢复CD录音的原有音量
		CDRecordVolumeControlDetails.paDetails=CDRecordVolumeOldState;
		mmr = mixerSetControlDetails
			(
			(HMIXEROBJ)hMixer,
			&CDRecordVolumeControlDetails, 
			MIXER_SETCONTROLDETAILSF_VALUE
			);
		if (MMSYSERR_NOERROR != mmr)
		{
			MessageBox
				(
				" Unable To Set The Mixer.\n mixerSetControlDetails() Failed\n Program May Be Abnormal!!",
				NULL,
				MB_OK|MB_ICONEXCLAMATION
				);
		}
		// 恢复Line录音的原有音量
		LineRecordVolumeControlDetails.paDetails=LineRecordVolumeOldState;
		mmr = mixerSetControlDetails((HMIXEROBJ)hMixer, &LineRecordVolumeControlDetails, MIXER_SETCONTROLDETAILSF_VALUE );
		if (MMSYSERR_NOERROR != mmr)
		{
			MessageBox
				(
				" Unable To Set The Mixer.\n mixerSetControlDetails() Failed\n Program May Be Abnormal!!",
				NULL,
				MB_OK|MB_ICONEXCLAMATION
				);
		}
		// 设置MIC录音音量为0
		MyMixerControlDetails_u[0].dwValue=10000;
		MyMixerControlDetails_u[1].dwValue=10000;
		MICRecordVolumeControlDetails.paDetails=MyMixerControlDetails_u;
		mmr = mixerSetControlDetails((HMIXEROBJ)hMixer, &MICRecordVolumeControlDetails, MIXER_SETCONTROLDETAILSF_VALUE );
		if (MMSYSERR_NOERROR != mmr)
		{
			MessageBox
				(
				" Unable To Set The Mixer.\n mixerSetControlDetails() Failed\n Program May Be Abnormal!!",
				NULL,
				MB_OK|MB_ICONEXCLAMATION
				);
		}
		// 关闭Mixer
		mixerClose(hMixer);

	}

	/////////////
	// MY CODE ENDS HERE
	/////////////
	
}

void CAdvanceDlg::OnLineRadio() 
{
	// TODO: Add your control notification handler code here

	/////////////
	// MY CODE STARTS HERE
	/////////////

	int i;
	
	// 如果没有处于 WORKSTATE_LINE 状态,则重新绘制控制面板
	if (WorkState!=WORKSTATE_LINE)
	{
		CRect LineWndRect;

		// 如果处于 WORKSTATE_INTRODUCE 状态,取得窗口大小后,
		// 删除 INTRODUCE 窗口
		if (WorkState==WORKSTATE_INTRODUCE)
		{
			CWnd* IntroduceWndPointer;
			IntroduceWndPointer=GetDlgItem(IDC_INTRODUCE_STATIC);
			IntroduceWndPointer->GetWindowRect(&LineWndRect);
			IntroduceWndPointer->DestroyWindow();
			GetDlgItem(IDC_BEGIN_STATIC)->DestroyWindow();
		}

		// 如果处于 WORKSTATE_MIC 状态,取得窗口大小后,
		// 删除 MIC 窗口
		if (WorkState==WORKSTATE_MIC)
		{
			CWnd* MICWndPointer;
			MICWndPointer=GetDlgItem(ID_MICWND_STATIC);
			MICWndPointer->GetWindowRect(&LineWndRect);
			MICWndPointer->DestroyWindow();
			GetDlgItem(ID_MICINTRODUCE_STATIC)->DestroyWindow();
			GetDlgItem(ID_MICPLAY_BUTTON)->DestroyWindow();
			GetDlgItem(ID_MICSTOP_BUTTON)->DestroyWindow();

			// 释放 MIC 的工作缓冲区
			for (i=0;i<DataBufferNumber;i++)
			{
				if ((MICDataHDR[i]->lpData)!=NULL)
				{
					GlobalUnlock(MICDataHDR[i]->lpData);
					GlobalFree(MICDataHDR[i]->lpData);
				}
				waveInReset(hWaveIn);
				waveInClose(hWaveIn);
				waveOutReset(hWaveOut);
				waveOutClose(hWaveOut);
			}
		}

		// 如果处于 WORKSTATE_WAV 状态,取得窗口大小后,
		// 删除 WAV 窗口以及 WAV 窗口内的所有控件
		if (WorkState==WORKSTATE_WAV)
		{
			CWnd* WAVWndPointer;
			WAVWndPointer=GetDlgItem(ID_WAVWND_STATIC);
			WAVWndPointer->GetWindowRect(&LineWndRect);
			WAVWndPointer->DestroyWindow();

			GetDlgItem(ID_WAVPLAY_BUTTON)->DestroyWindow();
			GetDlgItem(ID_WAVSTOP_BUTTON)->DestroyWindow();
			GetDlgItem(ID_WAVPAUSE_BUTTON)->DestroyWindow();
			GetDlgItem(ID_WAVLIST_BUTTON)->DestroyWindow();
			GetDlgItem(ID_WAVFILENAME_STATIC)->DestroyWindow();
			GetDlgItem(ID_WAVFILENAMECOUNTER_STATIC)->DestroyWindow();

			// 释放 WAV, WAVDelayData, TempData 的工作缓冲区
			for (i=0;i<DataBufferNumber;i++)
			{
				if ((WAVDataHDR[i]->lpData)!=NULL)
				{
					GlobalUnlock(WAVDataHDR[i]->lpData);
					GlobalFree(WAVDataHDR[i]->lpData);
				}
				waveOutReset(hWaveOut);
				waveOutClose(hWaveOut);
			}
			if ((WAVDelayData->lpData)!=NULL) GlobalFreePtr(WAVDelayData);
			if ((TempData->lpData)!=NULL) GlobalFreePtr(TempData);
		}

		// 如果处于 WORKSTATE_CD 状态,取得窗口大小后,
		// 删除 CD 窗口以及 CD 窗口内的所有控件
		if (WorkState==WORKSTATE_CD)
		{
			CWnd* CDWndPointer;
			CDWndPointer=GetDlgItem(ID_CDWND_STATIC);
			CDWndPointer->GetWindowRect(&LineWndRect);
			CDWndPointer->DestroyWindow();

			GetDlgItem(ID_CDPLAY_BUTTON)->DestroyWindow();
			GetDlgItem(ID_CDSTOP_BUTTON)->DestroyWindow();
			GetDlgItem(ID_CDPAUSE_BUTTON)->DestroyWindow();
			GetDlgItem(ID_CDPRIE_BUTTON)->DestroyWindow();
			GetDlgItem(ID_CDNEXT_BUTTON)->DestroyWindow();
			GetDlgItem(ID_CDTRACK1_BUTTON)->DestroyWindow();
			GetDlgItem(ID_CDTRACK2_BUTTON)->DestroyWindow();
			GetDlgItem(ID_CDTRACK3_BUTTON)->DestroyWindow();
			GetDlgItem(ID_CDTRACK4_BUTTON)->DestroyWindow();
			GetDlgItem(ID_CDTRACK5_BUTTON)->DestroyWindow();
			GetDlgItem(ID_CDTRACK6_BUTTON)->DestroyWindow();
			GetDlgItem(ID_CDTRACK7_BUTTON)->DestroyWindow();
			GetDlgItem(ID_CDTRACK8_BUTTON)->DestroyWindow();
			GetDlgItem(ID_CDTRACK9_BUTTON)->DestroyWindow();
			GetDlgItem(ID_CDTRACK10_BUTTON)->DestroyWindow();
			GetDlgItem(ID_CDTRACK11_BUTTON)->DestroyWindow();
			GetDlgItem(ID_CDTRACK12_BUTTON)->DestroyWindow();
			GetDlgItem(ID_CDTRACK13_BUTTON)->DestroyWindow();
			GetDlgItem(ID_CDTRACK14_BUTTON)->DestroyWindow();
			GetDlgItem(ID_CDTRACK15_BUTTON)->DestroyWindow();
			GetDlgItem(ID_CDTRACK_STATIC)->DestroyWindow();
			GetDlgItem(ID_CDMINUTE_STATIC)->DestroyWindow();
			GetDlgItem(ID_CDSECOND_STATIC)->DestroyWindow();
			GetDlgItem(ID_CDTRACKCOUNTER_STATIC)->DestroyWindow();
			GetDlgItem(ID_CDMINUTECOUNTER_STATIC)->DestroyWindow();
			GetDlgItem(ID_CDSECONDCOUNTER_STATIC)->DestroyWindow();

			// 释放 CD 的工作缓冲区
			for (i=0;i<DataBufferNumber;i++)
			{
				if ((CDDataHDR[i]->lpData)!=NULL)
				{
					GlobalUnlock(CDDataHDR[i]->lpData);
					GlobalFree(CDDataHDR[i]->lpData);
				}
				waveInReset(hWaveIn);
				waveInClose(hWaveIn);
				waveOutReset(hWaveOut);
				waveOutClose(hWaveOut);
			}
		}

		// 绘制 LINE 窗口
		ScreenToClient(LineWndRect);
		LineWnd.Create
			("Line",
			WS_CHILD|WS_VISIBLE|BS_GROUPBOX,
			LineWndRect,
			this,
			ID_LINEWND_STATIC
			);

		// 绘制 LINE 窗口中的说明
		CRect LineIntroduceRect;
		LineIntroduceRect.left  =LineWndRect.left  +LineWndRect.Width()/6;
		LineIntroduceRect.top   =LineWndRect.top   +LineWndRect.Height()/6;
		LineIntroduceRect.right =LineWndRect.right -LineWndRect.Width()/6;;
		LineIntroduceRect.bottom=LineWndRect.bottom-LineWndRect.Height()/2;
		LineIntroduceStatic.Create
			(
			"  Welcome Use The LineIn(Line) Controller",
			WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_PUSHBUTTON|BS_ICON,
			LineIntroduceRect,
			this,
			ID_LINEINTRODUCE_STATIC
			);

		// 绘制 MIC 窗口中的 PLAY 按钮
		LineIntroduceRect.left  =LineWndRect.left  +LineWndRect.Width()/3;
		LineIntroduceRect.top   =LineWndRect.top   +LineWndRect.Height()/2;
		LineIntroduceRect.right =LineWndRect.left  +LineWndRect.Width()/2;
		LineIntroduceRect.bottom=LineWndRect.bottom-LineWndRect.Height()/4;
		LinePlay.Create
			(
			"Play",
			WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_PUSHBUTTON|BS_ICON,
			LineIntroduceRect,
			this,
			ID_LINEPLAY_BUTTON
			);
		((CButton*)GetDlgItem(ID_LINEPLAY_BUTTON))->SetIcon(AfxGetApp()->LoadIcon(IDI_PLAY_ICON));

		// 绘制 CD 窗口中的 STOP 按钮
		LineIntroduceRect.left  =LineIntroduceRect.right;
		

⌨️ 快捷键说明

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