INT APIENTRY WinMain( HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR pCmdLine,
INT nCmdShow )
{
HRESULT hr;
DWORD dwResult;
MSG msg;
BOOL bDone;
HWND hDlg;
g_hInst = hInst;
g_hNotificationEvent = CreateEvent( NULL, FALSE, FALSE, NULL );
// Create the main dialog box, but keep it hidden for now
hDlg = CreateDialog( hInst, MAKEINTRESOURCE(IDD_MAIN), NULL, MainDlgProc );
// Display the formats dialog box, and show it
dwResult = (DWORD)DialogBox( hInst, MAKEINTRESOURCE(IDD_DEVICES),
NULL, DevicesDlgProc );
if( dwResult != IDOK )
{
// The user canceled, so stop message pump,
// and fall through to the cleanup code
PostQuitMessage( 0 );
}
else
{
// Init DirectSound
if( FAILED( hr = InitDirectSound( hDlg, &g_guidCaptureDevice ) ) )
{
DXTRACE_ERR_MSGBOX( TEXT("InitDirectSound"), hr );
MessageBox( hDlg, L"Error initializing DirectSound. Sample will now exit.",
L"DirectSound Sample", MB_OK | MB_ICONERROR );
PostQuitMessage( 0 );
dwResult = IDCANCEL;
}
}
// Display the formats dialog box, and show it
if( dwResult == IDOK )
{
dwResult = (DWORD)DialogBox( hInst, MAKEINTRESOURCE(IDD_FORMATS),
NULL, FormatsDlgProc );
}
if( dwResult != IDOK )
{
// The user canceled, so stop message pump,
// and fall through to the cleanup code
PostQuitMessage( 0 );
}
else
{
WAVEFORMATEX wfxInput;
TCHAR strInputFormat[255];
HWND hInputFormatText;
hInputFormatText = GetDlgItem( hDlg, IDC_MAIN_INPUTFORMAT_TEXT );
ZeroMemory( &wfxInput, sizeof(wfxInput));
g_pDSBCapture->GetFormat( &wfxInput, sizeof(wfxInput), NULL );
ConvertWaveFormatToString( &wfxInput, strInputFormat, 255 );
SetWindowText( hInputFormatText, strInputFormat );
g_bRecording = FALSE;
ShowWindow( hDlg, SW_SHOW );
}
bDone = FALSE;
while( !bDone )
{
dwResult = MsgWaitForMultipleObjects( 1, &g_hNotificationEvent,
FALSE, INFINITE, QS_ALLEVENTS );
switch( dwResult )
{
case WAIT_OBJECT_0 + 0:
// g_hNotificationEvents[0] is signaled
// This means that DirectSound just finished playing
// a piece of the buffer, so we need to fill the circular
// buffer with new sound from the wav file
if( FAILED( hr = RecordCapturedData() ) )
{
DXTRACE_ERR_MSGBOX( TEXT("RecordCapturedData"), hr );
MessageBox( hDlg, L"Error handling DirectSound notifications. "
L"Sample will now exit.", L"DirectSound Sample",
MB_OK | MB_ICONERROR );
bDone = TRUE;
}
break;
case WAIT_OBJECT_0 + 1:
// Windows messages are available
while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
{
if( !IsDialogMessage( hDlg, &msg ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
if( msg.message == WM_QUIT )
bDone = TRUE;
}
break;
}
}
// Stop the capture and read any data that was not caught by a notification
StartOrStopRecord( FALSE );
// Clean up everything
FreeDirectSound();
CloseHandle( g_hNotificationEvent );
return TRUE;
}
небольшой вопрос (Visual Studio 2005)
вот есть функция, как видно во время ее выполнения создаются окна... у меня такой вопрос как сделать чтобы при запуске сначала появлялось окно не из этой функции на котором будет например кнопка "старт" и только при нажатие на эту кнопку выполнялась функция, а при закрытие последнего окна из функции, появлялось первое окно с кнопкой "старт".