Skip to content

Instantly share code, notes, and snippets.

@prucha
Created May 6, 2015 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prucha/83af70f6e2f5f0fadaba to your computer and use it in GitHub Desktop.
Save prucha/83af70f6e2f5f0fadaba to your computer and use it in GitHub Desktop.
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: http://libcinder.org/
However, 'ShellExecute' should work in standard Windows Desktop Apps.
https://msdn.microsoft.com/en-us/library/windows/desktop/bb762153%28v=vs.85%29.aspx
*/
#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
{
public:
//-- standard Cinder Functions --
void setup();
void update();
void draw();
void mouseDown( MouseEvent event );
private:
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";
try
{
fs::path videoPath = getAssetPath( filepath );
wstring videoFilePath = videoPath.wstring();
LPCWSTR videoFilePathChars = (LPCWSTR)videoFilePath.c_str();
// THE IMPORTANT BIT!
//--------------------------------------------------------------------
//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 );
//--------------------------------------------------------------------
}
catch(...)
{
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