using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsMobile.Forms;
using Microsoft.WindowsMobile.PocketOutlook;
using Microsoft.WindowsMobile.Status;

namespace DeviceApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

            #if DEBUG
                MinimizeBox = false;
            #else       
                MinimizeBox = true;
            #endif

                this.butPhotoMake.Enabled = SystemState.CameraPresent;
                this.butRecordVideo.Enabled = SystemState.CameraPresent;
        }

        private string imageFileName;

        private void butPhotoMake_Click(object sender, EventArgs e)
        {
            CameraCaptureDialog cameraCaptureDialog = new CameraCaptureDialog();
            cameraCaptureDialog.Owner = this;
            cameraCaptureDialog.Title = "Фотограф";
            cameraCaptureDialog.Mode = CameraCaptureMode.Still;

            if (cameraCaptureDialog.ShowDialog() == DialogResult.OK &&
               cameraCaptureDialog.FileName.Length > 0)
            {
                pictureBox.Image = new Bitmap
                    (cameraCaptureDialog.FileName);
                MessageBox.Show("Снято!");

            }
        }

        private void butRecordVideo_Click(object sender, EventArgs e)
        {
            CameraCaptureDialog cameraCapture = new CameraCaptureDialog();

            cameraCapture.Owner = null;
            cameraCapture.InitialDirectory = @"\My Documents";
            cameraCapture.DefaultFileName = @"test.3gp";
            cameraCapture.Title = "Камера - Демонстрация";
            cameraCapture.VideoTypes = CameraCaptureVideoTypes.Messaging;
            cameraCapture.Resolution = new Size(176, 144);
            // Лимит в 10 секунд для видео
            cameraCapture.VideoTimeLimit = new TimeSpan(0, 0, 10);
            cameraCapture.Mode = CameraCaptureMode.VideoWithAudio;

            if (DialogResult.OK == cameraCapture.ShowDialog())
            {
                MessageBox.Show(
                    "Картинка или видео успешно записаны в:\n{0}", cameraCapture.FileName);
            }
        }

        private void butSendPhoto_Click(object sender, EventArgs e)
        {
            // Учетная запись и сообщение жестко закодировано для простоты
            MessagingApplication.DisplayComposeForm(
                "ActiveSync", "barsik@cat.ru",
                "От Барсика",
                "Это моя фотка",
                new string[] { this.imageFileName });
        }

        private void butChoosePicture_Click(object sender, EventArgs e)
        {
            SelectPictureDialog selectDialog = new SelectPictureDialog();
            selectDialog.ShowDialog();
            this.imageFileName = selectDialog.FileName;
            this.photoPictureBox.Image = new Bitmap(this.imageFileName);
        }
    }
}