Open in Explorer

How to open a path in the code explorer in C ++. I googled and could not find anything but system commands for this, however, I do not want it to block or show the console window.

+7
c ++ windows explorer
source share
2 answers

You are probably looking for the ShellExecute () function in shell32.h. It is called using the "action verb", path, and optional parameters. In your case, it will want to either "discover" or "explore" as follows:

ShellExecute(NULL, "open", "C:\", NULL, NULL, SW_SHOWDEFAULT); 

This will open the standalone explorer window in C :. ShellExecute () will give basically the same action as entering a command in the Run dialog box. It will also handle URLs, so the following browser will open the default browser:

 ShellExecute(NULL, "open", "http://www.google.com", NULL, NULL, SW_SHOWDEFAULT); 

Even though, pay attention to the note in the documentation that ShellExecute relies on COM (although your code does not need to worry about any COM objects).

 CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE) 
+16
source share

This does not display the command window, it simply opens the directory.

 system("explorer C:\\");
system("explorer C:\\"); 
+2
source share

All Articles