VS2010exp, AutoCAD 2012, Win7
Im my quest to come up with a fix for my openfile dialog,
I am trying to use a pinvoke method that accesses/sets the list view of the win OpenFileDialog control that I have in my form.
So what I accomplish is to set the selected file name in the list so it is the "selected item".
The code at the bottom is supposed to set the view to "Thumbnails" but so far, no joy.
The comment in the method code instructs to:
/// Hash to be called from the overriden WndProc in the parent window of the dialog
This is where I could use some help.
My attempt is not working, everything compiles fine but the open file dialog is not affected upon displaying it.
I am compiling to an AutoCAD net loaded .dll.
public partial class OpenDWGdialog : Form
{
public OpenDWGdialog()
{
InitializeComponent();
}
[STAThread]
static void Main(string[] args)
{
Application.Run(new OpenDWGdialog());
}
protected override void WndProc(ref Message m) //<< this is what I think I am supposed to do.
{
// Letting the Form take care off all messages.
base.WndProc(ref m);
FileDialogExtender.FileDialogExtender flde = new FileDialogExtender.FileDialogExtender(FileDialogExtender.FileDialogExtender.DialogViewTypes.Thumbnails, true);
flde.WndProc(ref m);
}
This is the dialog extension I'm using.
//
// This source file was provided by Robert Rohde via http://www.thecodeproject.com/cs/miscctrl/FileDialogExtender.asp
//
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace FileDialogExtender
{
public class FileDialogExtender
{
#region Enum DialogViewTypes
/// <summary>
/// Ansichtentypen der Listenanzeige von Dateidialogen
/// </summary>
public enum DialogViewTypes
{
/// <summary>
/// Symbole
/// </summary>
Icons = 0x7029,
/// <summary>
/// Liste
/// </summary>
List = 0x702b,
/// <summary>
/// Details
/// </summary>
Details= 0x702c,
/// <summary>
/// Minitauransicht
/// </summary>
Thumbnails= 0x702d,
/// <summary>
/// Kacheln
/// </summary>
Tiles = 0x702e,
}
#endregion
#region Fields
private const uint WM_COMMAND = 0x0111;
private uint _lastDialogHandle = 0;
private DialogViewTypes _viewType;
private bool _enabled;
#endregion
#region DllImports
[DllImport("user32.dll", EntryPoint="SendMessageA", CallingConvention=CallingConvention.StdCall,CharSet=CharSet.Ansi)]
private static extern uint SendMessage(uint Hdc, uint Msg_Const, uint wParam, uint lParam);
[DllImport("user32.dll", EntryPoint="FindWindowExA", CallingConvention=CallingConvention.StdCall,CharSet=CharSet.Ansi)]
private static extern uint FindWindowEx(uint hwndParent, uint hwndChildAfter, string lpszClass, string lpszWindow);
#endregion
#region Constructors & Destructors
public FileDialogExtender() : this(DialogViewTypes.List, false) {}
public FileDialogExtender(DialogViewTypes viewType) : this(viewType, false) {}
public FileDialogExtender(DialogViewTypes viewType, bool enabled)
{
_viewType = viewType;
Enabled = enabled;
}
#endregion
#region Properties
public DialogViewTypes DialogViewType
{
get { return _viewType; }
set { _viewType = value; }
}
public bool Enabled
{
get { return _enabled; }
set { _enabled = value; }
}
#endregion
#region Methods
/// <summary>
/// Hash to be called from the overriden WndProc in the parent window of the dialog
/// </summary>
/// <param name="m"></param>
public void WndProc(ref Message m)
{
if (!_enabled)
return;
if (m.Msg == 289) //Notify of message loop
{
uint dialogHandle = (uint)m.LParam; //handle of the file dialog
if (dialogHandle != _lastDialogHandle) //only when not already changed
{
//get handle of the listview
uint listviewHandle = FindWindowEx(dialogHandle, 0, "SHELLDLL_DefView", "");
//send message to listview
SendMessage(listviewHandle, WM_COMMAND, (uint)_viewType, 0);
// Sending message to the ListBox to select all items.
//SendMessage(listviewHandle, WM_COMMAND, (uint)0x00017021, (uint)0);
//remember last handle
_lastDialogHandle = dialogHandle;
}
}
}
#endregion
}
}