|
Since the design of the windows changed in visual studio 2010, we have a crash in function
BOOL CWnd::IsDialogMessage(LPMSG lpMsg)
of winocc.cpp file:
Unhandled exception at 0x7700477b in ####.exe: 0xC0150010
the buttons are also over the listview so you can't click on them.
|
|
|
|
|
ok, to avoid crash, just update the constructor code in selectfolderdialog.cpp:
: CFileDialog(TRUE, NULL,
(bShowFilesInDir)? ((lpszFilter)? NULL : "*.*") : _T("*..*"),
dwFlags, lpszFilter, pParentWnd, 0, FALSE)
This code set bVistaStyle to false, so that the "OnInitDone" notification can be fired.
The drawback is that you lose the vistastyle window.
|
|
|
|
|
I Got an Exception when using SelectFolder dialog in visual c++ 2005
Any one has a solution to this problem??
|
|
|
|
|
hi Salimon,
Haven't checked this code for a long time
Check the reply by "Rail Jon Rogut" if that helps...
Sridhar
|
|
|
|
|
Hi colleague!
Your FolderDlg class was EXACTLY what I was looking for!
Easy to use, really understandable, great coding technique... what else can I say!
It's one of the best documented and useful article I've ever seen.
Thanks a lot for your help!
|
|
|
|
|
We have included this class into an app that has been working for a couple of years now without error. After converting to VS2005, I get an error in the same area that has been mentioned in other posts. That error is an exception on CRect
Within:
OnInitDone()
rectCurrFolderEB;
pFD->GetDlgItem(edt1)->GetWindowRect(rectCurrFolderEB);
GetWindowRect tries to use edt1 to get it's rectangle and I get an assert because it is a value of 0x000000!
It seems that the object is not being created yet, (the dialog doesn't seem to be fully built) but I see no other message handler function that I can use since OnInitDone() is supposed to be after everthing is built and ready...
I have the latest edition that you have on this site and it seems to only be because of the conversion of VS 6.0 to VS2005.
Do you have any fixes?
Modified: I just was able to find the fix that you posted concerning non-function of OnInitDone() in WinXP and I tried it. It seems to work just fine. Thanks for that. Could you please incorporate those changes into your most recent version?
Regards,
David
-- modified at 17:25 Wednesday 7th March, 2007
|
|
|
|
|
I really like this Class! I appreciate the work done by anyone associated with it. I have found that it blows up if it has been created in a library and linked to by the app. I have not found the reason why, just that it fails. I will attempt to find the problem later and post it.
Thanks again!
David Leikis
ATK Thiokol Propulsion
|
|
|
|
|
When typing a wrong folder name in the Current Folder Edit Control, the CALLBACK WindowProcNew function asks if we want to create this folder since it doesn't exist. If we click No, it will remember the wrong file name and the DoModal will return IDOK.
Since my program assumes the folder path is OK when DoModal returns IDOK, I get a wrong folder name. The patch I made is to set the edit control ES_READONLY so the user won't type a wrong folder name, but I wondered if there would be a more elegant way to never get the wrong folder path?
Thanks in advance,
Véronique
|
|
|
|
|
In the WindowProcNew function, simply add the change as follows:
//If path does not exist
if(_access(cstrPath, 00) != 0)
{
if(AfxMessageBox(cstrPath + "\n" + "\n" +
"This path does not exist. Do you want to create it?",
MB_YESNO | MB_ICONQUESTION) == IDYES)
{
// MakeSureDirectoryPathExists(cstrPath + "\\");
CheckPath(&cstrPath, TRUE);
if(_access(cstrPath, 00) != 0)
{
AfxMessageBox((CString)"Could not create folder:" + "\n" + cstrPath);
return NULL;
}
}
else ////// Add this
{
return NULL;
}
}
Rail
-- modified at 15:37 Tuesday 22nd November, 2005
|
|
|
|
|
The method pFD->GetDlgItem(edt1)
returns NULL which causes a crash later on.
The dialog control with id == edt1 == 1152 does not seem to exist.
Any hint?
|
|
|
|
|
I added some code to the function OnInitDone which should fix it for you... (I've also changed the formatting to make the code more readable)
void CSelectFolderDialog::OnInitDone()
{
BOOL bXPType = FALSE;
int topVal = 12;
CWnd* pFD = GetParent();
CWnd *wndTemp;
wndTemp = pFD->GetDlgItem(edt1);
if (!wndTemp)
{
bXPType = TRUE;
topVal = 4;
}
CRect rectCancelPB;
pFD->GetDlgItem(IDCANCEL)->GetWindowRect(rectCancelPB);
pFD->ScreenToClient(rectCancelPB);
CRect rectOKPB;
pFD->GetDlgItem(IDOK)->GetWindowRect(rectOKPB);
pFD->ScreenToClient(rectOKPB);
pFD->GetDlgItem(IDOK)->SetWindowPos(0,rectCancelPB.left - rectOKPB.Width() - 4, rectCancelPB.top, 0,0, SWP_NOZORDER | SWP_NOSIZE);
CRect rectList2LC;
pFD->GetDlgItem(lst1)->GetWindowRect(rectList2LC);
pFD->ScreenToClient(rectList2LC);
pFD->GetDlgItem(lst1)->SetWindowPos(0,0,0,rectList2LC.Width(), abs(rectList2LC.top - (rectCancelPB.top - 45)) + 25, SWP_NOMOVE | SWP_NOZORDER);
SetControlText(IDOK, _T("Select"));
pFD->SetWindowText(_T(m_cstrTitle));
m_wndProc = (WNDPROC)SetWindowLong(pFD->m_hWnd, GWL_WNDPROC, (LONG)WindowProcNew);
CRect rectstc3ST;
pFD->GetDlgItem(stc3)->GetWindowRect(rectstc3ST);
pFD->ScreenToClient(rectstc3ST);
pFD->GetDlgItem(stc3)->SetWindowText("Folder name");
pFD->GetDlgItem(stc3)->SetWindowPos(0, rectstc3ST.left, rectstc3ST.top + topVal, rectstc3ST.Width() + 20, rectstc3ST.Height(), SWP_NOZORDER);
if (bXPType)
{
wndTemp = pFD->GetDlgItem(cmb13);
HideControl(cmb13);
topVal = 26;
}
else
{
HideControl(edt1);
topVal = 30;
}
CRect rectCurrFolderEB;
wndTemp->GetWindowRect(rectCurrFolderEB);
pFD->ScreenToClient(rectCurrFolderEB);
rectCurrFolderEB.left = rectstc3ST.left;
rectCurrFolderEB.right -= 70;
rectCurrFolderEB.top += topVal;
rectCurrFolderEB.bottom += topVal;
m_pEdit = new CEdit();
m_pEdit->Create(WS_TABSTOP | WS_VISIBLE | WS_CHILD,
rectCurrFolderEB, pFD, IDEB_FOLDER_DIALOG_SEL_FOLDER);
m_pEdit->SetWindowText(m_ofn.lpstrInitialDir);
m_pEdit->SetFont(pFD->GetDlgItem(cmb2)->GetFont());
m_pEdit->ModifyStyleEx(0, WS_EX_CLIENTEDGE, SWP_DRAWFRAME);
m_pEdit->SetWindowPos(pFD->GetDlgItem(lst1), 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
if(!m_bShowFilesInDir || (m_ofn.lpstrFilter == NULL) || (strlen(m_ofn.lpstrFilter) == 0))
{
HideControl(stc2);
HideControl(cmb1);
}
if(m_bShowFilesInDir && (m_ofn.lpstrFilter != NULL) && (strlen(m_ofn.lpstrFilter) != 0))
{
CRect rectDialog;
pFD->GetWindowRect(rectDialog);
rectDialog.bottom += 35;
pFD->SetWindowPos(0, 0, 0, rectDialog.Width(), rectDialog.Height(), SWP_NOZORDER | SWP_NOMOVE);
CRect rectST;
pFD->GetDlgItem(stc2)->GetWindowRect(rectST);
pFD->ScreenToClient(rectST);
rectST.top += 25;
rectST.bottom += 25;
pFD->GetDlgItem(stc2)->SetWindowPos(0, rectST.left, rectST.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
CRect rectComboDL;
pFD->GetDlgItem(cmb1)->GetWindowRect(rectComboDL);
pFD->ScreenToClient(rectComboDL);
rectComboDL.left = rectST.left;
rectComboDL.top = rectST.top + rectST.Height();
rectComboDL.bottom = rectST.bottom + rectST.Height();
pFD->GetDlgItem(cmb1)->SetWindowPos(0, rectComboDL.left, rectComboDL.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
pFD->GetDlgItem(IDCANCEL)->GetWindowRect(rectCancelPB);
pFD->ScreenToClient(rectCancelPB);
rectCancelPB.top = rectST.bottom - 2;
rectCancelPB.bottom = rectCancelPB.top + rectCancelPB.Height();
pFD->GetDlgItem(IDCANCEL)->SetWindowPos(0, rectCancelPB.left, rectCancelPB.top, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
pFD->GetDlgItem(IDOK)->GetWindowRect(rectOKPB);
pFD->ScreenToClient(rectOKPB);
pFD->GetDlgItem(IDOK)->SetWindowPos(0,rectCancelPB.left - rectOKPB.Width() - 4, rectCancelPB.top, 0,0, SWP_NOZORDER | SWP_NOSIZE);
rectCurrFolderEB.right = rectCancelPB.right;
m_pEdit->SetWindowPos(pFD->GetDlgItem(lst1), 0, 0, rectCurrFolderEB.Width(), rectCurrFolderEB.Height(), SWP_NOMOVE | SWP_NOZORDER);
}
pFD->CenterWindow();
}
Rail
|
|
|
|
|
It's the function SHBrowseForFolder()
, MSDN
|
|
|
|
|
This is far superior to SHBrowseForFolder().
Excellent code, exactly what I was looking for.
Thanks.
|
|
|
|
|
Hallo,
is it possible to disable the "Create-Folder" functionality?
Regards,
Thomas Moch
|
|
|
|
|
|
Is there a multiple directory selection possible?
|
|
|
|
|
I have a fixed size dialog.
I have list of tree items on the left view and when I click one of the nodes I want to display the dialog in the right view
with the condition that if the size of the dialog is bigger than the view then I'll have to provide the scroll bars to navigate.
I don't want to change the size of the dialogs at all.
My dialogs are all modal dialogs. I'm using splitter window to create two separate view.
Left side is the tree view and right side is the form view.
I want all my controls in the dialog in tact.
My view on the right side is a form view.
Can you provide some help regarding this.
Thanks
|
|
|
|
|
Folks, how do I use this
dialog *without* mouse?
When I press Enter, the
current directory gets
returned. No keypress can
make it change directory.
|
|
|
|
|
You need to start double '\' finding at index 2 in order to allow networks names like \\mycomp\c\...
Change
modify line #128 in SelectFolderDialog.cpp, starting i at 2 :
for (int i = 2; i < cstrPath.GetLength() - 1; i++)
However, thanks a lot for your code.
manu vanneau
|
|
|
|
|
Thank you guys (guess you know your names, I've forgotten them right now) for the code, and thank you, manu vanneau, for the hint, how to make the code accept network names. There is another problem which occurs selecting network folders. Objects like the "network environment" or computers, which are displayed in the dialog like folders may be selected, but do not possess a folder name. If you doubleclick for example the "network environment" and afterwards click the select button, this causes an unhandled exception.
You can solve the problem by replacing the code within the Method OnFolderChange() by the lines
if(::IsWindow(GetParent()->m_hWnd))
{
CString FolderPath = GetFolderPath();
int length = FolderPath.GetLength();
if(length >0)
m_pEdit->SetWindowText(FolderPath);
}
If you doubleclick an invalid symbol (such as the "network environment") the funcion GetFolderPath() returns an empty string. With my few lines, I prevent the Edit Control's text to be replaced by this empty string and thus causing an exception. With the modifies code, you select the last valid folder, whose path still ist in the edit control.
Thomas
|
|
|
|
|
Slight modification to this solution is given below. The modification diables the selection button if the folder is invalid.
void CSelectFolderDialog::OnFolderChange()
{
if(::IsWindow(GetParent()->m_hWnd)) {
CWnd* pFD = GetParent();
CString FolderPath = GetFolderPath();
if(FolderPath.IsEmpty()) {
pFD->GetDlgItem(IDOK)->EnableWindow(FALSE);
m_pEdit->SetWindowText(_T("Invalid Folder"));
}
else {
pFD->GetDlgItem(IDOK)->EnableWindow(TRUE);
m_pEdit->SetWindowText(FolderPath);
}
}
}
|
|
|
|
|
You should add the ES_AUTOHSCROLL style to the CEdit control's styles. Otherwise a long directory name will not scroll properly:
SelectFolderDialog.cpp, Line 205:
m_pEdit->Create(WS_TABSTOP | WS_VISIBLE | WS_CHILD | ES_AUTOHSCROLL,
rectCurrFolderEB, pFD, IDEB_FOLDER_DIALOG_SEL_FOLDER);
Brett Kapilik
|
|
|
|
|
Unfortunately I cannot test my app on these Windows versions at the moment. Does anyone know if this code is safe ?
Thanks
Jerry.
P.S. This is very useful code.
|
|
|
|
|
I had developed this code on WinNT (service pack 4.0), so i'm also not too sure whether they do work on other windows operating systems
|
|
|
|
|
Almost.....
The buttons to the right of the combo box at the top, are different. In Win98 one of these buttons is a desktop button. It looks a bit wierd having a desktop button there and another on the bar on the left. I could upload a a bitmap if you like..
|
|
|
|
|