起动摄像头需要执行两次打开的代码以及弹出选择视频设备的窗口

启动摄像头需要执行两次打开的代码以及弹出选择视频设备的窗口

        [DllImport("avicap32.dll")]
        public static extern IntPtr capCreateCaptureWindowA(string lpszWindowName, int dwStyle, int x, int y, int nWidth, int nHeight, IntPtr hWndParent, int nID);
        [DllImport("avicap32.dll")]
        public static extern bool capGetDriverDescriptionA(short wDriver, byte[] lpszName, int cbName, byte[] lpszVer, int cbVer);
        [DllImport("User32.dll")]
        public static extern bool SendMessage(IntPtr hWnd, int wMsg, bool wParam, int lParam);
        [DllImport("User32.dll")]
        public static extern bool SendMessage(IntPtr hWnd, int wMsg, short wParam, int lParam);
        [DllImport("User32.dll")]
        public static extern bool SendMessage(IntPtr hWnd, int wMsg, short wParam, FrameEventHandler lParam);
        [DllImport("User32.dll")]
        public static extern int SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int cx, int cy, int wFlags);
        [DllImport("avicap32.dll")]
        public static extern int capGetVideoFormat(IntPtr hWnd, IntPtr psVideoFormat, int wSize);
        [DllImport("User32.dll")]
        public static extern bool DestroyWindow(int hndw);
这些是CameraBase类里引入视频API的方法


        /// <summary>
        /// 打开摄像头。
        /// </summary>
        public void Open()
        {
            this.fWindowPtr = CameraBase.capCreateCaptureWindowA("0", 0x50000000, 0, 0, this.fWidth, this.fHeight, this.fControlPtr, 0);

            //连接摄像头
            if (this.capDriverConnect(this.fWindowPtr, 0))
            {
                CameraBase.SendMessage(this.fWindowPtr, 0x435, -1, 0);
                this.capPreviewRate(this.fWindowPtr, 66);
                CameraBase.SendMessage(this.fWindowPtr, 0x432, -1, 0);
                this.capPreview(this.fWindowPtr, true);
                CameraBase.SetWindowPos(this.fWindowPtr, 1, 0, 0, this.fWidth, this.fHeight, 6);
                this.fFrameEventHandler = new CameraBase.FrameEventHandler(FrameCallBack);
                this.capSetCallbackOnFrame(this.fWindowPtr, this.fFrameEventHandler);
            }
        }

这里的this.fControlPtr是一个Panel控件的窗口句柄


这个Open方法在我的笔记本上运行的时候,因为笔记本自带有摄像头,如果使用笔记本的摄像头,那么代码执行没有什么问题,但是当外接一个有驱动的摄像头后,使用外接摄像头(笔记本摄像头我已禁用),就需要执行两次Open方法,并且摄像头打开之前还会弹出一个视频源的窗口让选择视频设备,请问这是怎么一回事呢,我提供的代码是否有问题呢?
有遇到过此类问题并有解决方案的朋友帮忙一下,很急,我已经在网上搜了很久,都没有具体的方法~~
------解决方案--------------------
这是因为你使用的是针对Windows 3.x设计的VFW接口
如果你的客户使用Windows 95或者更高版本,建议换DirectShow。
------解决方案--------------------
引用:
这是因为你使用的是针对Windows 3.x设计的VFW接口
如果你的客户使用Windows 95或者更高版本,建议换DirectShow。

++1