Using Args at cmd line

Hi, I am making a notepad replica using Dev-Cpp, and I figured if I went into the cmd prompt, and typed in "Notepad whatever.txt" it would create it for you if it didn't exist. I am using the win32 api to code and I wonder how can I use arguments similar to the one in Notepad, and another question, how would you (in code) set a file types default associated program.. for example notepad opens text files. I would like to overwrite that and use my own, and if i decide to distribute it I would like to have the feature in code so users don't have to do it manually. Thanks for the help in advance!!
You don't need the API to create a new file. Just try to open the file for reading. If it doesn't exist, it will be created.

I think that was set in HKEY_CLASSES_ROOT, but I'm not sure how it works.
File associations:
http://www.atmaweapon.org/blog/?p=22

You can get command line arguments directly in main():
1
2
3
4
5
6
7
8
9
10
#include <iostream>
using namespace std;

int main( int argc, char* argv[] )
  {
  cout << "prog: " << argv[ 0 ] << '\n';
  for (int cntr = 1; cntr < argc; cntr++)
    cout << cntr << ": " << argv[ cntr ] << '\n';
  return 0;
  }


Or you can use the MS functions:
GetCommandLine() http://msdn.microsoft.com/en-us/library/ms683156(VS.85).aspx

For Unicode strings, use GetCommandLineW() with:
CommandLineToArgvW() http://msdn.microsoft.com/en-us/library/bb776391(VS.85).aspx
(which has an example and some important user commentary)

Hope this helps.
Thanks to both of you!!
Topic archived. No new replies allowed.