• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

Opening a Folder in VC++

Jacko28

New Member
Joined
Sep 23, 2008
Messages
67 (0.01/day)
I've recently started learning VC++ and it's coming along quite nicley, I've now been given a little task by my boss to add a button to an excisting Incident report program.

All the button needs to do is open a new explorer window and open the folder selected in the incident report program. There isn't a deadline for it, it's just to assist in my learning.

I'm not asking for anyone to do it for me, i just need a few suggestions on how to do this so i'm looking in the correct direction?

Thanks
 

temp02

New Member
Joined
Mar 18, 2009
Messages
493 (0.09/day)
Use ShellExecute, like this:
Code:
ShellExecute(NULL, "explore", "C:\", NULL, NULL, SW_SHOWDEFAULT);
And replace "C:\" with whatever folder path you want to open.
Good luck.
 

Jacko28

New Member
Joined
Sep 23, 2008
Messages
67 (0.01/day)
I've got the button working now, it opens the folder which I've stated.

I'm now looking at reading a string the user inputs, from this string I want to be able identify and open the folder using the button.

Is this in the range of someone at intermediate level?

Furthermore, is there a function like equalsIgnoreCase in c++ and would this be viable for doing what I need?
 

temp02

New Member
Joined
Mar 18, 2009
Messages
493 (0.09/day)
From the looks of it, you are making an GUI application, (not a console one) right?
If you really need to read the path from the user input as a string, which I don't recommend since writing a path is very tedious not to mention error prone, you can drop a TextBox on the form and use TextBox1.Text instead of "C:\" on the call to ShellExecute, like so:
Code:
ShellExecute(NULL, "explore", TextBox1.Text, NULL, NULL, SW_SHOWDEFAULT);

As for the "equalsIgnoreCase" (JAVA right?), you don't need to worry about that, Windows paths are case insensitive, so you can write something like "c:\dOcUmEnTS anD seTTingS\" and it will still work.

Also, I would recommend you taking a look at SHBrowseForFolder, for a more uniform an simple way of selecting a folder.

Good luck, sorry for the extra late reply, I was away for some hours.
 
Joined
Dec 22, 2007
Messages
184 (0.03/day)
Location
Central Nebraska
System Name CORSAIR
Processor AMD Phenom 1090T x6 @3.2
Motherboard Gigabyte Ga-78LMT-S2P
Cooling High efficiency dust cooling
Memory 8GB GSkill DDR3 1333
Video Card(s) Sapphire Radeon HD3870 512MB GDDR4 PCI-e toxic
Storage Seagate SV35.3 ST3250310SV 250GB SATAII(Windows 7 Pro x64), 320GB Samsung SATAII(Storage and SuSE)
Display(s) Dell 20" LCD, Dell 17" LCD
Power Supply Antec Cool Blue 650W Modular
Software Windows 7 Professional SP1, Visual Studio 2010 Ultimate
Jack28,
I would look into using a FolderBrowserDialog object in your application. This will open a dialog that lets you select a folder. Then use
Code:
FolderBrowserDialog1.selecteditem
to return the output string of the folder into a textbox, set the textbox enabled property to false so that they cannot type in the path, they have to get the path by selecting the folder using the folder browser.
This will endure your program never throws a directory not found exception and crashing itself.
This is what I have always doen and it works quite nicely.
 

ctrain

New Member
Joined
Jan 12, 2010
Messages
393 (0.08/day)
Jack28,
I would look into using a FolderBrowserDialog object in your application. This will open a dialog that lets you select a folder. Then use
Code:
FolderBrowserDialog1.selecteditem
to return the output string of the folder into a textbox, set the textbox enabled property to false so that they cannot type in the path, they have to get the path by selecting the folder using the folder browser.
This will endure your program never throws a directory not found exception and crashing itself.
This is what I have always doen and it works quite nicely.

This is .NET, not native Win32
 
Joined
Dec 22, 2007
Messages
184 (0.03/day)
Location
Central Nebraska
System Name CORSAIR
Processor AMD Phenom 1090T x6 @3.2
Motherboard Gigabyte Ga-78LMT-S2P
Cooling High efficiency dust cooling
Memory 8GB GSkill DDR3 1333
Video Card(s) Sapphire Radeon HD3870 512MB GDDR4 PCI-e toxic
Storage Seagate SV35.3 ST3250310SV 250GB SATAII(Windows 7 Pro x64), 320GB Samsung SATAII(Storage and SuSE)
Display(s) Dell 20" LCD, Dell 17" LCD
Power Supply Antec Cool Blue 650W Modular
Software Windows 7 Professional SP1, Visual Studio 2010 Ultimate
I do this with vb.net all the time:
Code:
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        FolderBrowserDialog1.ShowDialog()
        TextBox1.Text = FolderBrowserDialog1.SelectedPath
        My.Settings.SelectedPath = FolderBrowserDialog1.SelectedPath
        Process.Start("explorer.exe", My.Settings.SelectedPath)
    End Sub
End Class

This program in itself is a little silly, however if you use the textbox to save an application setting tht returns the path, you could change it later on if needed instead of hard coding it in.
 
Last edited:

Jacko28

New Member
Joined
Sep 23, 2008
Messages
67 (0.01/day)
Thanks for all of the help guys, I've managed to get it working now. I used OpenFileDialog in the end and I've used a StreamReader to open the file. As of right now I'm not reading from a textbox to find the file, the file's I actually need are all in the same directory/folder so I've just put a path to the folder and added a .txt filter(all files are saved a .txt).

I'll keep this thread updated, becuase I'm going to attempt to read from the textbox when I have some more free time.
 
Joined
Dec 22, 2007
Messages
184 (0.03/day)
Location
Central Nebraska
System Name CORSAIR
Processor AMD Phenom 1090T x6 @3.2
Motherboard Gigabyte Ga-78LMT-S2P
Cooling High efficiency dust cooling
Memory 8GB GSkill DDR3 1333
Video Card(s) Sapphire Radeon HD3870 512MB GDDR4 PCI-e toxic
Storage Seagate SV35.3 ST3250310SV 250GB SATAII(Windows 7 Pro x64), 320GB Samsung SATAII(Storage and SuSE)
Display(s) Dell 20" LCD, Dell 17" LCD
Power Supply Antec Cool Blue 650W Modular
Software Windows 7 Professional SP1, Visual Studio 2010 Ultimate
Top