Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Open a file in its default program (Windows)
// Opening a File (e.g. Video) in its default program
// --------------------------------------------------
This method, using the 'ShellExecute' command, only works in Windows
(tested in Windows 7).
The code snippet was taken from an App created using Cinder,
a C++ Framework for Creative Coding:
However, 'ShellExecute' should work in standard Windows Desktop Apps.
#include "cinder/app/AppNative.h"
#include "cinder/gl/gl.h"
#include <stdio.h>
//IMPORTANT! ShellExecute requires this header
#include <shellapi.h>
using namespace ci;
using namespace ci::app;
using namespace std;
class CinderApp : public AppNative
//-- standard Cinder Functions --
void setup();
void update();
void draw();
void mouseDown( MouseEvent event );
void playVideo(string videoFileName);
void CinderApp::setup() { /* Setup Cinder App */ }
void CinderApp::update() { /* Update state of App */ }
void CinderApp::draw() { /* Draw graphics */ }
//Cinder triggers this function when a mouse button is pressed
void CinderApp::mouseDown( MouseEvent event )
string filepath = "videos\\testVideo.wmv";
fs::path videoPath = getAssetPath( filepath );
wstring videoFilePath = videoPath.wstring();
LPCWSTR videoFilePathChars = (LPCWSTR)videoFilePath.c_str();
//The 'ShellExecute' function will open the video file externally,
//in whichever application has been set as the default for WMV files.
ShellExecute(0, 0, videoFilePathChars, 0, 0 , SW_SHOW );
cout << "ERROR! could not play video!!!" << endl;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment