CWnd* pParent= GetParent();
CWnd* pw= pParent->GetDlgItem( 0x0461 ); // SHELLDLL _DefView
...should get you the right window. Even knowing all of that, you are likely to run into strange problems -- the embedded target window doesn't exist when you expect it to. For instance, if you try to obtain the desired HWND in an OnDialogInit handler or an override of CFileDialog::OnInitDone, it will basically say "
Huh?" -- the window has not been created yet.
#pragma once
// CFileDlgEx
class CFileDlgEx : public CFileDialog
{
DECLARE_DYNAMIC(CFileDlgEx)
public:
CFileDlgEx(BOOL bOpenFileDialog, // TRUE for FileOpen, FALSE for FileSaveAs
LPCTSTR lpszDefExt = NULL,
LPCTSTR lpszFileName = NULL,
DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
LPCTSTR lpszFilter = NULL,
CWnd* pParentWnd = NULL);
virtual ~CFileDlgEx();
typedef enum { // enumerated values for WM_COMMAND wParam
VwNone= 0,
VwIcons= 0x7029,
VwList= 0x702b,
VwDetails= 0x702c,
VwTiles= 0x702e,
VwThumbnails= 0x7031,
} ViewType;
typedef enum {
ByNone= 0,
ByName= 0x7602,
BySize= 0x7603,
ByType= 0x7604,
ByModified= 0x7605,
ByAttributes= 0x7608, // note, there are others...
} SortBy;
virtual void OnFileNameChange( ); // the only member override
ViewType m_eView; // some new class variables
SortBy m_eSort;
bool m_fSortDescending;
protected:
bool m_fFirstPass;
DECLARE_MESSAGE_MAP()
};
The
FileDlgEx CPP file:
// FileDlgEx.cpp : implementation file
//
#include "stdafx.h"
#include "FileDlgEx.h"
IMPLEMENT_DYNAMIC(CFileDlgEx, CFileDialog)
CFileDlgEx::CFileDlgEx(BOOL bOpenFileDialog, LPCTSTR lpszDefExt, LPCTSTR lpszFileName,
DWORD dwFlags, LPCTSTR lpszFilter, CWnd* pParentWnd) :
CFileDialog(bOpenFileDialog, lpszDefExt, lpszFileName, dwFlags, lpszFilter, pParentWnd)
{
m_eSort= ByNone; // initialize our added variables
m_eView= VwNone;
m_fSortDescending= false;
m_fFirstPass= true;
}
CFileDlgEx::~CFileDlgEx(){}
BEGIN_MESSAGE_MAP(CFileDlgEx, CFileDialog)
END_MESSAGE_MAP()
void CFileDlgEx::OnFileNameChange()
{
CFileDialog::OnFileNameChange();
if ( !m_fFirstPass ) {
return;
}
m_fFirstPass= false;
CWnd* pParent= GetParent();
CWnd* pw= pParent->GetDlgItem( 0x0461 ); // SHELLDLL _DefView
if ( ! IsWindow(*pw) ) { // Failsafe (for Vista?)
return;
}
if ( m_eView ) { // set the View type
pw->SendMessage( WM_COMMAND, m_eView, 0 );
}
if ( m_eSort ) {
if ( m_eView != VwDetails ) { // others are always ascending
pw->SendMessage( WM_COMMAND, m_eSort, 0 );
return;
}
// -- here's the trick to "toggle" to desired sort order
pw->SendMessage( WM_COMMAND, ByAttributes, 0 );
if ( m_fSortDescending ) { // just do it twice
pw->SendMessage( WM_COMMAND, m_eSort, 0 );
}
pw->SendMessage( WM_COMMAND, m_eSort, 0 );
}
}
void CFileDlgEx_testerDlg::OnBnClickedButton1()
{
CString sFilters="All Files (*.*)|*.*||";
CFileDlgEx cDlg(TRUE, 0,0,0,sFilters );
cDlg.GetOFN().lpstrInitialDir= "C:\\temp\\testFileDlgEx";
cDlg.m_eView= CFileDlgEx::VwDetails;
cDlg.m_eSort= CFileDlgEx::ByType;
cDlg.m_fSortDescending= true;
int n= cDlg.DoModal();
if ( n==IDOK ) {
MessageBox( cDlg.GetPathName(), "Result" );
}
}
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (7)
Commented:
When in the open/save dialog, right click and arrange by name/type/modified/..., then hold the Ctrl key and X out of the dialog box. Every time you use it, from closing out forward, it will present the setting you closed out with.
Commented:
Commented:
I do not want to use the explorer style of CFileDialog. I need to achieve the above functionality in Old Style CFileDialog.
I have tried the following way:
When user enters any text in search field, we invoke a event handler through which search results will be displayed in the list control of CFileDialog.
Retrieve the list control and delete all elements which do not match with search input.
Open in new window
But somwhow it always deletes the last element irrespective of the index i pass.
Is there anyway i can get this work as i required.
Thanks
Author
Commented:-- Dan
BTW, the best way to get an answer here at EE is to ask a question in the regular Q/A section rather than in an Article comment.
Commented:
As you mentioned. I will put it up as a seperate question
View More