/*=============================================================================
Project: SharpImage
Module: siOpenImageDialog.cs
Language: C#
Author: Dan Mueller
Date: $Date: 2007-07-06 10:57:00 +1000 (Fri, 06 Jul 2007) $
Revision: $Revision: 2 $
Copyright (c) Queensland University of Technology (QUT) 2007.
All rights reserved.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=============================================================================*/
using System;
using System.Data;
using System.Text;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace SharpImage.Main
{
class siOpenImageDialog : siImageDialog
{
#region Construction and Disposal
//=====================================================================
public siOpenImageDialog()
{
this.m_Title = "Open image";
}
//=====================================================================
#endregion
#region Public Methods
//=====================================================================
///
/// Show the dialog.
///
/// The parent form.
///
public override DialogResult ShowDialog(Form parent)
{
// Create OFN struct and populate
OPENFILENAME ofn = new OPENFILENAME();
ofn.lStructSize = Marshal.SizeOf(ofn);
ofn.lpstrFilter = this.Filter.Replace('|', '\0') + '\0';
ofn.nFilterIndex = this.FilterIndex;
ofn.lpstrFile = this.FileName + new string(' ', 512);
ofn.nMaxFile = ofn.lpstrFile.Length;
ofn.lpstrFileTitle = System.IO.Path.GetFileName(this.FileName) + new string(' ', 512);
ofn.nMaxFileTitle = ofn.lpstrFileTitle.Length;
ofn.lpstrTitle = this.Title;
ofn.lpstrDefExt = this.DefaultExt;
ofn.hwndOwner = parent.Handle;
// Set the parent
this.m_Parent = parent;
// Set flags
// TODO: enable user to set these
ofn.Flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOTESTFILECREATE | OFN_HIDEREADONLY | OFN_ENABLEHOOK;
// Set hook using delegate as C function ptr
ofn.lpfnHook = new OFNHookProcDelegate(this.HookProc);
// Show the dialog
if (!GetOpenFileName(ref ofn))
{
int ret = CommDlgExtendedError();
if (ret != 0)
throw new ApplicationException("Could not show dialog. Error code:" + ret.ToString());
return DialogResult.Cancel;
}
// Save the filename and return
this.FileName = ofn.lpstrFile;
return DialogResult.OK;
}
//=====================================================================
#endregion
}
}