|
I want to create a new view that is able to scroll
in my MDI application whose base view class is CView.
I tired to create a new class from the Scroll view
and by using the create function i created the view
on a DialogBox .
After making some changes everthing is fine .
but when i click the scroll bars then i get error,on debugging
the viewcore.cpp is opend and in
int CView::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message)
{.....}
probable the problem is due to the New view is a child to main ?
How do i avoid that ? or is there any other solution
for this.
Thanks
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
vikas amin wrote:
i created the view
on a DialogBox .
That might be you problem right there. Views (any window derived from CView ) is meant to be used in a CFrameWnd window.
vikas amin wrote:
when i click the scroll bars then i get error,on debugging
the viewcore.cpp is opend and in
int CView::OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message)
{.....}
What error? What line? What does the debug output window tell you? What are the values of the various variables on the line that gave you the error?
"You're obviously a superstar." - Christian Graus about me - 12 Feb '03
"Obviously ??? You're definitely a superstar!!!" - mYkel - 21 Jun '04
"There's not enough blatant self-congratulatory backslapping in the world today..." - HumblePie - 21 Jun '05
Within you lies the power for good - Use it!
|
|
|
|
|
Thank you Arends
i have anyhow solved the problem by
displaying the view on the Mainframe .
Thank you for bring to my notice that
view are ment for CFrameWnd
Vikas Amin
Embin Technology
Bombay
vikas.amin@embin.com
|
|
|
|
|
Hi,
I am planning to write a common library to be used in two projects, but not everything in the common library will be used in both the projects.
does anyone know if the individual project binaries will bloat due to unnecessary inclusion of functions in the common library that they will not be using?
Thanks
/f
|
|
|
|
|
Usually the linker's clever enough to not include functions that aren't used. For more details, see the options on MSDN, specifically /OPT:REF (which is the default in release builds).
Matt Godbolt
Engineer, ProFactor Software
StyleManager project
|
|
|
|
|
Except that I am pretty sure all code for all members and functions of C++ classes are included. This is what can lead to bloat - your C++ classes are huge.
Stand-alone library functions - the linker only includes the ones you call or are directly called by other functions.
|
|
|
|
|
I am new VB programming and using vb6. I want to fill grid for some records from my database. I am using msflexgrid for displaying data and managing rows and columns in loop by code for that but by doing so, it slow the speed of application when records exceed about 50 - 60, is there any other alternative for that, also i m in search of any good input grid control
|
|
|
|
|
If m_Flex is the control variable connected to the control:
m_Flex.SetRedraw(FALSE);<br />
<br />
<br />
m_Flex.SetRedraw(TRUE);
And this is not a VBee forum.
this is this.
|
|
|
|
|
Hi,
try this one.
Regards
Achim Klein
We can do no great things, only small things with great love. - Mother Theresa
|
|
|
|
|
hi
i wanted to know how should i handle other Application's Messages?
something like what a Spys or KidControllers Applications do. for example getting the other applications keystrokes. or getting other applications Window position.
thx
-- modified at 5:50 Saturday 24th September, 2005
|
|
|
|
|
Here is a keyboard hook (Global hook):
http://www.codeproject.com/dll/keyboardhook.asp[^]
To know the other windows position:
1- ::EnumChildWindows(...) can be used.
First get the desktop window, then enumerate its children. That gives you HWND 's for all windows.
2- ::FindWindow(...)
You can give it the window title text, and it will return the HWND .
Then use ::GetWindowRect(...) . That will give you the left and top.
this is this.
|
|
|
|
|
hi all
ive made a dialog based application with MFC appwizard .
i wanted to handle the keyboard enteries so i used wm_keydown
but the problem is that when i hit The Arrows (up down ..) it doesnt call the function onKeyDown(). and also when i press enter the program exits.(i delete the OK and CANCEL default keys)
what should i do?? how should i handle arrow an enter keys??
|
|
|
|
|
Look here for handling keys:
http://www.codeproject.com/dialog/pretransdialog01.asp[^]
As for the Enter key, put a button on the dialog with ID:
IDOK .
(Change the default from IDC_BUTTON1 to IDOK)
Handle the click event:
OnOK()<br />
{<br />
}
Then delete the new button you put there.
this is this.
|
|
|
|
|
|
hi
i wanted to know how should i scale a bitmap.
can i use SetMapMode() ?? and then bitblt the bitmap??
|
|
|
|
|
|
Hi,
here is some copy-and-paste code:
CBitmap* CMyDialog::ZoomBitmap(CBitmap* pBitmap, const CRect& FitInto)
{
if (FitInto.IsRectEmpty()) return 0;
CRect bmpRect = doGetBitmapRect(pBitmap);
if (bmpRect.IsRectEmpty()) return 0;
CRect zoomedRect = doGetZoomedBitmapRect(pBitmap, FitInto);
if (zoomedRect.IsRectEmpty()) return 0;
CDC* pDC = GetDC();
if (pDC == 0) return 0;
CDC* memDC1 = new CDC;
if (memDC1->CreateCompatibleDC(pDC) == 0)
{
delete memDC1;
ReleaseDC(pDC);
return 0;
}
CDC* memDC2 = new CDC;
if (memDC2->CreateCompatibleDC(pDC) == 0)
{
delete memDC1;
delete memDC2;
ReleaseDC(pDC);
return 0;
}
CBitmap* zoomed = new CBitmap;
if (zoomed->CreateCompatibleBitmap(pDC, zoomedRect.Width(), zoomedRect.Height()) == 0)
{
delete memDC1;
delete memDC2;
delete zoomed;
ReleaseDC(pDC);
return 0;
}
ReleaseDC(pDC);
CBitmap* old1 = memDC1->SelectObject(pBitmap);
CBitmap* old2 = memDC2->SelectObject(zoomed);
memDC2->SetStretchBltMode(HALFTONE);
BOOL result = memDC2->StretchBlt
(
0,
0,
zoomedRect.Width(),
zoomedRect.Height(),
memDC1,
0,
0,
bmpRect.Width(),
bmpRect.Height(),
SRCCOPY
);
if (result == FALSE)
{
delete zoomed;
zoomed = 0;
}
memDC2->SelectObject(old2);
memDC1->SelectObject(old1);
delete memDC2;
delete memDC1;
return zoomed;
}
Regards
Achim Klein
We can do no great things, only small things with great love. - Mother Theresa
|
|
|
|
|
Looks good! But you should eliminate all thoses unneeded news. The only new required by your code is that used to allocate zoomed. If any one of the news (except the first one) was to throw an exception, your code would leak memory.
If you modified the code to take another CBitmap argument to store the results, then you could elimimate all allocation. That way the user of the ZoomBitmap function would not need to know that they are responsible for deleting the returned pointer via delete, unles they had allocated it themselfs.
Exmaple:
BOOL ZoomBitmap(Bitmap& zoomed, Bitmap& srcBitmap, const CRect& FitInto )
{...}<br>
void OnZoom()
{
CBitmap zoomed;
if( ZoomBitmap(zoomed,srcBitmap,FitInto) )
}
Oh well, just some minor observations...
INTP
Every thing is relative...
|
|
|
|
|
hi
how to search for a specific file in folder using VC++?
i have searched CFile class but didn't get the idea.
Thanx in advance
|
|
|
|
|
|
|
my project is get the signal from pc mic to pc. below is one of the Cwavein class. i wan to read buffer to display graph and do signal processing. could anyone help me how to read the buffer? and i wan use 2dpushgraph that is in code project to display my graph. the statement is m_pushgraph.push(a,b),a is the magnitude in the buffer. b is how many line i wan display. could anyone tell me what magnitude should i put, how can i knw the magnitude(shw me example of programming), and should i put all the magnitude or jst push one magnitude and use looping for it and buffer will automatically get the data one by one in the array.thx for ur help.
// WaveIn.cpp: implementation of the CWaveIn class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "xxx.h"
#include "WaveIn.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
IMPLEMENT_DYNCREATE(CWaveIn, CWinThread)
CWaveIn::CWaveIn(int iHertz)
{
memset(&m_WaveFormatEx,0x00,sizeof(m_WaveFormatEx)); // set the memory content to all zeros
// configure the audio input record format
m_WaveFormatEx.wFormatTag = WAVE_FORMAT_PCM; // Pulse Code Modulation
m_WaveFormatEx.nChannels = 1; // mono
m_WaveFormatEx.wBitsPerSample = 16; // 16-bit/sample
m_WaveFormatEx.cbSize = 0;
m_WaveFormatEx.nSamplesPerSec = iHertz; // sampling freq = 44.1kHz
m_WaveFormatEx.nAvgBytesPerSec = m_WaveFormatEx.nSamplesPerSec*(m_WaveFormatEx.wBitsPerSample/8);
m_WaveFormatEx.nBlockAlign = (m_WaveFormatEx.wBitsPerSample/8)*m_WaveFormatEx.nChannels;
// initialize indicators
m_bAudioIn = FALSE;
m_bRecording = FALSE;
// initialize pointers to NULL
m_ptrWaveOut = NULL;
m_ptrWaveFile = NULL;
}
CWaveIn::~CWaveIn()
{
}
BOOL CWaveIn::InitInstance()
{
// TODO: perform any per-thread initializetion here
return TRUE;
}
int CWaveIn::ExitInstance()
{
// TODO: perform any per-thread cleanup here
return CWinThread::ExitInstance();
}
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
BEGIN_MESSAGE_MAP(CWaveIn, CWinThread)
//{{AFX_MSG_MAP(CWaveIn)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
ON_THREAD_MESSAGE(WM_WAVEIN_START, StartWaveIn)
ON_THREAD_MESSAGE(WM_WAVEIN_STOP, StopWaveIn)
ON_THREAD_MESSAGE(MM_WIM_DATA, OnAudioInputBufferFull)
ON_THREAD_MESSAGE(WM_WAVEIN_ENDTHREAD, OnEndThread)
ON_THREAD_MESSAGE(WM_WAVEIN_ONPTRWAVEOUT, OnPtrWaveOut)
ON_THREAD_MESSAGE(WM_WAVEIN_ONPTRWAVEFILE, OnPtrWaveFile)
END_MESSAGE_MAP()
//////////////////////////////////////////////////////////////
// create pointer to CWaveOut
//////////////////////////////////////////////////////////////
LRESULT CWaveIn::OnPtrWaveOut(WPARAM wParam, LPARAM lParam)
{
m_ptrWaveOut = (CWaveOut*) lParam;
return TRUE;
//return ERROR_SUCCESS;
}
//////////////////////////////////////////////////////////////
// create pointer to CWaveFile
//////////////////////////////////////////////////////////////
LRESULT CWaveIn::OnPtrWaveFile(WPARAM wParam, LPARAM lParam)
{
m_ptrWaveFile = (CWaveFile*) lParam;
return TRUE;
//return ERROR_SUCCESS;
}
//////////////////////////////////////////////////////////////
// open audio input device
//////////////////////////////////////////////////////////////
LRESULT CWaveIn::StartWaveIn(WPARAM wParam, LPARAM lParam)
{
DWORD mmReturn = 0; // return parameter for multimedia devices
if(m_bAudioIn) // if MIC is already ON, then no need to ON it again.
return FALSE;
if(!m_bAudioIn)
{
// Open AudioInDevice
MMRESULT mmReturn = ::waveInOpen(&m_hWaveIn,WAVE_MAPPER,&m_WaveFormatEx, ::GetCurrentThreadId(),0,CALLBACK_THREAD);
// if failed to open AudioInDevice
if(mmReturn)
{
char errorbuffer[MAX_PATH];
char errorbuffer1[MAX_PATH];
waveInGetErrorText(mmReturn,errorbuffer,MAX_PATH);
sprintf(errorbuffer1,"WAVEIN:%x:%s",mmReturn,errorbuffer);
AfxMessageBox(errorbuffer1);
}
// if success opening the AudioInDevice
if(!mmReturn)
{
AllocateBuffers(MAXINPUTBUFFERS);
mmReturn = ::waveInStart(m_hWaveIn);// start sampling
// if start sampling failed
if(mmReturn)
{
char errorbuffer[MAX_PATH];
char errorbuffer1[MAX_PATH];
waveInGetErrorText(mmReturn,errorbuffer,MAX_PATH);
sprintf(errorbuffer1,"WAVEIN:%x:%s",mmReturn,errorbuffer);
AfxMessageBox(errorbuffer1);
}
// if start sampling success
if(!mmReturn)
{
m_bAudioIn = TRUE; // indicate successfully open the AudioInDevice for sampling
// if the pointer to CWaveOut is available
// send thread to Open the AudioOutDevice at CWaveOut
if(m_ptrWaveOut)
m_ptrWaveOut->PostThreadMessage(WM_WAVEOUT_START,0,0);
// need to modify here,
// do not create the file here,
// create the file in CWaveFile
// NOTE: the pointer m_ptrWaveOut & m_ptrWaveFile is obtained while program initialized.
// now we need to modify so that the
// m_ptrWaveFile is only create by
// a thread sent by CWaveFile
//
// so we can also use it as flag to indicate
// whether the recording is started...
// if the pointer to CWaveFile is available
//if(m_ptrWaveFile)
//{
// PWAVEFILE pwsf= (PWAVEFILE) new WAVEFILE;
// ZeroMemory(pwsf,sizeof(WAVEFILE));
// char *p = pwsf->lpszFileName;
// strcpy(p,"sound.wav"); // .wav filename, under the same directory
// memcpy(&pwsf->waveFormatEx,&m_WaveFormatEx,sizeof(m_WaveFormatEx));
// // send thread to create the file at CWaveFile
// m_ptrWaveFile->PostThreadMessage(WM_WAVEFILE_CREATE,0,(LPARAM)pwsf);
//}
return ERROR_SUCCESS;
}
}
}
return TRUE;
}
///////////////////////////////////////////////////////////////////
// close audio input device
///////////////////////////////////////////////////////////////////
LRESULT CWaveIn::StopWaveIn(WPARAM wParam, LPARAM lParam)
{
MMRESULT mmReturn = 0; // return parameter for multimedia device
// if MIC already close, then no need to close again
if(!m_bAudioIn)
return FALSE;
// if MIC is ON, then close it...
if(m_bAudioIn)
{
mmReturn = ::waveInStop(m_hWaveIn); // stop sampling process
if(!mmReturn)
mmReturn = ::waveInReset(m_hWaveIn);
FreeSpareBuffers(); // clean up all buffers
if(!mmReturn)
m_bAudioIn = FALSE; // indicate AudioOutDevice now Close.
Sleep(500);
if(!mmReturn)
mmReturn = ::waveInClose(m_hWaveIn); // close AudioInDevice
// if pointer to AudioOutDevice exist,
// send thread to close the device
if(m_ptrWaveOut)
m_ptrWaveOut->PostThreadMessage(WM_WAVEOUT_STOP,0,0);
// if pointer to CWaveFile exist,
// send thread to close the file.
//if(m_ptrWaveFile)
//m_ptrWaveFile->PostThreadMessage(WM_WAVEFILE_CLOSE,0,0);
return mmReturn;
}
return TRUE;
}
///////////////////////////////////////////////////////////////////
// response to MM_WIM_DATA
///////////////////////////////////////////////////////////////////
LRESULT CWaveIn::OnAudioInputBufferFull(WPARAM wParam, LPARAM lParam)
{
LPWAVEHDR lpWaveHdr = (LPWAVEHDR) lParam; // receive the return buffer
// if the buffer is not empty
if(lpWaveHdr)
{
BYTE * lpInt = (BYTE*) lpWaveHdr->lpData; // retrieve the audio data
DWORD iRecorded = lpWaveHdr->dwBytesRecorded; // get how many bytes recorded
/* TRACE("\n Data length %d",iRecorded);
AfxMessageBox("");
int *p = (int*)lpInt;
for(int i=0; i<irecorded; i++)
="" trace("\n="" data="" is="" %d",="" p[i]);*=""
="" ::waveinunprepareheader(m_hwavein,="" lpwavehdr,="" sizeof(wavehdr));
="" perform="" input="" signal="" processing="" here,="" i.e.:="" low="" pass="" filter
="" processsounddata(lpint,="" irecorded="" sizeof(byte));
="" if="" pointer="" to="" cwavefile="" exist,
="" send="" thread="" write="" into="" it...
="" if(m_ptrwavefile)
="" {
="" wavehdr*="" pwritehdr="new" wavehdr;
="" if(!pwritehdr)
="" return="" false;
="" memcpy(pwritehdr,lpwavehdr,sizeof(wavehdr));
="" byte="" *="" psound="new" byte[lpwavehdr-="">dwBufferLength];
if(!pSound)
{
delete pWriteHdr;
return FALSE;
}
memcpy(pSound,lpWaveHdr->lpData,lpWaveHdr->dwBufferLength);
pWriteHdr->lpData = (char*)pSound;
// send thread to write to file
m_ptrWaveFile->PostThreadMessage(WM_WAVEFILE_WRITE,GetCurrentThreadId(),(LPARAM) pWriteHdr);
}
// if pointer to CWaveOut exist,
// send thread to echo the audio.
if(m_ptrWaveOut)
{
m_ptrWaveOut->PostThreadMessage(WM_WAVEOUT_WRITE, GetCurrentThreadId(),(LPARAM) lpWaveHdr);
}
else
{
delete lpInt;
delete lpWaveHdr;
}
char debugbuffer[256];
sprintf(debugbuffer, "SOUND BUFFER returned: %d\n",iRecorded);
TRACE(debugbuffer);
if(m_bAudioIn)
{
AllocateBuffers(1);
}
}
return TRUE;
}
///////////////////////////////////////////////////////////////////
// perform clean up
///////////////////////////////////////////////////////////////////
LRESULT CWaveIn::OnEndThread(WPARAM wParam, LPARAM lParam)
{
if(m_bAudioIn)
{
StopWaveIn(0, 0);
}
::PostQuitMessage(0);
return TRUE;
}
///////////////////////////////////////////////////////////////////
// prepare & send the buffer to audio in device driver
///////////////////////////////////////////////////////////////////
void CWaveIn::AllocateBuffers(int nBuffers)
{
int i;
for(i=0; i < nBuffers; i++)
{
LPWAVEHDR lpWaveHdr = CreateWaveHeader();
::waveInPrepareHeader(m_hWaveIn,lpWaveHdr, sizeof(WAVEHDR));
::waveInAddBuffer(m_hWaveIn, lpWaveHdr, sizeof(WAVEHDR));
}
}
///////////////////////////////////////////////////////////////////
// create wave buffer header
///////////////////////////////////////////////////////////////////
LPWAVEHDR CWaveIn::CreateWaveHeader()
{
LPWAVEHDR lpWaveHdr = new WAVEHDR;
ZeroMemory(lpWaveHdr, sizeof(WAVEHDR));
BYTE* lpByte = new BYTE[(m_WaveFormatEx.nBlockAlign*SOUNDSAMPLES)];
lpWaveHdr->lpData = (char *) lpByte;
lpWaveHdr->dwBufferLength = (m_WaveFormatEx.nBlockAlign*SOUNDSAMPLES);
return lpWaveHdr;
}
///////////////////////////////////////////////////////////////////
// free the buffers remained audio in device driver
///////////////////////////////////////////////////////////////////
void CWaveIn::FreeSpareBuffers()
{
MSG msg;
Sleep(20);
while(::PeekMessage(&msg,NULL,MM_WIM_OPEN,MM_WIM_DATA,PM_REMOVE))
{
if(msg.wParam == MM_WIM_OPEN || msg.wParam == MM_WIM_CLOSE)
continue;
LPWAVEHDR lpWaveHdr = (LPWAVEHDR) msg.lParam;
if(lpWaveHdr)
{
BYTE * lpByte = (BYTE*) lpWaveHdr->lpData;
::waveInUnprepareHeader(m_hWaveIn, lpWaveHdr, sizeof(WAVEHDR));
if(lpByte)
delete lpByte;
delete lpWaveHdr;
}
}
}
void CWaveIn::ClearPtrWaveFile()
{
m_ptrWaveFile = NULL;
}
IMPLEMENT_DYNCREATE(CWaveIn, CWinThread)
CWaveIn::CWaveIn(int iHertz)
{
memset(&m_WaveFormatEx,0x00,sizeof(m_WaveFormatEx)); // set the memory content to all zeros
// configure the audio input record format
m_WaveFormatEx.wFormatTag = WAVE_FORMAT_PCM; // Pulse Code Modulation
m_WaveFormatEx.nChannels = 1; // mono
m_WaveFormatEx.wBitsPerSample = 16; // 16-bit/sample
m_WaveFormatEx.cbSize = 0;
m_WaveFormatEx.nSamplesPerSec = iHertz; // sampling freq = 44.1kHz
m_WaveFormatEx.nAvgBytesPerSec = m_WaveFormatEx.nSamplesPerSec*(m_WaveFormatEx.wBitsPerSample/8);
m_WaveFormatEx.nBlockAlign = (m_WaveFormatEx.wBitsPerSample/8)*m_WaveFormatEx.nChannels;
// initialize indicators
m_bAudioIn = FALSE;
m_bRecording = FALSE;
// initialize pointers to NULL
m_ptrWaveOut = NULL;
m_ptrWaveFile = NULL;
}
CWaveIn::~CWaveIn()
{
}
BOOL CWaveIn::InitInstance()
{
// TODO: perform any per-thread initializetion here
return TRUE;
}
int CWaveIn::ExitInstance()
{
// TODO: perform any per-thread cleanup here
return CWinThread::ExitInstance();
}
////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////
BEGIN_MESSAGE_MAP(CWaveIn, CWinThread)
//{{AFX_MSG_MAP(CWaveIn)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
ON_THREAD_MESSAGE(WM_WAVEIN_START, StartWaveIn)
ON_THREAD_MESSAGE(WM_WAVEIN_STOP, StopWaveIn)
ON_THREAD_MESSAGE(MM_WIM_DATA, OnAudioInputBufferFull)
ON_THREAD_MESSAGE(WM_WAVEIN_ENDTHREAD, OnEndThread)
ON_THREAD_MESSAGE(WM_WAVEIN_ONPTRWAVEOUT, OnPtrWaveOut)
ON_THREAD_MESSAGE(WM_WAVEIN_ONPTRWAVEFILE, OnPtrWaveFile)
END_MESSAGE_MAP()
//////////////////////////////////////////////////////////////
// create pointer to CWaveOut
//////////////////////////////////////////////////////////////
LRESULT CWaveIn::OnPtrWaveOut(WPARAM wParam, LPARAM lParam)
{
m_ptrWaveOut = (CWaveOut*) lParam;
return TRUE;
//return ERROR_SUCCESS;
}
//////////////////////////////////////////////////////////////
// create pointer to CWaveFile
//////////////////////////////////////////////////////////////
LRESULT CWaveIn::OnPtrWaveFile(WPARAM wParam, LPARAM lParam)
{
m_ptrWaveFile = (CWaveFile*) lParam;
return TRUE;
//return ERROR_SUCCESS;
}
//////////////////////////////////////////////////////////////
// open audio input device
//////////////////////////////////////////////////////////////
LRESULT CWaveIn::StartWaveIn(WPARAM wParam, LPARAM lParam)
{
DWORD mmReturn = 0; // return parameter for multimedia devices
if(m_bAudioIn) // if MIC is already ON, then no need to ON it again.
return FALSE;
if(!m_bAudioIn)
{
// Open AudioInDevice
MMRESULT mmReturn = ::waveInOpen(&m_hWaveIn,WAVE_MAPPER,&m_WaveFormatEx, ::GetCurrentThreadId(),0,CALLBACK_THREAD);
// if failed to open AudioInDevice
if(mmReturn)
{
char errorbuffer[MAX_PATH];
char errorbuffer1[MAX_PATH];
waveInGetErrorText(mmReturn,errorbuffer,MAX_PATH);
sprintf(errorbuffer1,"WAVEIN:%x:%s",mmReturn,errorbuffer);
AfxMessageBox(errorbuffer1);
}
// if success opening the AudioInDevice
if(!mmReturn)
{
AllocateBuffers(MAXINPUTBUFFERS);
mmReturn = ::waveInStart(m_hWaveIn);// start sampling
// if start sampling failed
if(mmReturn)
{
char errorbuffer[MAX_PATH];
char errorbuffer1[MAX_PATH];
waveInGetErrorText(mmReturn,errorbuffer,MAX_PATH);
sprintf(errorbuffer1,"WAVEIN:%x:%s",mmReturn,errorbuffer);
AfxMessageBox(errorbuffer1);
}
// if start sampling success
if(!mmReturn)
{
m_bAudioIn = TRUE; // indicate successfully open the AudioInDevice for sampling
// if the pointer to CWaveOut is available
// send thread to Open the AudioOutDevice at CWaveOut
if(m_ptrWaveOut)
m_ptrWaveOut->PostThreadMessage(WM_WAVEOUT_START,0,0);
// need to modify here,
// do not create the file here,
// create the file in CWaveFile
// NOTE: the pointer m_ptrWaveOut & m_ptrWaveFile is obtained while program initialized.
// now we need to modify so that the
// m_ptrWaveFile is only create by
// a thread sent by CWaveFile
//
// so we can also use it as flag to indicate
// whether the recording is started...
// if the pointer to CWaveFile is available
//if(m_ptrWaveFile)
//{
// PWAVEFILE pwsf= (PWAVEFILE) new WAVEFILE;
// ZeroMemory(pwsf,sizeof(WAVEFILE));
// char *p = pwsf->lpszFileName;
// strcpy(p,"sound.wav"); // .wav filename, under the same directory
// memcpy(&pwsf->waveFormatEx,&m_WaveFormatEx,sizeof(m_WaveFormatEx));
// // send thread to create the file at CWaveFile
// m_ptrWaveFile->PostThreadMessage(WM_WAVEFILE_CREATE,0,(LPARAM)pwsf);
//}
return ERROR_SUCCESS;
}
}
}
return TRUE;
}
///////////////////////////////////////////////////////////////////
// close audio input device
///////////////////////////////////////////////////////////////////
LRESULT CWaveIn::StopWaveIn(WPARAM wParam, LPARAM lParam)
{
MMRESULT mmReturn = 0; // return parameter for multimedia device
// if MIC already close, then no need to close again
if(!m_bAudioIn)
return FALSE;
// if MIC is ON, then close it...
if(m_bAudioIn)
{
mmReturn = ::waveInStop(m_hWaveIn); // stop sampling process
if(!mmReturn)
mmReturn = ::waveInReset(m_hWaveIn);
FreeSpareBuffers(); // clean up all buffers
if(!mmReturn)
m_bAudioIn = FALSE; // indicate AudioOutDevice now Close.
Sleep(500);
if(!mmReturn)
mmReturn = ::waveInClose(m_hWaveIn); // close AudioInDevice
// if pointer to AudioOutDevice exist,
// send thread to close the device
if(m_ptrWaveOut)
m_ptrWaveOut->PostThreadMessage(WM_WAVEOUT_STOP,0,0);
// if pointer to CWaveFile exist,
// send thread to close the file.
//if(m_ptrWaveFile)
//m_ptrWaveFile->PostThreadMessage(WM_WAVEFILE_CLOSE,0,0);
return mmReturn;
}
return TRUE;
}
///////////////////////////////////////////////////////////////////
// response to MM_WIM_DATA
///////////////////////////////////////////////////////////////////
LRESULT CWaveIn::OnAudioInputBufferFull(WPARAM wParam, LPARAM lParam)
{
LPWAVEHDR lpWaveHdr = (LPWAVEHDR) lParam; // receive the return buffer
// if the buffer is not empty
if(lpWaveHdr)
{
BYTE * lpInt = (BYTE*) lpWaveHdr->lpData; // retrieve the audio data
DWORD iRecorded = lpWaveHdr->dwBytesRecorded; // get how many bytes recorded
/* TRACE("\n Data length %d",iRecorded);
AfxMessageBox("");
int *p = (int*)lpInt;
for(int i=0; i<irecorded; i++)
="" trace("\n="" data="" is="" %d",="" p[i]);*=""
="" ::waveinunprepareheader(m_hwavein,="" lpwavehdr,="" sizeof(wavehdr));
="" perform="" input="" signal="" processing="" here,="" i.e.:="" low="" pass="" filter
="" processsounddata(lpint,="" irecorded="" sizeof(byte));
="" if="" pointer="" to="" cwavefile="" exist,
="" send="" thread="" write="" into="" it...
="" if(m_ptrwavefile)
="" {
="" wavehdr*="" pwritehdr="new" wavehdr;
="" if(!pwritehdr)
="" return="" false;
="" memcpy(pwritehdr,lpwavehdr,sizeof(wavehdr));
="" byte="" *="" psound="new" byte[lpwavehdr-="">dwBufferLength];
if(!pSound)
{
delete pWriteHdr;
return FALSE;
}
memcpy(pSound,lpWaveHdr->lpData,lpWaveHdr->dwBufferLength);
pWriteHdr->lpData = (char*)pSound;
// send thread to write to file
m_ptrWaveFile->PostThreadMessage(WM_WAVEFILE_WRITE,GetCurrentThreadId(),(LPARAM) pWriteHdr);
}
// if pointer to CWaveOut exist,
// send thread to echo the audio.
if(m_ptrWaveOut)
{
m_ptrWaveOut->PostThreadMessage(WM_WAVEOUT_WRITE, GetCurrentThreadId(),(LPARAM) lpWaveHdr);
}
else
{
delete lpInt;
delete lpWaveHdr;
}
char debugbuffer[256];
sprintf(debugbuffer, "SOUND BUFFER returned: %d\n",iRecorded);
TRACE(debugbuffer);
if(m_bAudioIn)
{
AllocateBuffers(1);
}
}
return TRUE;
}
///////////////////////////////////////////////////////////////////
// perform clean up
///////////////////////////////////////////////////////////////////
LRESULT CWaveIn::OnEndThread(WPARAM wParam, LPARAM lParam)
{
if(m_bAudioIn)
{
StopWaveIn(0, 0);
}
::PostQuitMessage(0);
return TRUE;
}
///////////////////////////////////////////////////////////////////
// prepare & send the buffer to audio in device driver
///////////////////////////////////////////////////////////////////
void CWaveIn::AllocateBuffers(int nBuffers)
{
int i;
for(i=0; i < nBuffers; i++)
{
LPWAVEHDR lpWaveHdr = CreateWaveHeader();
::waveInPrepareHeader(m_hWaveIn,lpWaveHdr, sizeof(WAVEHDR));
::waveInAddBuffer(m_hWaveIn, lpWaveHdr, sizeof(WAVEHDR));
}
}
///////////////////////////////////////////////////////////////////
// create wave buffer header
///////////////////////////////////////////////////////////////////
LPWAVEHDR CWaveIn::CreateWaveHeader()
{
LPWAVEHDR lpWaveHdr = new WAVEHDR;
ZeroMemory(lpWaveHdr, sizeof(WAVEHDR));
BYTE* lpByte = new BYTE[(m_WaveFormatEx.nBlockAlign*SOUNDSAMPLES)];
lpWaveHdr->lpData = (char *) lpByte;
lpWaveHdr->dwBufferLength = (m_WaveFormatEx.nBlockAlign*SOUNDSAMPLES);
return lpWaveHdr;
}
///////////////////////////////////////////////////////////////////
// free the buffers remained audio in device driver
///////////////////////////////////////////////////////////////////
void CWaveIn::FreeSpareBuffers()
{
MSG msg;
Sleep(20);
while(::PeekMessage(&msg,NULL,MM_WIM_OPEN,MM_WIM_DATA,PM_REMOVE))
{
if(msg.wParam == MM_WIM_OPEN || msg.wParam == MM_WIM_CLOSE)
continue;
LPWAVEHDR lpWaveHdr = (LPWAVEHDR) msg.lParam;
if(lpWaveHdr)
{
BYTE * lpByte = (BYTE*) lpWaveHdr->lpData;
::waveInUnprepareHeader(m_hWaveIn, lpWaveHdr, sizeof(WAVEHDR));
if(lpByte)
delete lpByte;
delete lpWaveHdr;
}
}
}
void CWaveIn::ClearPtrWaveFile()
{
m_ptrWaveFile = NULL;
}
|
|
|
|
|
There is an article in the audio section on building and dusplaying "peak files". A peak file is the bit representation of your waveform. The same code shows to display it.
Bill Dennis
Orlando, FL
|
|
|
|
|
Hi,
I have two questions:
1. What does KEY_EXECUTE access mode do to a registry key while opening/creating it?
2. MSDN talks about RegDeleteKeyEx, but it doesnt seem to be defined in VS6 or Platform SDK. Does anyone know more about this API?
Thanks.
|
|
|
|
|
KEY_EXECUTE is equivalent to KEY_READ.
Msdn says:
RegDeleteKeyEx
Client: Requires Windows "Longhorn" or Windows XP Professional x64 Edition.
Server: Requires Windows Server "Longhorn" or Windows Server 2003 SP1.
It is not in VS6. I guess it needs the newest Platform SDK, maybe even the one not compatible with VS6.
this is this.
|
|
|
|
|