| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 417 人关注过本帖
标题:视频播放时遇到的问题
只看楼主 加入收藏
蜀山小二V
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2011-12-15
结帖率:100%
收藏
 问题点数:0 回复次数:0 
视频播放时遇到的问题
我之前配置了一下DierctX SDK ,然后终于可以播放视频了。但是有一个问题是,我想让视频在原窗口播放,可以它总是新建一个窗口播放。苦恼~~~
特来发帖,寻得前辈相助。不胜感激!
       代码如下:
#include <windows.h>
#include <dshow.h>
#include <stdio.h>
#pragma comment(lib,"Strmiids.lib")
  
  LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  
  int WINAPI WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR lpCmdLine,
                     int nShowCmd)
  {
     static TCHAR lpszAppName[] = TEXT("HelloWin");
     HWND      hwnd;
     MSG       msg;
     WNDCLASS  wc;
 
     wc.style         = CS_HREDRAW | CS_VREDRAW;
     wc.lpfnWndProc   = WndProc;
     wc.cbClsExtra    = 0;
     wc.cbWndExtra    = 0;
     wc.hInstance     = hInstance;
     wc.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
     wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
     wc.lpszMenuName  = NULL;
     wc.lpszClassName = lpszAppName;
 
     // 注册窗口类
     if (!RegisterClass(&wc))
     {
         MessageBox(NULL, TEXT("This program requires Windows NT!"),
             lpszAppName, MB_ICONERROR);
         return 0;
     }
 
     // 创建应用程序主窗口
     hwnd = CreateWindow(lpszAppName,
         TEXT("The Hello Program"),
         WS_OVERLAPPEDWINDOW,
         CW_USEDEFAULT,
         CW_USEDEFAULT,
         CW_USEDEFAULT,
         CW_USEDEFAULT,
         NULL,
         NULL,
         hInstance,
         NULL);

     // 显示窗口
     ShowWindow(hwnd, nShowCmd);
     UpdateWindow(hwnd);

     /**************************************
     播放视频
     *********************************************/
    IGraphBuilder    *pGraph = NULL;
    IMediaControl    *pControl = NULL;
    IMediaEvent        *pEvent = NULL;
    //初始化COM
    HRESULT hr = CoInitialize(NULL);
    if (FAILED(hr)) {
        printf("ERROR - Could not initialize COM library");
        //return;
    }
    //创建过滤图表管理器并查询接口
    hr = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER, IID_IGraphBuilder, (void**)&pGraph);
    if (FAILED(hr)) {
        printf("ERROR - Could not create the Filter Graph Manager.");
    //    return;
    }
    hr = pGraph->QueryInterface(IID_IMediaControl, (void**)&pControl);
    hr = pGraph->QueryInterface(IID_IMediaEvent, (void**)&pEvent);
    //建立图表。注意在此需要改变你系统上的一个文件
    hr = pGraph->RenderFile(L"F:\\我的游戏实训--保卫宝岛\\资源文件\\sendstringplay\\playmovie\\mpeg\\mpeg1.avi", NULL);
    if (SUCCEEDED(hr)) {
        //Run the graph.
        hr = pControl->Run();
        if (SUCCEEDED(hr)) {
            //Wait for completion.
            long evCode;
            pEvent->WaitForCompletion(INFINITE, &evCode);
            //注意:不要在项目中使用“无限”,因为会被无限地阻拦
        }
    }
    pControl->Release();
    pEvent->Release();
    pGraph->Release();
    CoUninitialize();
 
     // 消息循环
     while (GetMessage(&msg, NULL, 0, 0))
     {
         TranslateMessage(&msg);
         DispatchMessage(&msg);
     }
 
     return msg.wParam;
 }
  //
 // 窗口过程函数
 //
 LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
 {
     HDC         hdc;
     PAINTSTRUCT ps;
     RECT        rect;
 
     switch (message)
     {
     case WM_CREATE:
         return 0;
     case WM_PAINT:
         hdc = BeginPaint(hwnd, &ps);
         GetClientRect(hwnd, &rect);
         DrawText(hdc, TEXT("Hello World!"), -1, &rect,
             DT_SINGLELINE | DT_CENTER | DT_VCENTER);
         EndPaint(hwnd, &ps);
         return 0;
     case WM_DESTROY:
         PostQuitMessage(0);
         return 0;
     }
 
     return DefWindowProc(hwnd, message, wParam, lParam);
 }
搜索更多相关主题的帖子: 视频播放 不胜感激 comment include 
2012-12-20 18:26
快速回复:视频播放时遇到的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015518 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved