Open With Program...

Just going to ask this since I'm 85% dead inside right now ^_^

When you right click a file in Windows Explorer, you can open it with a program (open with...). How would I write that in a program?

Let's say, turning this "example.txt" into whatever the user opened the file/program with:

1
2
3
4
  ofstream File_A;
  File_A.open ("example.txt");
  File_A<< "This file sucks.";
  File_A.close();


I'm thinking there's a few lines of code out there that go:
1
2
  string FName = Windows.fileName;
  string FLoc = Windows.fileLoc;

but I'm probably wrong.
Last edited on
There is SHOpenWithDialog() function, but it is only available in Windows Vista or later.
I'm having a problem with this, I'm getting several errors and I think it's because I'm not using the right libs, or maybe I'm just stupid... Mind taking a looking and giving me some feedback?

1
2
3
4
5
6
7
8
#include <windows.h>

int main()
{
    OPENASINFO Info = { 0 };
    Info.oaifInFlags = OAIF_EXEC | OAIF_ALLOW_REGISTRATION;
    SHOpenWithDialog(NULL, &amp;Info);
}
You are not passing any filename. How can the dialog box know what file it should refer to? You must provide the file's name.
Now I'm getting the error:

5 C:\CPlusPlus\OpenDialog.cpp `OPENASINFO' undeclared (first use this function)


Also, I changed the code to:

1
2
3
4
5
6
7
8
9
10
#include <windows.h>

int main()
{
    OPENASINFO Info = { 0 };
    Info.pcszFile = L"C:\\CPlusPlus\\OpenDialog.cpp";
    Info.pcszClass = NULL;
    Info.oaifInFlags = OAIF_ALLOW_REGISTRATION;
    SHOpenWithDialog(NULL, &amp;Info);
}
Last edited on
MSDN Online is your friend. http://msdn.microsoft.com/en-us/library/windows/desktop/bb762234(v=vs.85).aspx

In there you'll see which header you must include, and which lib you need to include to link your project.
webJose, you are my greatest friend of the hour, thank you ^_^
Topic archived. No new replies allowed.