private const uint BM_CLICK = 0xF5; //鼠标点击的消息,对于各种消息的数值,查API手册,也可用VS2010自带的SPY++
[DllImport("user32.dll", EntryPoint = "SendMessage", SetLastError = true, CharSet = CharSet.Auto)]
private static extern int SendMessage(IntPtr hwnd, uint wMsg, IntPtr wParam, int lParam);
//开个线程准备关闭对话框
System.Threading.Thread th = new System.Threading.Thread(new System.Threading.ThreadStart(closevideoprompt));
th.Start();
//线程中关闭对话框的函数
private void closevideoprompt()
{
while (true)
{
System.Threading.Thread.Sleep(100);
IntPtr hWnd = FindWindow(null, "视频源");
//this.textBox1.Text = hWnd.ToString() + "!";
//ShowWindow(hWnd, SW_RESTORE); //将窗口还原
//SetForegroundWindow(hWnd); //如果没有ShowWindow,此方法不能设置最小化的窗口
if (hWnd != IntPtr.Zero)
{
IntPtr hwndSure = FindWindowEx(hWnd, (IntPtr)0, "Button", "确定"); //获取确定按钮的句柄
SendMessage(hwndSure, BM_CLICK, (IntPtr)0, 0); //发送单击消息
}
}
}
//6次不成功就算了
int i = 0 , j = 0;
while (i != 1)
{
i = SendMessage(hHwnd, WM_CAP_DRIVER_CONNECT, iDevice, 0);
System.Threading.Thread.Sleep(100);
j++;
if (j > 6) { MessageBox.Show("请确认视频连接正常!"); th.Abort(); return; }
}
勉强算解决了这个问题。就是开视频时用户还能看到视频源对话框一闪而过
这篇文档对您是否有帮助?