Solved

CFileDialog Browsing...

Posted on 1998-10-23
24
510 Views
Last Modified: 2013-11-20
Hi,

is it possible to make CFileDialog come up with the same display as you get from the first screen of My Computer or if you go up a directory from the root directory of your drive in File Explorer? i.e. so you see all your drives and network neighbourhood...

If so how?
0
Comment
Question by:henryj
  • 11
  • 6
  • 2
  • +3
24 Comments
 

Author Comment

by:henryj
Comment Utility
Edited text of question
0
 

Author Comment

by:henryj
Comment Utility
p.s. by "come up" I mean for it to start on that screen...
0
 
LVL 1

Expert Comment

by:Dex_Man
Comment Utility
In the m_ofn section of the dialog box (check help on CFileDialog, then m_ofn, then OPENFILENAME struct), you can set the DWORD Flags member to explorer type or non-explorer type. See if this is what you are wanting.

-Dex Man
0
 

Author Comment

by:henryj
Comment Utility
I don't want an explorer STYLE interface - I already have this. I want to know how to start the file open dialogue on the screen which lists all the machines drives and network neighbourhood. I would've thought there may be something you can put in the default path to do this but I can't find what it is. If I put nothing it starts in the current default directory. Does this clarify?
0
 
LVL 1

Expert Comment

by:Dex_Man
Comment Utility
There should be a way to set the default directory (again, check the m_ofn members), but you probably won't be able to get network connects and local drives on the same screen (except MAPPED drives and local drives) unless you create your oen special dialog box with a tree in it and fill it with local drives network drives. You shoudl be able to open it in the root directory though, with C:, Network Ne... etc. Sorry, I'm not at my PC right now, but I'll look later and see if I can help ya out.

-Dex Man
0
 

Author Comment

by:henryj
Comment Utility
There is a way to set default directory - but thats really my question - how do I set it so that I get a screen showing the drives available along with network mapped drives and network neighbood. i.e. if you are in windows explorer and you are in C:\ and you press the button to go up a directory - how do I get THAT screen in CFileDialog. I thought I might get it by using \\networknameofmachine\ but thats no joy...
0
 
LVL 11

Expert Comment

by:mikeblas
Comment Utility
You can't.  While the dialog made by the file dialog APIs supports browsing through the shell namespace, it doesn't allow setting such a location as the initial directory.

B ekiM


0
 

Author Comment

by:henryj
Comment Utility
I am not actually rejecting your answer - I just want to leave the issue open for a few more days incase someone knows a hack or something. If nobody responds by Tuesday please send me another "answer" (just say "gimme the points"  or something) and I'll award the points to you. Thanks....

0
 
LVL 3

Expert Comment

by:danny_pav
Comment Utility
Why not try this?
Override/subclass the dialog box, see http://www.vcdj.com for an article on how to do this.
In the OnInitDialog override, simulate the necessary steps to navigate to the network neighborhood area.
0
 

Author Comment

by:henryj
Comment Utility
Haha yeah - well in essence what you are saying is write it yourself. The thing is that I use MFC to do this crap for me. If I have to write it myself I should probably be asking why am I using MFC - which is a valid question - and the answer is the client wants it and the code I am modifying is written in it. Yes, it *IS* one solution. However, my deadlines don't really allow it's investigation.

0
 
LVL 11

Expert Comment

by:mikeblas
Comment Utility
Actually, Danny isn't saying that you should write it yourself. What he's suggesting is less than a page of code; that's far less (by, say, a factor of 100) code than it takes to implement the dialog from scratch.

Danny's approach has merit, but I didn't recommend it because I'm not sure it is readily localizable.

MFC doesn't fix the operating system. It's the OS-supplied COMDLG32.DLL that doesn't have this functionality (aka "crap").

B ekiM

0
 

Author Comment

