【VC开源代码栏目提醒】:网学会员为广大网友收集整理了,bdasampl.cpp,希望对大家有所帮助!
//------------------------------------------------------------------------------
// File: Bdasampl.cpp
//
// Desc: Sample code implementing BDA graph building.
//
// Copyright (c) 2000-2002, Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------------
#include "bdasampl.h"
#include "graph.h"
#include "resource.h"
#include <initguid.h>
#include <objbase.h>
//
// NOTE: In this sample, text strings are hard-coded for
// simplicity and for readability. For product code, you should
// use string tables and LoadString().
//
// Global data
HWND hwndMain=0;
HWND g_hwndDlg=0;
HINSTANCE hInst=0;
TCHAR szAppName[] = TEXT("BDASampl\0");
TCHAR szAppTitle[] = TEXT("BDA Sample\0");
CBDAFilterGraph* g_pfg = NULL;
// Constants
const int MAJOR_CHANNEL_LOWER_LIMIT = -1;
const int MAJOR_CHANNEL_UPPER_LIMIT = 126;
const int MINOR_CHANNEL_LOWER_LIMIT = -1;
const int MINOR_CHANNEL_UPPER_LIMIT = 126;
INT WINAPI
WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine,
INT nCmdShow)
{
MSG msg={0};
WNDCLASS wndclass={0};
HWND hwnd=0;
HACCEL hAccel=0;
// Save application instance handle for later use
hInst = hInstance;
// Initialize COM library
HRESULT hr = CoInitializeEx (NULL, COINIT_APARTMENTTHREADED);
if (FAILED (hr))
{
MessageBox(NULL, TEXT("Failed to initialize COM library!\0"),
TEXT("Initialization Error\0"), MB_ICONEXCLAMATION);
return 0;
}
// Register window class
wndclass.style = 0;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInst;
wndclass.hIcon = LoadIcon(hInst, TEXT("BDASAMPLICON"));
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 2);
wndclass.lpszMenuName = szAppName;
wndclass.lpszClassName = szAppName;
RegisterClass(&wndclass);
hwnd = CreateWindow(szAppName, szAppTitle,
WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
200, 200, 500, 280,
NULL, NULL, hInst, NULL);
ASSERT(hwnd);
// Create the BDA filter graph and initialize its components
g_pfg = new CBDAFilterGraph();
ASSERT(g_pfg);
// If the graph failed to build, don't go any further.
if (!g_pfg)
{
MessageBox(hwnd, TEXT("Failed to create the filter graph!"),
TEXT("Initialization Error"), MB_ICONEXCLAMATION);
return 0;
}
// Display main window and configure accelerators
ShowWindow(hwnd, nCmdShow);
hwndMain = hwnd;
hAccel = LoadAccelerators(hInst, MAKEINTRESOURCE(ACC_GRAPH));
// Main message loop
while(GetMessage(&msg, NULL, 0, 0) > 0)
{
if(!TranslateAccelerator(hwnd, hAccel, &msg))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
// Release the BDA components and clean up
delete g_pfg;
CoUninitialize ();
return msg.wParam;
}
// WndProc
LRESULT CALLBACK
WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_CREATE:
{
DbgInitialise (hInst);
break;
}
case WM_SIZE:
{
if(g_pfg && g_pfg->m_fGraphBuilt)
g_pfg->SetVideoWindow(hwndMain);
break;
}
case WM_COMMAND:
switch(LOWORD(wParam))
{
case IDM_BUILD_ATSC:
{
if (!g_pfg)
break;
if(FAILED(g_pfg->BuildGraph(ATSC)))
{
ErrorMessageBox(TEXT("Could not Build the ATSC BDA FilterGraph."));
}
else
{
g_pfg->SetVideoWindow(hwndMain);
}
HMENU hMenu = GetSubMenu(GetMenu(hwnd), 1);
EnableMenuItem(hMenu, IDM_BUILD_ATSC, MF_GRAYED | MF_BYCOMMAND);
EnableMenuItem(hMenu, IDM_STOP_GRAPH,
(g_pfg->m_fGraphRunning) ? (MF_BYCOMMAND|MF_ENABLED) : (MF_BYCOMMAND|MF_GRAYED));
EnableMenuItem(hMenu, IDM_SELECT_CHANNEL,
(g_pfg->m_fGraphBuilt) ? (MF_BYCOMMAND|MF_ENABLED) : (MF_BYCOMMAND|MF_GRAYED));
break;
}
case IDM_RUN_GRAPH:
{
if (!g_pfg)
break;
if(g_pfg->m_fGraphBuilt)
{
if(!g_pfg->m_fGraphRunning)
{
if(FAILED(g_pfg->RunGraph()))
{
ErrorMessageBox(TEXT("Could not play the FilterGraph."));
}
}
}
else
{
ErrorMessageBox(TEXT("The FilterGraph is not yet built."));
}
break;
}
case IDM_STOP_GRAPH:
{
if (!g_pfg)
break;
if(g_pfg->m_fGraphBuilt)
{
if(g_pfg->m_fGraphRunning)
{
if(FAILED(g_pfg->StopGraph()))
{
ErrorMessageBox(TEXT("Could not stop the FilterGraph,"));
}
}
}
else
{
ErrorMessageBox(TEXT("The FilterGraph is not yet built."));
}
HMENU hMenu = GetSubMenu (GetMenu (hwnd), 1);
EnableMenuItem (hMenu, IDM_SELECT_CHANNEL, MF_BYCOMMAND | MF_GRAYED);
break;
}
case IDM_SELECT_CHANNEL:
{
if (!g_pfg)
break;
if(g_pfg->m_fGrap