Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open directory in Windows Explorer using C/C++

I am making a game in C++, and I have a directory in a weird location (the installation directory) with screenshots from my game taken with the Print Screen key.

What I want to do is to create a button that opens Windows Explorer with the location of the screenshots.

I was thinking about using C's system function with explorer.exe and some arguments, but I don't think this is the correct way of doing it.

I am probably going to disable this feature in Full Screen mode, as I want to avoid unexpected behaviour.

like image 371
Pacha Avatar asked Nov 26 '25 02:11

Pacha


2 Answers

The best way to do this is with the SHOpenFolderAndSelectItems() function. This lets you open the default folder manager (i.e. not hard-coded to Explorer, respecting the user's choice) and has the benefit of letting you automatically select the newly created screenshots.

like image 133
Jonathan Potter Avatar answered Nov 28 '25 17:11

Jonathan Potter


Use ShellExecute native windows API to do that

#include <shellapi.h>
#pragma comment(lib, "shell32")
int main()
{
    ShellExecute(NULL, "open", "C:\\ProgramFiles\Location", NULL, NULL, SW_SHOWMINIMIZED);
    return 0;
}
like image 32
Balu Avatar answered Nov 28 '25 17:11

Balu