天天看點

定時拍照功能

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

);

*/

public static extern IntPtr SendMessage(

IntPtr hWnd, // handle to destination window

uint Msg, // message

uint wParam, // first message parameter

uint lParam // second message parameter

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);

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");

SendMessage(hwnd, 0x101, 0x1b, 0xc0310001);

tmr.Dispose();

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

使用Remote Spy的方法可參考:

<a href="http://hi.baidu.com/%D0%CF%BD%F2%C8%F0/blog/item/33f8c9170bea01064a90a712.html">http://hi.baidu.com/%D0%CF%BD%F2%C8%F0/blog/item/33f8c9170bea01064a90a712.html</a>

參考:

<a href="http://hi.baidu.com/%D0%CF%BD%F2%C8%F0/blog/item/793132ddef3f28e876c6385f.html/cmtid/6b2f0307824e84c17b8947a2">http://hi.baidu.com/%D0%CF%BD%F2%C8%F0/blog/item/793132ddef3f28e876c6385f.html/cmtid/6b2f0307824e84c17b8947a2</a>

<a href="http://www.christec.co.nz/blog/archives/208">http://www.christec.co.nz/blog/archives/208</a>

     本文轉自xyz_lmn51CTO部落格,原文連結:http://blog.51cto.com/xyzlmn/818933,如需轉載請自行聯系原作者

繼續閱讀