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

📄 vbvoice.cpp

📁 eVB 呼叫由eVC 所撰寫的DLL檔案達到使用程式來控制錄放音的要求
💻 CPP
字号:
/*---------------------------------------------------------------------------
   THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
   ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED
   TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
   PARTICULAR PURPOSE

   Copyright (C) 2000. Microsoft Corporation. All rights reserved.

   vbvoice.cpp
   
----------------------------------------------------------------------------*/


// vbvoice.cpp : Defines the entry point for the DLL application.
//



// custom visual basic interface to the voice control (voicectl.dll)
// libray.  This library wraps most of the functionality of the
// voice control and modifies the behavior to not allow WM_ACTIVATE
// stop the control.  Because it's a simple DLL notifications are
// not passed back to the VB caller.

// About WM_ACTIVATE.  The voicectl.dll was designed to be used
// as a one-shot record or playback of a file.  If the use takes
// activation of the window of this control, it will automatically
// close itself.  This message is overridden so that the user will 
// have control over when the the voice control will go away.

/////////////////
// Usage
// Create the control in the Form_Load or at some command before
// calling any other functions.
// Follow the documentation on using VoiceRecord_Create regarding
// filenames and playmode.
//
// To specify a different file to record, use vbVoiceSetFile.  Then
// vbVoiceRec will record onto a different file.
//
// If you so desire to create the control hidden, specify an X and Y
// coordinate off the form.  Create command buttons to call vbVoicePlay
// vbVoiceRec, and vbVoiceStop.
//
// After calling vbVoiceOk, vbCreateVoiceControl must be
// called again before using the other functions.


#include <windows.h>
#include <voicectl.h>

#define VRS_HIDDEN 0x0080

/// GLOBALS
//// for the voice control
static HWND g_hwndVoice;
static WNDPROC OriginalVoiceProc;

// current location, flags, and wave file.
int g_nXPos;
int g_nYPos;
int g_dwFlags;
TCHAR g_szFileName[MAX_PATH];


#define ID_VOICECTL 101
static BOOL CALLBACK MyVoiceProc (HWND hwnd, UINT msg, UINT wParam, LONG lParam);
static HWND CreateVoiceControl (HWND hwndParent, int CmdShow);




BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{
    return TRUE;
}



//////////////////////////////////////////////////////////////////////////////
// Exposed Interface functions
//////////////////////////////////////////////////////////////////////////////

BOOL APIENTRY vbCreateVoiceControl(
	HWND hWndParent,
    DWORD dwFlags,
	int x,
	int y,
	LPTSTR szFileName)
{
	// check parms
	if (szFileName == NULL)
		if (dwFlags & VRS_PLAY_MODE)
			return FALSE;

    // set "properties"
	g_nXPos = x;
	g_nYPos = y;
	g_dwFlags = dwFlags;
	lstrcpy(g_szFileName, szFileName);

	if (dwFlags & VRS_HIDDEN)
		g_hwndVoice = CreateVoiceControl(hWndParent, SW_HIDE);
	else
		g_hwndVoice = CreateVoiceControl(hWndParent, SW_SHOW);


	return TRUE;
}

BOOL APIENTRY vbVoicePlay(void)
{
	if (g_hwndVoice == NULL)
		return FALSE;


	SendMessage (g_hwndVoice, VRM_PLAY, NULL, NULL);
	return TRUE;
}

BOOL APIENTRY vbVoiceRec(void)
{
	if (g_hwndVoice == NULL)
		return FALSE;


	SendMessage (g_hwndVoice, VRM_RECORD, NULL, NULL);
	return TRUE;
}

BOOL APIENTRY vbVoiceStop(void)
{
	if (g_hwndVoice == NULL)
		return FALSE;

	SendMessage (g_hwndVoice, VRM_STOP, NULL, NULL);
	return TRUE;
}

// the OK function will close the voice control
// OK will save the datafile and close
// Note that VRM_CANCEL does not seem to work

BOOL APIENTRY vbVoiceOk(void)
{
	if (g_hwndVoice == NULL)
		return FALSE;

	SendMessage (g_hwndVoice, VRM_OK, NULL, NULL);

	g_hwndVoice = NULL;
	OriginalVoiceProc = NULL;

	return TRUE;

}



//////////////////////////////////////////////////////////////////////////////
// Helper functions to create and manage the voice control
//////////////////////////////////////////////////////////////////////////////

/*****************************************************************************

  CreateVoiceControl

  ***************************************************************************/

HWND CreateVoiceControl (HWND hwndParent, int CmdShow)
{
	HWND hwnd;

	CM_VOICE_RECORDER cmvr;
	memset( &(cmvr), 0, sizeof(cmvr));
	cmvr.cb = sizeof (CM_VOICE_RECORDER);
	cmvr.dwStyle = g_dwFlags | VRS_NO_OKCANCEL | VRS_NO_NOTIFY; 
	cmvr.xPos = g_nXPos;
	cmvr.yPos = g_nYPos;
	cmvr.hwndParent = hwndParent;
	cmvr.id = ID_VOICECTL;
	cmvr.lpszRecordFileName = g_szFileName;

	hwnd = VoiceRecorder_Create (&cmvr);

	
/// modify the control's wndproc to override WM_ACTIVATE
	OriginalVoiceProc = (WNDPROC)SetWindowLong(hwnd, DWL_DLGPROC, (LONG)MyVoiceProc);

	ShowWindow(hwnd, CmdShow );
	UpdateWindow(hwnd);
	
	return hwnd;
}


BOOL CALLBACK MyVoiceProc (HWND hwnd, UINT msg, UINT wParam, LONG lParam)
{

	if (msg == WM_ACTIVATE)
		return TRUE;
	else
		return CallWindowProc(OriginalVoiceProc, hwnd, msg, wParam, lParam);

}

⌨️ 快捷键说明

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