Click here to Skip to main content
6,916,824 members and growing! (15,279 online)
Email Password   helpLost your password?
Desktop Development » Dialogs and Windows » Windows Common dialogs     Advanced License: The Code Project Open License (CPOL)

Remote Control of Microsoft FileDialog Class (OpenFileDialog)

By avramik

Remote control of Microsoft FileDialog class (OpenFileDialog)
C# (C#1.0, C#2.0, C#3.0), Windows (WinXP, Vista), .NET (.NET2.0, .NET3.0), Win32, Visual-Studio (VS2005, VS2008), WinForms, Dev
Revision:8 (See All)
Posted:3 Feb 2009
Updated:23 Nov 2009
Views:10,582
Bookmarked:28 times
printPrint Friendly   add Share
      Discuss Discuss   Broken Article?Report  
2 votes for this article.
Popularity: 1.35 Rating: 4.50 out of 5

1

2

3
1 vote, 50.0%
4
1 vote, 50.0%
5

Introduction

If you frequently use a standard File Open Dialog in your program with a big collection of files, you very quickly start missing some default parameters that use them to open with details and order by date.

Background

At this point, if you don't want to rewrite the File Dialog in Visual Studio (2005, 2008) you start searching for an easy solution to this problem. The good examples for such solutions that I found are:

But I did not find how to order by date, or size !!!!!!

So, here is my small solution for this problem.

Using the Code

For this, I found how to remote control columns. The class that contains a column list is a "ListViewRemote".

To call this class, you need to know the Handler that is inside the FileOpenDialog. Here is a small code that you can enter in any form that helps you find the handle.

/// <summary> 
/// this part of code, i took from FileDialogExtender.aspx 
/// </summary> 
/// <param name="m"></param> 
protected override void WndProc(ref Message m)
{
  base.WndProc(ref m);
  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 
      IntPtr SHELLDLL_DefView = Win32.FindWindowEx
			((IntPtr)dialogHandle, 0, "SHELLDLL_DefView", "");
      //send message to SHELLDLL_DefView 
      IntPtr result = Win32.SendMessage(SHELLDLL_DefView, 
			(int)Win32.WM_COMMAND, (int)DialogView, 0);

Now when you get the handle, you can call the ListViewRemote.

      if (DialogView == DialogViewTypes.Details)
      {
        ListViewRemote lvr = new ListViewRemote(SHELLDLL_DefView);
        lvr.SetSortBy((string)sortByComboBox.SelectedItem, 
			(ColumnSort)sortToComboBox.SelectedItem);
      }
  //remember last handle 
  _lastDialogHandle = dialogHandle;
}
}
}

The main idea of the solution is to catch the Header of ListView...

base.AssignHandle(Win32.FindWindowEx
	(SHELLDLL_DefView, 0, "SysListView32", "FolderView"));

IntPtr listViewHeader = Win32.FindWindowEx(listViewHandle, 0, "SysHeader32", "");

... and use the HDITEM as remote control item (and sometimes just generate mouse click).

The code example that I have given in this article is only the first step in how to resolve the problem of the File Dialog of Visual Studio.

History

  • 2/2/2009 First version
    Currently: sort asc and desc in any column of listview and choose what type of listview we need

Wow I did it. :) It's very annoying not to find a solution for such an important thing!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

avramik


Member

Location: Israel Israel

Other popular Dialogs and Windows articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 5 of 5 (Total in Forum: 5) (Refresh)FirstPrevNext
Generalproblem with vista 64 bit Pinmemberhjozi19:15 3 Feb '09  
GeneralRe: problem with vista 64 bit Pinmemberavramik16:33 4 Feb '09  
did you need program for vista only?
GeneralRe: problem with vista 64 bit Pinmemberhjozi20:40 4 Feb '09  
GeneralCorrect link I think... PinmemberTeashirt211:44 3 Feb '09  
AnswerRe: Correct link I think... Pinmemberavramik12:32 3 Feb '09  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+PgUp/PgDown to switch pages.

PermaLink | Privacy | Terms of Use
Last Updated: 23 Nov 2009
Editor: Deeksha Shenoy
Copyright 2009 by avramik
Everything else Copyright © CodeProject, 1999-2010
Web20 | Advertise on the Code Project