Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
While designing a text editor in C on windows, when the user double clicks on my editor executable it opens a text editor to allow the user to type-in and then save it with a test.xyz file extension.

After this step the when the user directly opens test.xyz file by double clicking on desktop, how do I make the test.xyz file open with my texteditor.exe editor automatically.

I am asking this because I store the contents of the test.xyz file in a unique format that only my testeditor.exe can understand and interpret the contents to user in a correct way.

How to embed this feature in in testeditor source code so that the user need not open the testeditor but instead he can directly open the .xyz documents and then automatically view this file in testeditor.

For example, if you click on a .doc file it automatically opens in MS word instead of notepad.

Any clues to this will be appreciated.
Posted
Comments
[no name] 23-Jul-12 14:57pm    
You need to lookup "File associations"
Kenneth Haugland 23-Jul-12 15:01pm    
Here is a tool you could use:
http://sourceforge.net/projects/istool/

1 solution

There are two parts of it: your application functionality + system registry settings related to the Shell.

On application part, you need to handle the command line parameters passed to your application when it is started. As this is C, you have an entry point called main. The OS loader of the applications passes the command line parameters argc, and argv as they appear in on of the following signatures
C++
int main(int argc, char **argv);
int main(int argc, char *argv[]);
int main(int argc, char **argv, char **envp);


Please see:
http://en.wikipedia.org/wiki/Main_function#C_and_C.2B.2B[^].

Your application should parse the command line, recognize file name(s) and try to load a file.

On the system registry side, you need to update the register to register the association between your application and some file type(s) recognized by the file name pattern (usually called "extensions", but this term is incorrect: there are no "extensions" in modern file systems; the letters after the last '.' character in file names are just the part of the file name). Please see:
http://msdn.microsoft.com/en-us/library/windows/desktop/cc144158%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/cc144156%28v=vs.85%29.aspx[^].

—SA
 
Share this answer
 
v2
Comments
enhzflep 23-Jul-12 16:22pm    
The answers don't get better than this. +5!
Sergey Alexandrovich Kryukov 23-Jul-12 16:41pm    
Thank you,
--SA
Malli_S 24-Jul-12 2:18am    
Agreed ! +5
[no name] 23-Jul-12 20:03pm    
Yep
Sergey Alexandrovich Kryukov 23-Jul-12 21:27pm    
Aha... :-)
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900