/// <summary>
        /// Sets up the data structures necessary to display the OpenFileDialog
        /// </summary>
        public InsertImageDialog(string defaultExtension, string directoryName, IWin32Window parent)
        {
            //for thumbnail later
            thumbListener = new ThumbnailReadinessListener(parent.Handle, this);

            // Need two buffers in unmanaged memory to hold the filename
            // Note: the multiplication by 2 is to allow for Unicode (16-bit) characters
            _fileNameBuffer  = Marshal.AllocCoTaskMem(2 * _MAX_PATH);
            _fileTitleBuffer = Marshal.AllocCoTaskMem(2 * _MAX_PATH);
            _directoryBuffer = Marshal.AllocCoTaskMem(2 * _MAX_PATH);

            if (directoryName == String.Empty)
            {
                directoryName = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
            }
            // Zero these two buffers
            byte[] zeroBuffer = new byte[2 * (_MAX_PATH + 1)];
            for (int i = 0; i < 2 * (_MAX_PATH + 1); i++)
            {
                zeroBuffer[i] = 0;
            }
            Marshal.Copy(zeroBuffer, 0, _fileNameBuffer, 2 * _MAX_PATH);
            Marshal.Copy(zeroBuffer, 0, _fileTitleBuffer, 2 * _MAX_PATH);
            Marshal.Copy(zeroBuffer, 0, _directoryBuffer, 2 * _MAX_PATH);

            // copy initial directory name into unmanaged memory buffer
            byte[] directoryBytes = Encoding.Unicode.GetBytes(directoryName);
            Marshal.Copy(directoryBytes, 0, _directoryBuffer, directoryBytes.Length);

            // Create an in-memory Win32 dialog template; this will be a "child" window inside the FileOpenDialog
            // We have no use for this child window, except that its presence allows us to capture events when
            // the user interacts with the FileOpenDialog
            _ipTemplate = BuildDialogTemplate();

            // Populate the OPENFILENAME structure
            // The flags specified are the minimal set to get the appearance and behaviour we need
            _ofn.lStructSize     = Marshal.SizeOf(_ofn);
            _ofn.lpstrFile       = _fileNameBuffer;
            _ofn.nMaxFile        = _MAX_PATH + 1;
            _ofn.lpstrDefExt     = Marshal.StringToCoTaskMemUni(defaultExtension);
            _ofn.lpstrFileTitle  = _fileTitleBuffer;
            _ofn.nMaxFileTitle   = _MAX_PATH + 1;
            _ofn.lpstrInitialDir = _directoryBuffer;
            _ofn.lpstrFilter     = Marshal.StringToCoTaskMemUni(String.Format(CultureInfo.InvariantCulture, "{0} \0*.gif;*.jpg;*.jpeg;*.png\0{1} \0*.*\0\0", Res.Get(StringId.ImagesFilterString), Res.Get(StringId.AllFilesFilterString)));
            _ofn.Flags           = OpenFileNameFlags.HideReadOnly | OpenFileNameFlags.EnableHook |
                                   OpenFileNameFlags.EnableTemplateHandle | OpenFileNameFlags.EnableSizing
                                   | OpenFileNameFlags.Explorer
                                   | OpenFileNameFlags.FileMustExist | OpenFileNameFlags.PathMustExist;

            if (MarketizationOptions.IsFeatureEnabled(MarketizationOptions.Feature.AllowMultiSelectImage))
            {
                _ofn.Flags |= OpenFileNameFlags.AllowMultiSelect;
            }

            _ofn.hInstance = _ipTemplate;
            string title = String.Format(CultureInfo.InvariantCulture, "{0}\0\0", Res.Get(StringId.InsertPicture));

            _ofn.lpstrTitle = Marshal.StringToCoTaskMemUni(title);
            _ofn.lpfnHook   = new OfnHookProc(MyHookProc);
            _ofn.hwndOwner  = parent.Handle;
        }
        /// <summary>
        /// Sets up the data structures necessary to display the OpenFileDialog
        /// </summary>
        public InsertImageDialog(string defaultExtension, string directoryName, IWin32Window parent)
        {
            //for thumbnail later
            thumbListener = new ThumbnailReadinessListener(parent.Handle, this);

            // Need two buffers in unmanaged memory to hold the filename
            // Note: the multiplication by 2 is to allow for Unicode (16-bit) characters
            _fileNameBuffer = Marshal.AllocCoTaskMem(2 * _MAX_PATH);
            _fileTitleBuffer = Marshal.AllocCoTaskMem(2 * _MAX_PATH);
            _directoryBuffer = Marshal.AllocCoTaskMem(2 * _MAX_PATH);

            if (directoryName == String.Empty)
            {
                directoryName = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
            }
            // Zero these two buffers
            byte[] zeroBuffer = new byte[2 * (_MAX_PATH + 1)];
            for (int i = 0; i < 2 * (_MAX_PATH + 1); i++) zeroBuffer[i] = 0;
            Marshal.Copy(zeroBuffer, 0, _fileNameBuffer, 2 * _MAX_PATH);
            Marshal.Copy(zeroBuffer, 0, _fileTitleBuffer, 2 * _MAX_PATH);
            Marshal.Copy(zeroBuffer, 0, _directoryBuffer, 2 * _MAX_PATH);

            // copy initial directory name into unmanaged memory buffer
            byte[] directoryBytes = Encoding.Unicode.GetBytes(directoryName);
            Marshal.Copy(directoryBytes, 0, _directoryBuffer, directoryBytes.Length);

            // Create an in-memory Win32 dialog template; this will be a "child" window inside the FileOpenDialog
            // We have no use for this child window, except that its presence allows us to capture events when
            // the user interacts with the FileOpenDialog
            _ipTemplate = BuildDialogTemplate();

            // Populate the OPENFILENAME structure
            // The flags specified are the minimal set to get the appearance and behaviour we need
            _ofn.lStructSize = Marshal.SizeOf(_ofn);
            _ofn.lpstrFile = _fileNameBuffer;
            _ofn.nMaxFile = _MAX_PATH + 1;
            _ofn.lpstrDefExt = Marshal.StringToCoTaskMemUni(defaultExtension);
            _ofn.lpstrFileTitle = _fileTitleBuffer;
            _ofn.nMaxFileTitle = _MAX_PATH + 1;
            _ofn.lpstrInitialDir = _directoryBuffer;
            _ofn.lpstrFilter = Marshal.StringToCoTaskMemUni(String.Format(CultureInfo.InvariantCulture, "{0} \0*.gif;*.jpg;*.jpeg;*.png\0{1} \0*.*\0\0", Res.Get(StringId.ImagesFilterString), Res.Get(StringId.AllFilesFilterString)));
            _ofn.Flags = OpenFileNameFlags.HideReadOnly | OpenFileNameFlags.EnableHook |
                         OpenFileNameFlags.EnableTemplateHandle | OpenFileNameFlags.EnableSizing
                         | OpenFileNameFlags.Explorer
                         | OpenFileNameFlags.FileMustExist | OpenFileNameFlags.PathMustExist;

            if (MarketizationOptions.IsFeatureEnabled(MarketizationOptions.Feature.AllowMultiSelectImage))
            {
                _ofn.Flags |= OpenFileNameFlags.AllowMultiSelect;
            }

            _ofn.hInstance = _ipTemplate;
            string title = String.Format(CultureInfo.InvariantCulture, "{0}\0\0", Res.Get(StringId.InsertPicture));
            _ofn.lpstrTitle = Marshal.StringToCoTaskMemUni(title);
            _ofn.lpfnHook = new OfnHookProc(MyHookProc);
            _ofn.hwndOwner = parent.Handle;
        }