博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
定时拍照功能
阅读量:6897 次
发布时间:2019-06-27

本文共 1831 字,大约阅读时间需要 6 分钟。

CameraCaptureDialog 后必须手动按“确定”然后“退出”,才能拍照, 怎样使用 CameraCaptureDialog 实现自动、定时拍照呢?可以使用System.Windows.Forms.Timer 、SendMessage方法实现,Timer方法必须在主线程中。

 

实现代码:

public partial class Form1 : Form

{
/*
[DllImport("CoreDll")]
public static extern IntPtr FindWindow(
string lpClassName, // class name
string lpWindowName // window name
);
*/
[DllImport("CoreDll")]
public static extern IntPtr SendMessage(
IntPtr hWnd, // handle to destination window
uint Msg, // message
uint wParam, // first message parameter
uint lParam // second message parameter
);

[DllImport("CoreDll")]

public static extern IntPtr GetForegroundWindow();

System.Threading.Timer tmr;

public Form1()

{
InitializeComponent();

}

private void menuItem2_Click(object sender, EventArgs e)

{
Application.Exit();
}

private void menuItem1_Click(object sender, EventArgs e)

{

CameraCaptureDialog ccd = new CameraCaptureDialog();

ccd.Mode = CameraCaptureMode.Still;

object someState = new object();

TimerCallback tmrClbck = new TimerCallback(this.atTimer1);
tmr = new System.Threading.Timer(tmrClbck, someState, 10* 1000, -1);
if (ccd.ShowDialog() == DialogResult.OK)
{
pictureBox1.Image = new Bitmap(ccd.FileName);
//MessageBox.Show("OK");
}
}

private void atTimer1(object state)
{
Debug.WriteLine("Timer 1 On");
IntPtr hwnd = GetForegroundWindow();
SendMessage(hwnd, 0x100, 0x0d, 0xf20001);

object someState = new object();

TimerCallback tmrClbck = new TimerCallback(this.atTimer2);
tmr = new System.Threading.Timer(tmrClbck, someState, 2 * 1000, -1);
//tmr.Dispose();
}

private void atTimer2(object state)

{
Debug.WriteLine("Timer 2 On");
IntPtr hwnd = GetForegroundWindow();
SendMessage(hwnd, 0x101, 0x1b, 0xc0310001);
tmr.Dispose();
}
}

 

程序中发送的 message,不同的 device 不同,需要用 Remote Spy 去抓

使用Remote Spy的方法可参考:

 

参考:

 

     本文转自xyz_lmn51CTO博客,原文链接:http://blog.51cto.com/xyzlmn/818933,如需转载请自行联系原作者

你可能感兴趣的文章
Unity3D Asset文件导出3DMax 可编辑格式
查看>>
Java DES 加解密("DES/ECB/PKCS1Padding")
查看>>
图像滤镜艺术---Swirl滤镜
查看>>
hdu 2842(矩阵高速幂+递推)
查看>>
Servlet、Tomcat访问(access)日志配置、记录Post请求参数
查看>>
bootstrap table 分页只显示分页不显示总页数等数据
查看>>
Tomcat控制台总是打印日志问题的解决办法
查看>>
各种Js插件汇总;JavaScript插件
查看>>
电脑自动关机导致文件丢失怎么办?
查看>>
sublime 安装ctags跳转以及跳转快捷键
查看>>
Hive学习之路 (十八)Hive的Shell操作
查看>>
对"某V皮"N服务器节点的一次后渗透测试
查看>>
Centos7.x 执行top命令教程
查看>>
引体向上高级技巧:停顿式引体向上!
查看>>
C++ 友元类使用 (friend)
查看>>
C#中重写(override)和覆盖(new)的区别
查看>>
Jackson的用法实例分析
查看>>
ios webview下纯JS实现长按
查看>>
数字证书简介及Java编码实现
查看>>
Haproxy安装与配置
查看>>