by:henryj
Comment Utility
I think it would probably be more then a page of code - maybe 2 :) At least assuming you space it out properly. But in any case I don't have time to do this as it's one small part of a larger whole that is more important. Also I doubt it would be a small task to make it look and behave exactly the same as the other network neighbourhood / drives display which could lead to user confusion. Testing on every possible system might also be problamatical (it's to go into a commercial product). So overall I don't like the idea much :) I agree it's crap that this functionality doesn't exist within COMDLG32.DLL - it makes the interface more limited from a programmers point of view then it is from a users point of view (because you can't start it at that location).
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 3

Expert Comment

by:danny_pav
Comment Utility
1. You don't have to write the code from scratch.  There is example code at the site I mentioned along with an article explaining what the heck is going on.  It is also free, doesn't require membership, or that you sacrifice your first born...
2. Modifying existing code by removal will almost always be quicker than reinventing the wheel.
0
 

Author Comment

by:henryj
Comment Utility
1. I looked at the site. There are pages of stuff here. There is an article that probably explains what you describe. Either way it's not an answer for me as I asked how I might force CFileDialog to open at that specific screen. Regardless of whether I write the code myself from scratch or just take out stuff from the examples provided and add stuff to detect network drives etc. it is still not the solution I was looking for.

2. Absolutely true.

3. Maybe mikeblas would like to answer again that it's not possible without modification of CFileDialog. I believe this is the correct answer to my question and it seems without modification there is no other answer.

4. Thanks for the reference anyway - maybe it will be useful for a different project someday.
0
 

Expert Comment

by:ddeboskey
Comment Utility
There is a function called SHGetSpecialFolderLocation which
can return a handle to the "Desktop" folder when passed
CSIDL_DESKTOP.

By modifying the m_ofn structure of your file dialog, you should be able to get the "desktop" folder to appear.
0
 
LVL 11

Expert Comment

by:mikeblas
Comment Utility
Did you try following your own advice, ddeboskey?

First, The SHGetSpecialFolderLocation() routine returns an ITEMIDLIST, not a handle.

Next, there's no way to give the ITEMIDLIST to the OPENFILEDIALOG structure. (It's documented to work for CSIDL_PERSONAL, but it doesn't.)

Finally, you might try translating the ITEMIDLIST to a path name with SHGetPathFromIDList(), or by calling SHGetSpecialFolderPath() directly in the first place. But there's no path name for the CSIDL_DRIVES folder.

So, your suggestion won't work.

B ekiM

0
 

Author Comment

by:henryj
Comment Utility
I go along with mikeblas's comments on your answer... I think the correct answer is that there isn't an easy reliable way of doing this without writing your own code to emulate what windows does. So mikeblas's original answer of "you can't" was probably correct. Maybe he would care to reply again so we can close this question and he can have the points... I think that this has been around long enough now...
0
 

Expert Comment

by:cmihalache
Comment Utility
hello henryj,
Here is the code you need:

HKEY hKey;
RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", 0, NULL, 0, KEY_READ, NULL, &hKey, NULL);
DWORD lcpPath = MAX_PATH;
char szDesktopPath[MAX_PATH + 1];
RegQueryValueEx(hKey, "Desktop", NULL, NULL, (LPBYTE)szDesktopPath, &lcpPath);

CFileDialog dlgFile( true, "*.*", CString(szDesktopPath) + "\\*.*", ...);
if (dlgFile.DoModal() == IDOK)
{
.
}

It works in both Win95 and WinN.

0
 
LVL 11

Expert Comment

by:mikeblas
Comment Utility
While at VCDC, I remembered that the dropdown is a COMBOBOXEX and not a COMBOBOX. But, unfortunately, I still can't pry anything out of the control. IT's evidently doing some custom handling.

B ekiM
0
 
LVL 11

Expert Comment

by:mikeblas
Comment Utility
Did you _read_ the qestion, cmihalache?  Henry has asked for the "My Computer" folder, not the "Desktop" folder.  They're quite different!

Even that withstanding, you should have advised the use of the SHGetSpecialFolderPath() API instead of encouraging a random registry hack.

B ekiM

0
 

Expert Comment

by:cmihalache
Comment Utility
I didn't read all the discution but, as i saw, he wants to see network neighbourhood. This folder are sawn only from the Desktop folder.
0
 

Author Comment

by:henryj
Comment Utility
I am not into fiddling with the registry. I think this question has got out of hand. My question was intended originally to get answers about how to make CFileDialog show the My Computer folder (i.e. all drives including mapped ones). I don't know where network neighbourhood crept in - maybe I got confused somewhere along the discussion. But essentially my question was not about how to program a simulation of the my computer display but how to make CFileDialog show it and whether it was possible. I still think mikeblas answer that it's not possible with CFileDialog is the correct answer.

Many have suggested how I can simulate it and thats fine but it's not the answer I was looking for. My code has to go into a commercial product and I am very conservative about what I am willing to hack to get this simulation. Unless I can be 100% certain it will work everywhere I'd rather default to starting somewhere else other then in MyComputer as it's safer.

Now Mike will you answer again so we can put this one to bed before someone else suggests another simulation of the functionality? :)

0
 
LVL 11

Accepted Solution

by:
mikeblas earned 100 total points
Comment Utility
Thanks.

Good luck with your project.

B ekiM
0
 

Author Comment

by:henryj
Comment Utility
Great. Not the ideal answer but the correct one I suspect :) Why they don't implement this functionality is beyond me but I guess it's one of those things. Thanks...

0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now