Hmm...I know how you feel, every time I get a new install in work or home I have to tinker with the registry to get it to open these files with my beloved TextPad (better than wordpad as it has a hex viewer too )
To ease my pain as well as yours I just wrote this
Code:
//#define UNICODE //Uncomment if you want a unicode build
//#define _UNICODE //Uncomment if you want a unicode build
#include <windows.h>
#include <tchar.h>
int WINAPI WinMain(HINSTANCE hInst,HINSTANCE,LPSTR,int){
//
//File Dilaog box
//
OPENFILENAME ofn = {sizeof(OPENFILENAME)};
TCHAR szFile[MAX_PATH] = {0};
TCHAR *szFilter = _T("WordPad.exe\0wordpad.exe\0Other prog\0*.exe\0"),
*szTitle = _T("Locate Wordpad.exe....or choose another editor");
ofn.hInstance = hInst;
ofn.lpstrFile = szFile;
ofn.nMaxFile = MAX_PATH;
ofn.lpstrFilter = szFilter;
ofn.lpstrTitle = szTitle;
if(!GetOpenFileName(&ofn))
return 1;
//
//String manipulation
//
TCHAR *szCommString = NULL;
HKEY hKey = NULL;
__try{
DWORD dwLen = _tcslen(szFile);
dwLen += 8;
szCommString = new TCHAR[dwLen];
if(!szCommString){
MessageBox(HWND_DESKTOP,_T("Memory Error"),NULL,MB_OK);
return 1;
}
_tcscpy(szCommString, _T("\""));
_tcscat(szCommString,szFile);
_tcscat(szCommString,_T("\" \"%1\""));
//
//Nasty Registry stuff
//
TCHAR *szUnKnown = _T("\\Unknown\\shell"),
*szUnKnownCom = _T("Unknown\\shell\\edit\\command"),
*szComDef = _T("edit");
if(RegOpenKey(HKEY_CLASSES_ROOT,szUnKnown,&hKey) != ERROR_SUCCESS){
MessageBox(HWND_DESKTOP,_T("Error opening key"),NULL,MB_OK);
return 1;
}
if(RegSetValue(hKey,NULL,REG_SZ ,szComDef,_tcslen(szComDef)) != ERROR_SUCCESS){
MessageBox(HWND_DESKTOP,_T("Error setting command"),NULL,MB_OK);
return 1;
}
RegCloseKey(hKey);
if(RegCreateKey(HKEY_CLASSES_ROOT,szUnKnownCom,&hKey) != ERROR_SUCCESS){
MessageBox(HWND_DESKTOP,_T("Error creating command"),NULL,MB_OK);
return 1;
}
if(RegSetValue(hKey,NULL,REG_SZ ,szCommString,_tcslen(szCommString))
!= ERROR_SUCCESS){
MessageBox(HWND_DESKTOP,_T("Error setting commandline"),NULL,MB_OK);
return 1;
}
return 0;
}
__finally{
if(hKey)RegCloseKey(hKey);
if(szCommString) delete [] szCommString;
}
return 0;
}
Ok, you need to run VC++, but if you havent got it I included the exe....
Once you run it, it opens a dialog for you to select the location of Wordpad (if you go to the bottom dropdown there's an option to select any exe file...supposing you drop wordpad ....)...now once you have found your exe, it will edit the registry to add an "edit" option to all files without an extension..also, after running the app, whenever you double click, you will get the doc opened in your chosen editor..
I tested it on WinXP and it works aok......should also work on other Win32 platforms
Enjoy (I hope!)