|
Hello, I would like to ask c# how to use the above function
|
|
|
|
|
CSelectDialog ofd( TRUE, _T("*.*"), NULL,
OFN_HIDEREADONLY ,
_T("Show Folders Only|.|") );
|
|
|
|
|
Hello,
I have tried running the SelectDialogTest.exe and it's working well. But when I compiled it using VS2010/2013 it compiles fine and after clicking the browse button and select files then click okay, the SelectDialog.cpp line 50 gets the "Access violation writing location 0x00000020".
Is there an additional setting for it to run well in VS? I am using Windows 7 by the way. Thanks.
|
|
|
|
|
GetParent() is returning NULL. I see the same with VS2013 on Win7.
You can fix the problem by setting bVistaStyle to FALSE. I did this by adding the dwSize and bVistaStyle arguments to the CSelectDialog constructor, with a default value of FALSE for bVistaStyle, and passing them through to the superclass. (Note something may be off in the project dependencies -- I had to use "rebuild project" when experimenting with switching the vista style on and off.)
This does leave you with an older style of file dialog though.
modified 25-Nov-14 18:39pm.
|
|
|
|
|
Found the following code in afxdlgs.h
explicit CFileDialog(BOOL bOpenFileDialog,
LPCTSTR lpszDefExt = NULL,
LPCTSTR lpszFileName = NULL,
DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
LPCTSTR lpszFilter = NULL,
CWnd* pParentWnd = NULL,
DWORD dwSize = 0,
BOOL bVistaStyle = TRUE);
virtual ~CFileDialog();
and changed bVistaStyle to false - needed to run VS as Admin to save changes in this include file and rebuild all
Now I have the problem that the dropdown listing all the files in the folder almost obscures the select button on the main form but I can't see how to change the anything about that screen to deal with that problem. Is it possible to fix it?
modified 28-Aug-15 20:43pm.
|
|
|
|
|
Hi!
Very useful utility, thanks!
I have a small issue though, if you use the quick links on the left, sometimes the app fail to grab the current directory and set it to an empty string instead. It's still ok when you click MyComputer or Desktop, but it fails if you click Libraries. Any idea why?
I ran it as is on VisualStudio 2010.
|
|
|
|
|
It appears that you can get the actual path by sending CDM_GETFOLDERIDLIST to the parent dialog. This doesn't work when the current directory is a "virtual" folder, like Libraries or Computer, because there is no filesystem path to them. It does work for Desktop, My Documents, and so on, while GetFolderPath() (and CDM_GETFOLDERPATH) does not.
So it's not perfect, but it's an important step up.
For example, try putting this in OnFolderChange() (use your favorite debug macro in place of LOGD):
void SelectFilesDialog2::OnFolderChange()
{
CString path = GetFolderPath();
LOGD("Current folder now '%ls'", (LPCWSTR) path);
CWnd* pParent = GetParent();
LRESULT len = pParent->SendMessage(CDM_GETFOLDERIDLIST, 0, NULL);
if (len <= 0) {
LOGW("Can't get folder ID list, len is %d", len);
} else {
LPCITEMIDLIST pidlFolder = (LPCITEMIDLIST) CoTaskMemAlloc(len);
len = pParent->SendMessage(CDM_GETFOLDERIDLIST, len,
(LPARAM) pidlFolder);
ASSERT(len > 0);
WCHAR buf[MAX_PATH];
BOOL result = SHGetPathFromIDList(pidlFolder, buf);
if (result) {
LOGI("Current folder is really '%ls'", buf);
} else {
LOGI("Current folder has no path");
}
CoTaskMemFree((LPVOID) pidlFolder);
}
}
|
|
|
|
|
|
hi? how to use it in vc6.0? thanks!
|
|
|
|
|
But executable has no functionality:
1. "Multiple" select will highlight more than one file in the open dialog.
2. textbox actually fills with the highlighted items -> "x" "y" "z" "aa" etc.
3. items remain highlighted there but the button "Open" causes complete freeze.
4. "Cancel" will dismiss the opn dialog but the original dialog can't be closed by any method.
5. Must open task manager to shutdown frozen application.
|
|
|
|
|
Working on a project with XP, this was working great.
Before project completion I switched to Windows 7 and suddenly
SelectDialog crashes in CSelectDialog::OnFileNameOK()
because GetParent() returns NULL.
Don't know MFC that much, so I can't estimate whether something has changed
with Win7.
MSDN says
When you are using the Windows Vista style of the CFileDialog, you cannot use message maps and dialog templates. Instead, you will need to use the COM interfaces for similar functionality.
I set VistaStyle to false as suggested, but maybe it does default to true in win7.
Has anyone tested this with Windows 7 and could share it?
|
|
|
|
|
Hi,
I removed my message from yesterday as looking into this further, and using the original code as is, I cannot fault it on any version of windows 7 or 2008, it seems to work fine.
|
|
|
|
|
Hi everybody
I tested attached demo in Win 7 and saw that everything is fine except in new special folders such as Library and My docs(folders are not selected and path is not full from root).
I would try to solve it as soon as possible after I recover my deleted partitions!!!
|
|
|
|
|
Hi!
I am also coding a utility based on the CFileDialog using MFC and VS2010. But for me too, when browsing using the virtual folders (Libraries, MyDoc,...) I can not recover the current directory. (GetFolderPath(); returns an empty string)
Did you by any chance find a way to fix this?
|
|
|
|
|
As mentioned by some users OnInitDone function does not works in Win7 so we should add two new parameters at the end of constructor as shown below:
CSelectDialog(
BOOL bOpenFileDialog,
LPCTSTR lpszDefExt,
LPCTSTR lpszFileName,
DWORD dwFlags,
LPCTSTR lpszFilter,
CWnd* pParentWnd)
:CFileDialog(
bOpenFileDialog,
lpszDefExt,
lpszFileName,
dwFlags | OFN_EXPLORER | OFN_HIDEREADONLY &(~OFN_SHOWHELP),
lpszFilter,
pParentWnd,
0, FALSE)
|
|
|
|
|
Well, it's been some time since I posted this,
but thx, that did the trick.
I had just passed one more parameter instead of two
Now it works as expected.
|
|
|
|
|
I just downloaded and ran the demo project and it's exactly what I need. However, I'm coding in C#. Would this project be possible in C#?
Thank you...very nice work!
|
|
|
|
|
I think a lot of people could use this in c# ... help is welcome
|
|
|
|
|
Dear Hojjat Bohlooli
When I ran the demoproject, I found it only lists 16 files and the last file that I selected. It can not show all the selected files. How do I conquer this problem ?
Best Reguards
Jiann-Tsair Chang
Nov. 10, 2009
Be Happy Every Day.
|
|
|
|
|
Hi sir
add below code to CSelectDialogTestDlg::OnBrowse
///
ofd.m_ofn.nMaxFile = MAXFILE;
char *pTotalLen = new char[MAXFILE];
ofd.m_ofn.lpstrFile = pTotalLen;
ofd.m_ofn.lpstrFile[0] = NULL;
.
.
.
if( ofd.DoModal() != IDOK )
{
delete []pTotalLen;
return;
}
.
.
.
delete []pTotalLen;
///
maybe solve the problem.
|
|
|
|
|
I found the problem
change the MAX_PATH in the CSelectDialog::WindowProcNew function in line
pDlg->SendMessage(CDM_GETSPEC, (WPARAM)MAX_PATH, ...
to a integer variable with big value such as 10240.
e.g.
int ilen = 10240;
pDlg->SendMessage(CDM_GETSPEC, (WPARAM)ilen, ...
the mentioned problem will be solve.
regards.
|
|
|
|
|
This function doesn't work correctly, when you select multiple files and the file extensions of known file types are hidden in the Explorer settings.
Here ist my corrected while loop (Line 156) in the SelectDialog.cpp:
<br />
<br />
while((nSelected--) > 0)<br />
{<br />
strItemText = wndLst1->GetItemText(nItem,1);<br />
strItemText = strDirectory + strItemText;<br />
int pos=-2;<br />
if (fileslist.Find(_T("\""),0)!=-1)<br />
{<br />
pos=fileslist.Find(_T("\"") + strItemText.Right(strItemText.GetLength() - 3) + _T("."),0);<br />
}<br />
else<br />
{<br />
pos=fileslist.Find(strItemText.Right(strItemText.GetLength() - 3) + _T("."),0);<br />
}<br />
DWORD attr = GetFileAttributes(strItemText);<br />
if((attr != 0xFFFFFFFF) && (attr & FILE_ATTRIBUTE_DIRECTORY) && (pos==-1))<br />
m_SelectedItemList.Add(strItemText);<br />
nItem = wndLst1->GetNextItem(nItem, LVNI_SELECTED);<br />
}<br />
|
|
|
|
|
The sample you provided works as stated on XP and Vista when compiled using VS2005 - as how your sample is supplied. However, if you compile using VS2008, XP still works fine, but nothing works on Vista.
On Vista, the dialog control changes do not take and no items are returned in the resulting multi-select list.
Are you planning to update the project to work correctly with VS2008 and Vista?
Thanks,
Peter
|
|
|
|
|
Problem is with OnInitDone() function.
MS says here http://msdn.microsoft.com/de-de/library/77x9ftyf.aspx
Windows Vista style file dialogs do not support this function. Attempting to use this function on a Windows Vista style file dialog will throw CNotSupportedException. See CFileDialog Class for more information.
Both the appearance and the functionality of the CFileDialog with Windows Vista differ from the earlier versions of Windows. The default CFileDialog automatically uses the new Windows Vista style without code changes if a program is compiled and run under Windows Vista. Use the bVistaStyle parameter in the constructor to manually override this automatic update. The exception to the automatic update is customized dialog boxes. They will not be converted to the new style. For more information about the constructor, see CFileDialog::CFileDialog.
So, if you still want to use this functionality, just put bVistaStyle to FALSE in the constructor.
CSelectDialog(BOOL bOpenFileDialog, // TRUE for FileOpen, FALSE for FileSaveAs
LPCTSTR lpszDefExt = NULL,
LPCTSTR lpszFileName = NULL,
DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT |
OFN_EXPLORER & (~OFN_SHOWHELP),
LPCTSTR lpszFilter = NULL,
CWnd* pParentWnd = NULL,
DWORD dwSize = 0,
BOOL bVistaStyle = FALSE);
|
|
|
|
|
I've attempted to add the bVistaStyle flag, but the dialog still doesn't want to play.
Has anyone got this working for vista & VS2008? If so could they post a revised version.
|
|
|
|