C#:如何打开配置Pin对话框?

时间:2011-01-13 13:35:11

标签: c# configuration video properties dialog

我想知道使用

运行什么进程
 System.Diagnostics.Process.Start("", "");

打开此对话框。谢谢 alt text 该对话框来自MS Expression编码器的实时广播项目,所选设备的Config pin Dialog。 alt text

4 个答案:

答案 0 :(得分:4)

此对话框不是可以与System.Diagnostics.Process.Start一起运行的单独可执行文件。这是捕获设备的配置对话框。您的捕获设备表示为DirectShow捕获设备。此设备是一个COM对象,它实现ISpecifyPropertyPages,这是您正在查看的特定屏幕的来源。 Here是一篇关于如何显示DirectShow过滤器属性页的MSDN文章。

答案 1 :(得分:2)

如果您使用的是Expression Encoder SDK 4,则可以按如下方式显示此对话框和其他配置窗口:

 LiveDeviceSource _deviceSource;   
 ....
 if (_deviceSource.IsDialogSupported(ConfigurationDialog.VideoCapturePinDialog))
 {              
       _deviceSource.ShowConfigurationDialog(ConfigurationDialog.VideoCapturePinDialog, (new HandleRef(panelVideoPreview, panelVideoPreview.Handle)));
 }

您可以通过浏览Microsoft.Expression.Encoder.Live.ConfigurationDialog类型来查看支持的所有配置对话框。

答案 2 :(得分:1)

没有可以使用该行运行的程序来调出该对话框。 (当然,除非你做一个。)

答案 3 :(得分:1)

使用Expression Encoder SDK中的LiveDeviceSource.ShowConfigurationDialog函数通常是一个不错的选择。但是,在我的情况下,我有一些捕获源,如果它们配置错误,Expression Encoder无法正确实例化。要正确配置它们,我需要它们的配置对话框。所以,我使用DirectShow.NET

将这个解决方案整合在一起
/// <summary>
/// Retrieves the IBaseFilter with the requested name
/// </summary>
/// <param name="deviceName">The friendly name of the device to retrieve</param>
/// <param name="deviceType">The type of device to retrieve</param>
/// <returns>Returns the filter with the given friendly name, or null if no such filter exists</returns>
public static IBaseFilter GetDeviceFilterByName(string deviceName, EncoderDeviceType deviceType)
{
    int hr = 0;
    IEnumMoniker classEnum = null;
    IMoniker[] moniker = new IMoniker[1];

    // Create the system device enumerator
    ICreateDevEnum devEnum = (ICreateDevEnum)new CreateDevEnum();

    // Create an enumerator for the video or audio capture devices
    if (deviceType == EncoderDeviceType.Audio)
    {
        hr = devEnum.CreateClassEnumerator(FilterCategory.AudioInputDevice, out classEnum, 0);
    } else
    {
        hr = devEnum.CreateClassEnumerator(FilterCategory.VideoInputDevice, out classEnum, 0);
    }

    DsError.ThrowExceptionForHR(hr);
    Marshal.ReleaseComObject(devEnum);

    // no enumerators for video/audio input devices
    if (classEnum == null)
    {
        return null;
    }

    IBaseFilter foundFilter = null;
    // enumerate all input devices, looking for one with the desired friendly name
    while(classEnum.Next(moniker.Length, moniker, IntPtr.Zero) == 0)
    {
        Guid iid = typeof(IPropertyBag).GUID;
        object props;
        moniker[0].BindToStorage(null, null, ref iid, out props);
        object currentName;
        (props as IPropertyBag).Read("FriendlyName", out currentName, null);

        if ((string)currentName == deviceName)
        {
            object filter;
            iid = typeof(IBaseFilter).GUID;
            moniker[0].BindToObject(null, null, ref iid, out filter);
            foundFilter = (IBaseFilter)filter;

            Marshal.ReleaseComObject(moniker[0]);
            break;
        }
        Marshal.ReleaseComObject(moniker[0]);
    }

    Marshal.ReleaseComObject(classEnum);
    return foundFilter;
}

/// <summary>
/// Opens the property pages for the filter with the given name
/// </summary>
/// <param name="filter">The filter for which we wish to retrieve and open the property pages</param>
public static void ShowDevicePropertyPages(IBaseFilter filter, IntPtr handle)
{
    // get the ISpecifyPropertyPages for the filter
    ISpecifyPropertyPages pProp = filter as ISpecifyPropertyPages;
    int hr = 0;
    if (pProp == null)
    {
        // if the filter doesn't implement ISpecifyPropertyPages, try displaying IAMVfwCompressDialogs instead
        IAMVfwCompressDialogs compressDialog = filter as IAMVfwCompressDialogs;
        if (compressDialog != null)
        {
            hr = compressDialog.ShowDialog(VfwCompressDialogs.Config, IntPtr.Zero);
            DsError.ThrowExceptionForHR(hr);
        }
        return;
    }

    // get the name of the filter from the FilterInfo struct
    FilterInfo filterInfo;
    hr = filter.QueryFilterInfo(out filterInfo);
    DsError.ThrowExceptionForHR(hr);

    // get the propertypages from the property bag
    DsCAUUID caGUID;
    hr = pProp.GetPages(out caGUID);
    DsError.ThrowExceptionForHR(hr);

    // create and display the OlePropertyFrame
    object[] oDevice = new[] {(object)filter};
    hr = OleCreatePropertyFrame(handle, 0, 0, filterInfo.achName, 1, oDevice,
                                caGUID.cElems, caGUID.ToGuidArray(), 0, 0, 0);
    DsError.ThrowExceptionForHR(hr);

    // release COM objects
    Marshal.FreeCoTaskMem(caGUID.pElems);
    Marshal.ReleaseComObject(pProp);
    if (filterInfo.pGraph != null)
    {
        Marshal.ReleaseComObject(filterInfo.pGraph);
    }
}

[DllImport("oleaut32.dll", CharSet = CharSet.Unicode, ExactSpelling = true)]
static extern int OleCreatePropertyFrame(IntPtr hwndOwner,
    int x,
    int y,
    [MarshalAs(UnmanagedType.LPWStr)] string lpszCaption,
    int cObjects,
    [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 4, ArraySubType = UnmanagedType.IUnknown)] object[] lplpUnk,
    int cPages,
    [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 6)] Guid[] lpPageClsID,
    int lcid,
    int dwReserved,
    int lpvReserved);

用法:

var device = GetDeviceFilterByName(_settingsViewModel.VideoEncoderDevice.Name, EncoderDeviceType.Video);
ShowDevicePropertyPages(device, new HandleRef(ConfigurationDialogHost, 
                    ConfigurationDialogHost.Handle).Handle);